Commit 4a88d8fb authored by bmeurer's avatar bmeurer Committed by Commit bot

[builtins] Migrate Object.setPrototypeOf to C++.

This calls into C++ anyways, so no need to add the JavaScript wrapper
around it.

R=yangguo@chromium.org
BUG=v8:5049

Review-Url: https://codereview.chromium.org/2421803002
Cr-Commit-Position: refs/heads/master@{#40293}
parent cdc3459a
......@@ -1161,6 +1161,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
object_function, "getPrototypeOf", Builtins::kObjectGetPrototypeOf,
1, false);
native_context()->set_object_get_prototype_of(*object_get_prototype_of);
SimpleInstallFunction(object_function, "setPrototypeOf",
Builtins::kObjectSetPrototypeOf, 2, false);
Handle<JSFunction> object_is_extensible = SimpleInstallFunction(
object_function, "isExtensible", Builtins::kObjectIsExtensible,
......
......@@ -688,6 +688,40 @@ BUILTIN(ObjectGetPrototypeOf) {
JSReceiver::GetPrototype(isolate, receiver));
}
// ES6 section 19.1.2.21 Object.setPrototypeOf ( O, proto )
BUILTIN(ObjectSetPrototypeOf) {
HandleScope scope(isolate);
// 1. Let O be ? RequireObjectCoercible(O).
Handle<Object> object = args.atOrUndefined(isolate, 1);
if (object->IsNull(isolate) || object->IsUndefined(isolate)) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kCalledOnNullOrUndefined,
isolate->factory()->NewStringFromAsciiChecked(
"Object.setPrototypeOf")));
}
// 2. If Type(proto) is neither Object nor Null, throw a TypeError exception.
Handle<Object> proto = args.atOrUndefined(isolate, 2);
if (!proto->IsNull(isolate) && !proto->IsJSReceiver()) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kProtoObjectOrNull, proto));
}
// 3. If Type(O) is not Object, return O.
if (!object->IsJSReceiver()) return *object;
Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(object);
// 4. Let status be ? O.[[SetPrototypeOf]](proto).
// 5. If status is false, throw a TypeError exception.
MAYBE_RETURN(
JSReceiver::SetPrototype(receiver, proto, true, Object::THROW_ON_ERROR),
isolate->heap()->exception());
// 6. Return O.
return *receiver;
}
// ES6 section 19.1.2.6 Object.getOwnPropertyDescriptor ( O, P )
BUILTIN(ObjectGetOwnPropertyDescriptor) {
HandleScope scope(isolate);
......
......@@ -525,6 +525,7 @@ namespace internal {
CPP(ObjectGetOwnPropertyNames) \
CPP(ObjectGetOwnPropertySymbols) \
CPP(ObjectGetPrototypeOf) \
CPP(ObjectSetPrototypeOf) \
/* ES6 section 19.1.3.2 Object.prototype.hasOwnProperty */ \
TFJ(ObjectHasOwnProperty, 2) \
CPP(ObjectIs) \
......
......@@ -104,21 +104,6 @@ function GetMethod(obj, p) {
throw %make_type_error(kCalledNonCallable, typeof func);
}
// ES6 section 19.1.2.18.
function ObjectSetPrototypeOf(obj, proto) {
CHECK_OBJECT_COERCIBLE(obj, "Object.setPrototypeOf");
if (proto !== null && !IS_RECEIVER(proto)) {
throw %make_type_error(kProtoObjectOrNull, proto);
}
if (IS_RECEIVER(obj)) {
%SetPrototype(obj, proto);
}
return obj;
}
// ES6 B.2.2.1.1
function ObjectGetProto() {
return %object_get_prototype_of(this);
......@@ -169,14 +154,6 @@ utils.InstallFunctions(GlobalObject.prototype, DONT_ENUM, [
utils.InstallGetterSetter(
GlobalObject.prototype, "__proto__", ObjectGetProto, ObjectSetProto);
// Set up non-enumerable functions in the Object object.
utils.InstallFunctions(GlobalObject, DONT_ENUM, [
"setPrototypeOf", ObjectSetPrototypeOf,
// getOwnPropertySymbols is added in symbol.js.
// Others are added in bootstrapper.cc.
]);
// ----------------------------------------------------------------------------
// Number
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment