use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject in project es6draft by anba.
the class ArrayPrototype method iterationKindForSparse.
private static IterationKind iterationKindForSparse(OrdinaryObject arrayLike, long length) {
IterationKind iteration = IterationKind.SparseOwnKeys;
int protoDepth = 0;
long indexed = 0;
for (OrdinaryObject object = arrayLike; ; ) {
indexed += object.getIndexedSize();
ScriptObject prototype = object.getPrototype();
if (prototype == null) {
break;
}
if (!(prototype instanceof OrdinaryObject)) {
return IterationKind.Slow;
}
object = (OrdinaryObject) prototype;
if (object.hasSpecialIndexedProperties()) {
return IterationKind.Slow;
}
if (object.hasIndexedProperties()) {
if (object.hasIndexedAccessors()) {
return IterationKind.Slow;
}
iteration = IterationKind.InheritedKeys;
}
if (++protoDepth == MAX_PROTO_DEPTH) {
return IterationKind.Slow;
}
}
double density = indexed / (double) length;
if (density > 0.75) {
return IterationKind.Slow;
}
return iteration;
}
use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject in project es6draft by anba.
the class Properties method createAliasFunction.
private static void createAliasFunction(Realm realm, OrdinaryObject target, AliasFunctionLayout layout) {
Object propertyKey = layout.propertyKey;
Property fun;
if (propertyKey instanceof String) {
fun = target.lookupOwnProperty((String) propertyKey);
} else {
fun = target.lookupOwnProperty(((BuiltinSymbol) propertyKey).get());
}
assert fun != null : "property not found: " + propertyKey;
defineProperty(target, layout, valueProperty(layout, fun.getValue()));
}
use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject in project es6draft by anba.
the class Properties method createConstructor.
private static OrdinaryObject createConstructor(ExecutionContext cx, String className, OrdinaryObject proto, Converter converter, ObjectLayout layout) {
Entry<Function, MethodHandle> constructorEntry = findConstructor(layout);
if (constructorEntry != null) {
// User supplied method, perform manual ClassDefinitionEvaluation for constructors
Function function = constructorEntry.getKey();
MethodHandle unreflect = constructorEntry.getValue();
MethodHandle callMethod = getConstructorStaticMethodHandle(cx, converter, unreflect, MethodKind.Call);
MethodHandle constructMethod = getConstructorStaticMethodHandle(cx, converter, unreflect, MethodKind.Construct);
NativeConstructor constructor = new NativeConstructor(cx.getRealm(), className, function.arity(), callMethod, constructMethod);
constructor.defineOwnProperty(cx, "prototype", new PropertyDescriptor(proto, false, false, false));
proto.defineOwnProperty(cx, "constructor", new PropertyDescriptor(constructor, true, false, true));
return constructor;
}
// Create default constructor
String sourceText = String.format("(class %s { })", sanitizeName(className));
ScriptLoader scriptLoader = cx.getRealm().getScriptLoader();
Script script = scriptLoader.script(new Source("<Constructor>", 1), sourceText);
Object constructor = script.evaluate(cx);
assert constructor instanceof OrdinaryConstructorFunction : constructor.getClass();
return (OrdinaryConstructorFunction) constructor;
}
use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject in project es6draft by anba.
the class GeneratorFunctionConstructor method CreateDynamicConstructorGenerator.
private static OrdinaryConstructorGenerator CreateDynamicConstructorGenerator(ExecutionContext callerContext, ExecutionContext cx, Constructor newTarget, Object... args) {
/* step 1 (not applicable) */
/* step 2 (not applicable) */
/* step 3 */
Intrinsics fallbackProto = Intrinsics.Generator;
/* steps 4-10 */
String[] sourceText = functionSourceText(cx, args);
String parameters = sourceText[0], bodyText = sourceText[1];
/* steps 11, 13-20 */
Source source = functionSource(SourceKind.Generator, cx.getRealm(), callerContext);
RuntimeInfo.Function function;
try {
ScriptLoader scriptLoader = cx.getRealm().getScriptLoader();
function = scriptLoader.generator(source, parameters, bodyText).getFunction();
} catch (ParserException | CompilationException e) {
throw e.toScriptException(cx);
}
/* step 12 */
boolean strict = function.isStrict();
/* steps 21-22 */
ScriptObject proto = GetPrototypeFromConstructor(cx, newTarget, fallbackProto);
/* step 23 */
OrdinaryConstructorGenerator f = OrdinaryConstructorGenerator.FunctionAllocate(cx, proto, strict, FunctionKind.Normal);
/* steps 24-25 */
LexicalEnvironment<GlobalEnvironmentRecord> scope = f.getRealm().getGlobalEnv();
/* step 26 */
FunctionInitialize(f, FunctionKind.Normal, function, scope, newFunctionExecutable(source));
/* step 27 */
OrdinaryObject prototype = ObjectCreate(cx, Intrinsics.GeneratorPrototype);
MakeConstructor(f, true, prototype);
/* step 28 (not applicable) */
/* step 29 */
SetFunctionName(f, "anonymous");
/* step 30 */
return f;
}
use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject in project es6draft by anba.
the class ReflectParser method visit.
@Override
public Object visit(SuperPropertyAccessor node, Void value) {
Object object = superNode(node);
Object property = createIdentifier(node.getName());
boolean computed = false;
if (hasBuilder(Type.MemberExpression)) {
return call(Type.MemberExpression, node, object, property, computed);
}
OrdinaryObject expression = createExpression(node, Type.MemberExpression);
addProperty(expression, "object", object);
addProperty(expression, "property", property);
addProperty(expression, "computed", computed);
return expression;
}
Aggregations