Chromium Code Reviews| Index: src/builtins.cc |
| diff --git a/src/builtins.cc b/src/builtins.cc |
| index 3b4710dee426fcc172b84c624b3a50655221ee89..17be78afc6793ba73b41d66fd5cddd2972bf6b2f 100644 |
| --- a/src/builtins.cc |
| +++ b/src/builtins.cc |
| @@ -1489,6 +1489,41 @@ BUILTIN(ObjectAssign) { |
| } |
| +// ES6 section 19.1.2.2 Object.create ( O [ , Properties ] ) |
| +BUILTIN(ObjectCreate) { |
| + HandleScope scope(isolate); |
| + Handle<Object> prototype = args.atOrUndefined(isolate, 1); |
| + if (!prototype->IsNull() && !prototype->IsJSReceiver()) { |
| + THROW_NEW_ERROR_RETURN_FAILURE( |
| + isolate, NewTypeError(MessageTemplate::kProtoObjectOrNull, prototype)); |
| + } |
| + |
| + // Generate the map with the specified {prototype} based on the Object |
| + // function's initial map from the current native context. |
| + // TODO(bmeurer): Use a dedicated cache for Object.create; think about |
| + // slack tracking for Object.create. |
| + Handle<Map> map(isolate->native_context()->object_function()->initial_map(), |
| + isolate); |
| + if (map->prototype() != *prototype) { |
| + map = Map::TransitionToPrototype(map, prototype, FAST_PROTOTYPE); |
| + } |
| + |
| + // Actually allocate the object. |
| + Handle<JSObject> object = isolate->factory()->NewJSObjectFromMap(map); |
| + |
| + // Define the properties if properties was specified and is not undefined. |
| + if (args.length() >= 3) { |
| + Handle<Object> properties = args.at<Object>(2); |
|
Camillo Bruni
2015/12/30 08:54:30
you could use atOrUndefined here ;) (I have to sel
Benedikt Meurer
2015/12/30 13:13:46
Hah, gotcha :-)
|
| + if (!properties->IsUndefined()) { |
| + RETURN_FAILURE_ON_EXCEPTION( |
| + isolate, JSReceiver::DefineProperties(isolate, object, properties)); |
| + } |
| + } |
| + |
| + return *object; |
| +} |
| + |
| + |
| namespace { |
| bool CodeGenerationFromStringsAllowed(Isolate* isolate, |