// https://tc39.github.io/ecma262/#sec-reflect.construct EncodedJSValue JSC_HOST_CALL reflectObjectConstruct(ExecState* exec) { VM& vm = exec->vm(); auto scope = DECLARE_THROW_SCOPE(vm); JSValue target = exec->argument(0); if (!target.isObject()) return JSValue::encode(throwTypeError(exec, scope, ASCIILiteral("Reflect.construct requires the first argument be a constructor"))); ConstructData constructData; ConstructType constructType; if (!target.isConstructor(constructType, constructData)) return JSValue::encode(throwTypeError(exec, scope, ASCIILiteral("Reflect.construct requires the first argument be a constructor"))); JSValue newTarget = target; if (exec->argumentCount() >= 3) { newTarget = exec->argument(2); if (!newTarget.isConstructor()) return JSValue::encode(throwTypeError(exec, scope, ASCIILiteral("Reflect.construct requires the third argument be a constructor if present"))); } MarkedArgumentBuffer arguments; JSObject* argumentsObject = jsDynamicCast<JSObject*>(exec->argument(1)); if (!argumentsObject) return JSValue::encode(throwTypeError(exec, scope, ASCIILiteral("Reflect.construct requires the second argument be an object"))); createListFromArrayLike(exec, argumentsObject, RuntimeTypeMaskAllTypes, ASCIILiteral("This error must not be raised"), [&] (JSValue value, RuntimeType) -> bool { arguments.append(value); return false; }); RETURN_IF_EXCEPTION(scope, encodedJSValue()); scope.release(); return JSValue::encode(construct(exec, target, constructType, constructData, arguments, newTarget)); }
// https://tc39.github.io/ecma262/#sec-reflect.construct EncodedJSValue JSC_HOST_CALL reflectObjectConstruct(ExecState* exec) { JSValue target = exec->argument(0); if (!target.isObject()) return JSValue::encode(throwTypeError(exec, ASCIILiteral("Reflect.construct requires the first argument be a constructor"))); ConstructData constructData; ConstructType constructType; if (!target.isConstructor(constructType, constructData)) return JSValue::encode(throwTypeError(exec, ASCIILiteral("Reflect.construct requires the first argument be a constructor"))); JSValue newTarget = target; if (exec->argumentCount() >= 3) { newTarget = exec->argument(2); if (!newTarget.isConstructor()) return JSValue::encode(throwTypeError(exec, ASCIILiteral("Reflect.construct requires the third argument be a constructor if present"))); } MarkedArgumentBuffer arguments; JSObject* argumentsObject = jsDynamicCast<JSObject*>(exec->argument(1)); if (!argumentsObject) return JSValue::encode(throwTypeError(exec, ASCIILiteral("Reflect.construct requires the second argument be an object"))); createListFromArrayLike(exec, argumentsObject, RuntimeTypeMaskAllTypes, ASCIILiteral("This error must not be raised"), [&] (JSValue value, RuntimeType) -> bool { arguments.append(value); return false; }); if (exec->hadException()) return JSValue::encode(jsUndefined()); return JSValue::encode(construct(exec, target, constructType, constructData, arguments, newTarget)); }