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 Handle<Object> properties = args.atOrUndefined(isolate, 2); |
| 1516 if (!properties->IsUndefined()) { |
| 1517 RETURN_FAILURE_ON_EXCEPTION( |
| 1518 isolate, JSReceiver::DefineProperties(isolate, object, properties)); |
| 1519 } |
| 1520 |
| 1521 return *object; |
| 1522 } |
| 1523 |
| 1524 |
1492 namespace { | 1525 namespace { |
1493 | 1526 |
1494 bool CodeGenerationFromStringsAllowed(Isolate* isolate, | 1527 bool CodeGenerationFromStringsAllowed(Isolate* isolate, |
1495 Handle<Context> context) { | 1528 Handle<Context> context) { |
1496 DCHECK(context->allow_code_gen_from_strings()->IsFalse()); | 1529 DCHECK(context->allow_code_gen_from_strings()->IsFalse()); |
1497 // Check with callback if set. | 1530 // Check with callback if set. |
1498 AllowCodeGenerationFromStringsCallback callback = | 1531 AllowCodeGenerationFromStringsCallback callback = |
1499 isolate->allow_code_gen_callback(); | 1532 isolate->allow_code_gen_callback(); |
1500 if (callback == NULL) { | 1533 if (callback == NULL) { |
1501 // No callback set and code generation disallowed. | 1534 // 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) | 2777 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
2745 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 2778 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
2746 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 2779 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
2747 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 2780 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
2748 #undef DEFINE_BUILTIN_ACCESSOR_C | 2781 #undef DEFINE_BUILTIN_ACCESSOR_C |
2749 #undef DEFINE_BUILTIN_ACCESSOR_A | 2782 #undef DEFINE_BUILTIN_ACCESSOR_A |
2750 | 2783 |
2751 | 2784 |
2752 } // namespace internal | 2785 } // namespace internal |
2753 } // namespace v8 | 2786 } // namespace v8 |
OLD | NEW |