// https://tc39.github.io/ecma262/#sec-reflect.setprototypeof EncodedJSValue JSC_HOST_CALL reflectObjectSetPrototypeOf(ExecState* exec) { JSValue target = exec->argument(0); if (!target.isObject()) return JSValue::encode(throwTypeError(exec, ASCIILiteral("Reflect.setPrototypeOf requires the first argument be an object"))); JSValue proto = exec->argument(1); if (!proto.isObject() && !proto.isNull()) return JSValue::encode(throwTypeError(exec, ASCIILiteral("Reflect.setPrototypeOf requires the second argument be either an object or null"))); JSObject* object = asObject(target); if (!checkProtoSetterAccessAllowed(exec, object)) return JSValue::encode(jsBoolean(false)); VM& vm = exec->vm(); bool shouldThrowIfCantSet = false; bool didSetPrototype = object->setPrototype(vm, exec, proto, shouldThrowIfCantSet); if (vm.exception()) return JSValue::encode(JSValue()); return JSValue::encode(jsBoolean(didSetPrototype)); }
// http://www.ecma-international.org/ecma-262/6.0/#sec-reflect.setprototypeof EncodedJSValue JSC_HOST_CALL reflectObjectSetPrototypeOf(ExecState* exec) { JSValue target = exec->argument(0); if (!target.isObject()) return JSValue::encode(throwTypeError(exec, ASCIILiteral("Reflect.setPrototypeOf requires the first argument be an object"))); JSValue proto = exec->argument(1); if (!proto.isObject() && !proto.isNull()) return JSValue::encode(throwTypeError(exec, ASCIILiteral("Reflect.setPrototypeOf requires the second argument be either an object or null"))); JSObject* object = asObject(target); if (!checkProtoSetterAccessAllowed(exec, object)) return JSValue::encode(jsBoolean(false)); if (object->prototype() == proto) return JSValue::encode(jsBoolean(true)); if (!object->isExtensible()) return JSValue::encode(jsBoolean(false)); return JSValue::encode(jsBoolean(object->setPrototypeWithCycleCheck(exec, proto))); }