Java Code Examples for jdk.nashorn.internal.objects.annotations.Attribute.NOT_ENUMERABLE

The following are Jave code examples for showing how to use NOT_ENUMERABLE of the jdk.nashorn.internal.objects.annotations.Attribute class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File: NativeArray.java   View Source Code Vote up 6 votes
/**
 * ECMA 15.4.4.20 Array.prototype.filter ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return filtered array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static NativeArray filter(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, new NativeArray()) {
        private long to = 0;
        private final MethodHandle filterInvoker = getFILTER_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            if ((boolean)filterInvoker.invokeExact(callbackfn, thisArg, val, i, self)) {
                result.defineOwnProperty(ArrayIndex.getArrayIndex(to++), val);
            }
            return true;
        }
    }.apply();
}
 
Example 2
Project: OpenJSharp   File: NativeString.java   View Source Code Vote up 6 votes
/**
 * ECMA 15.5.4.14 String.prototype.split (separator, limit)
 *
 * @param self      self reference
 * @param separator separator for split
 * @param limit     limit for splits
 * @return array object in which splits have been placed
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static ScriptObject split(final Object self, final Object separator, final Object limit) {
    final String str = checkObjectToString(self);
    final long lim = limit == UNDEFINED ? JSType.MAX_UINT : JSType.toUint32(limit);

    if (separator == UNDEFINED) {
        return lim == 0 ? new NativeArray() : new NativeArray(new Object[]{str});
    }

    if (separator instanceof NativeRegExp) {
        return ((NativeRegExp) separator).split(str, lim);
    }

    // when separator is a string, it is treated as a literal search string to be used for splitting.
    return splitString(str, JSType.toString(separator), lim);
}
 
Example 3
Project: OpenJSharp   File: NativeJavaImporter.java   View Source Code Vote up 5 votes
/**
 * "No such property" handler.
 *
 * @param self self reference
 * @param name property name
 * @return value of the missing property
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object __noSuchProperty__(final Object self, final Object name) {
    if (! (self instanceof NativeJavaImporter)) {
        throw typeError("not.a.java.importer", ScriptRuntime.safeToString(self));
    }
    return ((NativeJavaImporter)self).createProperty(JSType.toString(name));
}
 
Example 4
Project: openjdk-jdk10   File: NativeFunction.java   View Source Code Vote up 5 votes
/**
 * ECMA 15.3.4.5 Function.prototype.bind (thisArg [, arg1 [, arg2, ...]])
 *
 * @param self self reference
 * @param args arguments for bind
 * @return function with bound arguments
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object bind(final Object self, final Object... args) {
    final Object thiz = (args.length == 0) ? UNDEFINED : args[0];

    Object[] arguments;
    if (args.length > 1) {
        arguments = new Object[args.length - 1];
        System.arraycopy(args, 1, arguments, 0, arguments.length);
    } else {
        arguments = ScriptRuntime.EMPTY_ARRAY;
    }

    return Bootstrap.bindCallable(self, thiz, arguments);
}
 
Example 5
Project: openjdk-jdk10   File: NativeObject.java   View Source Code Vote up 5 votes
/**
 * ECMA 15.2.3.13 Object.isExtensible ( O )
 *
 * @param self self reference
 * @param obj check whether an object is extensible
 * @return true if object is extensible, false otherwise
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static boolean isExtensible(final Object self, final Object obj) {
    if (obj instanceof ScriptObject) {
        return ((ScriptObject)obj).isExtensible();
    } else if (obj instanceof ScriptObjectMirror) {
        return ((ScriptObjectMirror)obj).isExtensible();
    } else {
        throw notAnObject(obj);
    }
}
 
Example 6
Project: openjdk-jdk10   File: NativeRegExpExecResult.java   View Source Code Vote up 5 votes
/**
 * Length getter
 * @param self self reference
 * @return length property value
 */
@Getter(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_CONFIGURABLE)
public static Object length(final Object self) {
    if (self instanceof ScriptObject) {
        return (double) JSType.toUint32(((ScriptObject)self).getArray().length());
    }

    return 0;
}
 
Example 7
Project: openjdk-jdk10   File: NativeDataView.java   View Source Code Vote up 5 votes
/**
 * Set 64-bit float at the given byteOffset
 *
 * @param self DataView object
 * @param byteOffset byte offset to write at
 * @param value double value to set
 * @param littleEndian (optional) flag indicating whether to write in little endian order
 * @return undefined
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
public static Object setFloat64(final Object self, final Object byteOffset, final Object value, final Object littleEndian) {
    try {
        getBuffer(self, littleEndian).putDouble((int)JSType.toUint32(byteOffset), JSType.toNumber(value));
        return UNDEFINED;
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example 8
Project: openjdk-jdk10   File: Global.java   View Source Code Vote up 4 votes
/**
 * Setter for the RangeError property.
 * @param self self reference
 * @param value value for the RangeError property
 */
@Setter(name = "RangeError", attributes = Attribute.NOT_ENUMERABLE)
public static void setRangeError(final Object self, final Object value) {
    final Global global = Global.instanceFrom(self);
    global.rangeError = value;
}
 
