use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class TypedArrayConstructorPrototype method construct.
/**
* 22.2.1.1 %TypedArray% ( )
*/
@Override
public ScriptObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
ExecutionContext calleeContext = calleeContext();
/* step 3 */
if (newTarget == this) {
throw newTypeError(calleeContext, Messages.Key.TypedArrayCreate);
}
/* step 4 */
ScriptObject super_ = getPrototypeOf(calleeContext);
/* step 5 */
if (!IsConstructor(super_)) {
throw newTypeError(calleeContext, Messages.Key.NotConstructor);
}
/* steps 6-7 */
return ((Constructor) super_).construct(calleeContext, newTarget, args);
}
use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class MapConstructor method construct.
/**
* 23.1.1.1 Map ([ iterable ])
*/
@Override
public MapObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
ExecutionContext calleeContext = calleeContext();
Object iterable = argument(args, 0);
/* step 1 (not applicable) */
/* steps 2-4 */
MapObject map = OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.MapPrototype, MapObject::new);
/* steps 5-6, 8 */
if (Type.isUndefinedOrNull(iterable)) {
return map;
}
/* step 7 */
Object _adder = Get(calleeContext, map, "set");
if (!IsCallable(_adder)) {
throw newTypeError(calleeContext, Messages.Key.PropertyNotCallable, "set");
}
Callable adder = (Callable) _adder;
boolean isBuiltin = MapPrototype.isBuiltinSet(_adder);
if (isBuiltin && iterable instanceof MapObject) {
MapObject other = (MapObject) iterable;
if (ScriptIterators.isBuiltinIterator(calleeContext, other)) {
map.getMapData().setAll(other.getMapData());
return map;
}
}
ScriptIterator<?> iter = GetScriptIterator(calleeContext, iterable);
/* step 9 */
try {
while (iter.hasNext()) {
Object nextItem = iter.next();
if (!Type.isObject(nextItem)) {
throw newTypeError(calleeContext, Messages.Key.MapPairNotObject);
}
ScriptObject item = Type.objectValue(nextItem);
Object k = Get(calleeContext, item, 0);
Object v = Get(calleeContext, item, 1);
if (isBuiltin) {
map.getMapData().set(k, v);
} else {
adder.call(calleeContext, map, k, v);
}
}
return map;
} catch (ScriptException e) {
iter.close(e);
throw e;
}
}
use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class IntlAbstractOperations method SupportedLocales.
/**
* 9.2.9 SupportedLocales (availableLocales, requestedLocales, options)
*
* @param cx
* the execution context
* @param availableLocales
* the set of available locales
* @param requestedLocales
* the set of requested locales
* @param options
* the options object
* @return the supported locales array
*/
public static ScriptObject SupportedLocales(ExecutionContext cx, Set<String> availableLocales, Set<String> requestedLocales, Object options) {
/* step 1 */
String matcher = null;
if (!Type.isUndefined(options)) {
matcher = GetStringOption(cx, ToObject(cx, options), "localeMatcher", set("lookup", "best fit"), "best fit");
}
/* steps 2-5 */
List<String> supportedLocales;
if (matcher == null || "best fit".equals(matcher)) {
supportedLocales = BestFitSupportedLocales(availableLocales, requestedLocales);
} else {
supportedLocales = LookupSupportedLocales(availableLocales, requestedLocales);
}
/* steps 6-8 */
ArrayObject subset = ArrayCreate(cx, supportedLocales.size());
int index = 0;
for (Object value : supportedLocales) {
subset.defineOwnProperty(cx, index++, new PropertyDescriptor(value, false, true, false));
}
PropertyDescriptor nonConfigurableWritable = new PropertyDescriptor();
nonConfigurableWritable.setConfigurable(false);
nonConfigurableWritable.setWritable(false);
subset.defineOwnProperty(cx, "length", nonConfigurableWritable);
/* step 9 */
return subset;
}
use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class WeakMapConstructor method construct.
/**
* 23.3.1.1 WeakMap ([ iterable ])
*/
@Override
public WeakMapObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
ExecutionContext calleeContext = calleeContext();
Object iterable = argument(args, 0);
/* step 1 (not applicable) */
/* steps 2-4 */
WeakMapObject map = OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.WeakMapPrototype, WeakMapObject::new);
/* steps 5-6, 8 */
if (Type.isUndefinedOrNull(iterable)) {
return map;
}
/* step 7 */
Object _adder = Get(calleeContext, map, "set");
if (!IsCallable(_adder)) {
throw newTypeError(calleeContext, Messages.Key.PropertyNotCallable, "set");
}
Callable adder = (Callable) _adder;
ScriptIterator<?> iter = GetScriptIterator(calleeContext, iterable);
/* step 9 */
try {
while (iter.hasNext()) {
Object nextItem = iter.next();
if (!Type.isObject(nextItem)) {
throw newTypeError(calleeContext, Messages.Key.WeakMapPairNotObject);
}
ScriptObject item = Type.objectValue(nextItem);
Object k = Get(calleeContext, item, 0);
Object v = Get(calleeContext, item, 1);
adder.call(calleeContext, map, k, v);
}
return map;
} catch (ScriptException e) {
iter.close(e);
throw e;
}
}
use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class SharedArrayBufferConstructor method AllocateSharedArrayBuffer.
/**
* AllocateSharedArrayBuffer( constructor, byteLength )
*
* @param cx
* the execution context
* @param constructor
* the constructor function
* @param byteLength
* the buffer byte length
* @return the new shared array buffer object
*/
public static SharedArrayBufferObject AllocateSharedArrayBuffer(ExecutionContext cx, Constructor constructor, long byteLength) {
/* steps 1-2 */
ScriptObject proto = GetPrototypeFromConstructor(cx, constructor, Intrinsics.SharedArrayBufferPrototype);
/* step 3 */
assert byteLength >= 0;
/* steps 4-5 */
ByteBuffer block = CreateSharedByteDataBlock(cx, byteLength);
/* steps 1-2, 6-8 */
return new SharedArrayBufferObject(cx.getRealm(), block, byteLength, proto);
}
Aggregations