Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(532)

Unified Diff: src/builtins/builtins-object.cc

Issue 2421803002: [builtins] Migrate Object.setPrototypeOf to C++. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/builtins/builtins.h ('k') | src/js/v8natives.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins/builtins-object.cc
diff --git a/src/builtins/builtins-object.cc b/src/builtins/builtins-object.cc
index fd08f3757ffe729176b0b00ee1d60dea6e1b4c66..5899879778ad95eb83d51b3fd13e6c354518b5c0 100644
--- a/src/builtins/builtins-object.cc
+++ b/src/builtins/builtins-object.cc
@@ -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);
« no previous file with comments | « src/builtins/builtins.h ('k') | src/js/v8natives.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698