Example 9
Project: openjdk-jdk10   File: NativeDebug.java   View Source Code Vote up 4 votes
/**
 * Return all runtime events in the queue as an array
 * @param self self reference
 * @return array of events
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object getRuntimeEvents(final Object self) {
    final LinkedList<RuntimeEvent<?>> q = getEventQueue(self);
    return q.toArray(new RuntimeEvent<?>[0]);
}
 
Example 10
Project: OpenJSharp   File: NativeDebug.java   View Source Code Vote up 4 votes
/**
 * Clear the runtime event queue
 * @param self self reference
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static void clearRuntimeEvents(final Object self) {
    final LinkedList<RuntimeEvent<?>> q = getEventQueue(self);
    q.clear();
}
 
Example 11
Project: openjdk-jdk10   File: NativeDate.java   View Source Code Vote up 3 votes
/**
 * ECMA 15.9.5.34 Date.prototype.setHours (hour [, min [, sec [, ms ] ] ] )
 *
 * @param self self reference
 * @param args hour (optional arguments after are minutes, seconds, milliseconds)
 * @return time
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 4)
public static double setHours(final Object self, final Object... args) {
    final NativeDate nd = getNativeDate(self);
    setFields(nd, HOUR, args, true);
    return nd.getTime();
}
 
Example 12
Project: OpenJSharp   File: NativeFloat64Array.java   View Source Code Vote up 2 votes
/**
 * Returns a new TypedArray view of the ArrayBuffer store for this TypedArray,
 * referencing the elements at begin, inclusive, up to end, exclusive. If either
 * begin or end is negative, it refers to an index from the end of the array,
 * as opposed to from the beginning.
 * <p>
 * If end is unspecified, the subarray contains all elements from begin to the end
 * of the TypedArray. The range specified by the begin and end values is clamped to
 * the valid index range for the current array. If the computed length of the new
 * TypedArray would be negative, it is clamped to zero.
 * <p>
 * The returned TypedArray will be of the same type as the array on which this
 * method is invoked.
 *
 * @param self self reference
 * @param begin begin position
 * @param end end position
 *
 * @return sub array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
protected static NativeFloat64Array subarray(final Object self, final Object begin, final Object end) {
    return (NativeFloat64Array)ArrayBufferView.subarrayImpl(self, begin, end);
}
 
Example 13
Project: OpenJSharp   File: NativeString.java   View Source Code Vote up 2 votes
/**
 * ECMA 15.5.4.3 String.prototype.valueOf ( )
 * @param self self reference
 * @return self as string
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static String valueOf(final Object self) {
    return getString(self);
}
 
Example 14
Project: OpenJSharp   File: NativeMath.java   View Source Code Vote up 2 votes
/**
 * ECMA 15.8.2.14 random()
 *
 * @param self  self reference
 *
 * @return random number in the range [0..1)
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static double random(final Object self) {
    return Math.random();
}
 
Example 15
Project: openjdk-jdk10   File: NativeJava.java   View Source Code Vote up 2 votes
/**
 * When given an object created using {@code Java.extend()} or equivalent mechanism (that is, any JavaScript-to-Java
 * adapter), returns an object that can be used to invoke superclass methods on that object. E.g.:
 * <pre>
 * var cw = new FilterWriterAdapter(sw) {
 *     write: function(s, off, len) {
 *         s = capitalize(s, off, len)
 *         cw_super.write(s, 0, s.length())
 *     }
 * }
 * var cw_super = Java.super(cw)
 * </pre>
 * @param self the {@code Java} object itself - not used.
 * @param adapter the original Java adapter instance for which the super adapter is created.
 * @return a super adapter for the original adapter
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR, name="super")
public static Object _super(final Object self, final Object adapter) {
    return Bootstrap.createSuperAdapter(adapter);
}
 
Example 16
Project: OpenJSharp   File: NativeJavaPackage.java   View Source Code Vote up 2 votes
/**
 * "No such property" call placeholder.
 *
 * This can never be called as we override {@link ScriptObject#noSuchProperty}. We do declare it here as it's a signal
 * to {@link WithObject} that it's worth trying doing a {@code noSuchProperty} on this object.
 *
 * @param self self reference
 * @param name property name
 * @return never returns
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object __noSuchProperty__(final Object self, final Object name) {
    throw new AssertionError("__noSuchProperty__ placeholder called");
}
 
Example 17
Project: openjdk-jdk10   File: NativeDate.java   View Source Code Vote up 2 votes
/**
 * ECMA 15.9.5.12 Date.prototype.getMonth ( )
 *
 * @param self self reference
 * @return month
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static double getMonth(final Object self) {
    return getField(self, MONTH);
}
 
Example 18
Project: openjdk-jdk10   File: NativeDate.java   View Source Code Vote up 2 votes
/**
 * ECMA 15.9.5.6 Date.prototype.toLocaleDateString ( )
 *
 * @param self self reference
 * @return string value with the "date" part of the Date in the current time zone and locale
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static String toLocaleDateString(final Object self) {
    return toStringImpl(self, FORMAT_LOCAL_DATE);
}
 
Example 19
Project: openjdk-jdk10   File: NativeFloat32Array.java   View Source Code Vote up 2 votes
/**
 * Set values
 * @param self   self reference
 * @param array  multiple values of array's type to set
 * @param offset optional start index, interpreted  0 if undefined
 * @return undefined
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
protected static Object set(final Object self, final Object array, final Object offset) {
    return ArrayBufferView.setImpl(self, array, offset);
}
 
Example 20
Project: OpenJSharp   File: NativeMath.java   View Source Code Vote up 2 votes
/**
 * ECMA 15.8.2.13 pow(x,y)
 *
 * @param self  self reference
 * @param x     first argument
 * @param y     second argument
 *
 * @return x raised to the power of y
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static double pow(final Object self, final Object x, final Object y) {
    return Math.pow(JSType.toNumber(x), JSType.toNumber(y));
}