OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/builtins.h" | 5 #include "src/builtins.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
9 #include "src/arguments.h" | 9 #include "src/arguments.h" |
10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
(...skipping 1471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1482 isolate, status, Runtime::SetObjectProperty(isolate, to, next_key, | 1482 isolate, status, Runtime::SetObjectProperty(isolate, to, next_key, |
1483 prop_value, STRICT)); | 1483 prop_value, STRICT)); |
1484 } | 1484 } |
1485 } | 1485 } |
1486 } | 1486 } |
1487 // 5. Return to. | 1487 // 5. Return to. |
1488 return *to; | 1488 return *to; |
1489 } | 1489 } |
1490 | 1490 |
1491 | 1491 |
1492 // ES6 section 19.1.2.2 Object.create ( O [ , Properties ] ) | |
1493 BUILTIN(ObjectCreate) { | |
1494 HandleScope scope(isolate); | |
1495 Handle<Object> prototype = args.atOrUndefined(isolate, 1); | |
1496 if (!prototype->IsNull() && !prototype->IsJSReceiver()) { | |
1497 THROW_NEW_ERROR_RETURN_FAILURE( | |
1498 isolate, NewTypeError(MessageTemplate::kProtoObjectOrNull, prototype)); | |
1499 } | |
1500 | |
1501 // Generate the map with the specified {prototype} based on the Object | |
1502 // function's initial map from the current native context. | |
1503 // TODO(bmeurer): Use a dedicated cache for Object.create; think about | |
1504 // slack tracking for Object.create. | |
1505 Handle<Map> map(isolate->native_context()->object_function()->initial_map(), | |
1506 isolate); | |
1507 if (map->prototype() != *prototype) { | |
1508 map = Map::TransitionToPrototype(map, prototype, FAST_PROTOTYPE); | |
1509 } | |
1510 | |
1511 // Actually allocate the object. | |
1512 Handle<JSObject> object = isolate->factory()->NewJSObjectFromMap(map); | |
1513 | |
1514 // Define the properties if properties was specified and is not undefined. | |
1515 if (args.length() >= 3) { | |
1516 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 :-)
| |
1517 if (!properties->IsUndefined()) { | |
1518 RETURN_FAILURE_ON_EXCEPTION( | |
1519 isolate, JSReceiver::DefineProperties(isolate, object, properties)); | |
1520 } | |
1521 } | |
1522 | |
1523 return *object; | |
1524 } | |
1525 | |
1526 | |
1492 namespace { | 1527 namespace { |
1493 | 1528 |
1494 bool CodeGenerationFromStringsAllowed(Isolate* isolate, | 1529 bool CodeGenerationFromStringsAllowed(Isolate* isolate, |
1495 Handle<Context> context) { | 1530 Handle<Context> context) { |
1496 DCHECK(context->allow_code_gen_from_strings()->IsFalse()); | 1531 DCHECK(context->allow_code_gen_from_strings()->IsFalse()); |
1497 // Check with callback if set. | 1532 // Check with callback if set. |
1498 AllowCodeGenerationFromStringsCallback callback = | 1533 AllowCodeGenerationFromStringsCallback callback = |
1499 isolate->allow_code_gen_callback(); | 1534 isolate->allow_code_gen_callback(); |
1500 if (callback == NULL) { | 1535 if (callback == NULL) { |
1501 // No callback set and code generation disallowed. | 1536 // No callback set and code generation disallowed. |
(...skipping 1242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2744 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 2779 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
2745 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 2780 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
2746 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 2781 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
2747 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 2782 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
2748 #undef DEFINE_BUILTIN_ACCESSOR_C | 2783 #undef DEFINE_BUILTIN_ACCESSOR_C |
2749 #undef DEFINE_BUILTIN_ACCESSOR_A | 2784 #undef DEFINE_BUILTIN_ACCESSOR_A |
2750 | 2785 |
2751 | 2786 |
2752 } // namespace internal | 2787 } // namespace internal |
2753 } // namespace v8 | 2788 } // namespace v8 |
OLD | NEW |