| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/bootstrapper.h" | 5 #include "src/bootstrapper.h" |
| 6 | 6 |
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
| 9 #include "src/base/ieee754.h" | 9 #include "src/base/ieee754.h" |
| 10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
| (...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 959 | 959 |
| 960 static void InstallWithIntrinsicDefaultProto(Isolate* isolate, | 960 static void InstallWithIntrinsicDefaultProto(Isolate* isolate, |
| 961 Handle<JSFunction> function, | 961 Handle<JSFunction> function, |
| 962 int context_index) { | 962 int context_index) { |
| 963 Handle<Smi> index(Smi::FromInt(context_index), isolate); | 963 Handle<Smi> index(Smi::FromInt(context_index), isolate); |
| 964 JSObject::AddProperty( | 964 JSObject::AddProperty( |
| 965 function, isolate->factory()->native_context_index_symbol(), index, NONE); | 965 function, isolate->factory()->native_context_index_symbol(), index, NONE); |
| 966 isolate->native_context()->set(context_index, *function); | 966 isolate->native_context()->set(context_index, *function); |
| 967 } | 967 } |
| 968 | 968 |
| 969 static void InstallError(Isolate* isolate, Handle<JSObject> global, | |
| 970 Handle<String> name, int context_index) { | |
| 971 Factory* factory = isolate->factory(); | |
| 972 | |
| 973 Handle<JSFunction> error_fun = | |
| 974 InstallFunction(global, name, JS_ERROR_TYPE, JSObject::kHeaderSize, | |
| 975 isolate->initial_object_prototype(), | |
| 976 Builtins::kErrorConstructor, DONT_ENUM); | |
| 977 error_fun->shared()->set_instance_class_name(*factory->Error_string()); | |
| 978 error_fun->shared()->DontAdaptArguments(); | |
| 979 error_fun->shared()->set_construct_stub( | |
| 980 *isolate->builtins()->ErrorConstructor()); | |
| 981 error_fun->shared()->set_length(1); | |
| 982 error_fun->shared()->set_native(true); | |
| 983 | |
| 984 if (context_index == Context::ERROR_FUNCTION_INDEX) { | |
| 985 Handle<JSFunction> capture_stack_trace_fun = | |
| 986 SimpleInstallFunction(error_fun, "captureStackTrace", | |
| 987 Builtins::kErrorCaptureStackTrace, 2, false); | |
| 988 capture_stack_trace_fun->shared()->set_native(true); | |
| 989 } | |
| 990 | |
| 991 InstallWithIntrinsicDefaultProto(isolate, error_fun, context_index); | |
| 992 | |
| 993 { | |
| 994 Handle<JSObject> prototype = | |
| 995 factory->NewJSObject(isolate->object_function(), TENURED); | |
| 996 | |
| 997 JSObject::AddProperty(prototype, factory->name_string(), name, DONT_ENUM); | |
| 998 JSObject::AddProperty(prototype, factory->message_string(), | |
| 999 factory->empty_string(), DONT_ENUM); | |
| 1000 JSObject::AddProperty(prototype, factory->constructor_string(), error_fun, | |
| 1001 DONT_ENUM); | |
| 1002 | |
| 1003 Handle<JSFunction> to_string_fun = | |
| 1004 SimpleInstallFunction(prototype, factory->toString_string(), | |
| 1005 Builtins::kErrorPrototypeToString, 0, true); | |
| 1006 to_string_fun->shared()->set_native(true); | |
| 1007 | |
| 1008 if (context_index != Context::ERROR_FUNCTION_INDEX) { | |
| 1009 Handle<JSFunction> global_error = isolate->error_function(); | |
| 1010 CHECK(JSReceiver::SetPrototype(error_fun, global_error, false, | |
| 1011 Object::THROW_ON_ERROR) | |
| 1012 .FromMaybe(false)); | |
| 1013 CHECK(JSReceiver::SetPrototype(prototype, | |
| 1014 handle(global_error->prototype(), isolate), | |
| 1015 false, Object::THROW_ON_ERROR) | |
| 1016 .FromMaybe(false)); | |
| 1017 } | |
| 1018 | |
| 1019 Accessors::FunctionSetPrototype(error_fun, prototype).Assert(); | |
| 1020 } | |
| 1021 | |
| 1022 Handle<Map> initial_map(error_fun->initial_map()); | |
| 1023 Map::EnsureDescriptorSlack(initial_map, 1); | |
| 1024 | |
| 1025 PropertyAttributes attribs = DONT_ENUM; | |
| 1026 Handle<AccessorInfo> error_stack = | |
| 1027 Accessors::ErrorStackInfo(isolate, attribs); | |
| 1028 { | |
| 1029 AccessorConstantDescriptor d(Handle<Name>(Name::cast(error_stack->name())), | |
| 1030 error_stack, attribs); | |
| 1031 initial_map->AppendDescriptor(&d); | |
| 1032 } | |
| 1033 } | |
| 1034 | 969 |
| 1035 // This is only called if we are not using snapshots. The equivalent | 970 // This is only called if we are not using snapshots. The equivalent |
| 1036 // work in the snapshot case is done in HookUpGlobalObject. | 971 // work in the snapshot case is done in HookUpGlobalObject. |
| 1037 void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, | 972 void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, |
| 1038 Handle<JSFunction> empty_function, | 973 Handle<JSFunction> empty_function, |
| 1039 GlobalContextType context_type) { | 974 GlobalContextType context_type) { |
| 1040 // --- N a t i v e C o n t e x t --- | 975 // --- N a t i v e C o n t e x t --- |
| 1041 // Use the empty function as closure (no scope info). | 976 // Use the empty function as closure (no scope info). |
| 1042 native_context()->set_closure(*empty_function); | 977 native_context()->set_closure(*empty_function); |
| 1043 native_context()->set_previous(NULL); | 978 native_context()->set_previous(NULL); |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1567 initial_map->AppendDescriptor(&field); | 1502 initial_map->AppendDescriptor(&field); |
| 1568 | 1503 |
| 1569 static const int num_fields = JSRegExp::kInObjectFieldCount; | 1504 static const int num_fields = JSRegExp::kInObjectFieldCount; |
| 1570 initial_map->SetInObjectProperties(num_fields); | 1505 initial_map->SetInObjectProperties(num_fields); |
| 1571 initial_map->set_unused_property_fields(0); | 1506 initial_map->set_unused_property_fields(0); |
| 1572 initial_map->set_instance_size(initial_map->instance_size() + | 1507 initial_map->set_instance_size(initial_map->instance_size() + |
| 1573 num_fields * kPointerSize); | 1508 num_fields * kPointerSize); |
| 1574 } | 1509 } |
| 1575 | 1510 |
| 1576 { // -- E r r o r | 1511 { // -- E r r o r |
| 1577 InstallError(isolate, global, factory->Error_string(), | 1512 Handle<JSFunction> error_fun = InstallFunction( |
| 1578 Context::ERROR_FUNCTION_INDEX); | 1513 global, "Error", JS_ERROR_TYPE, JSObject::kHeaderSize, |
| 1514 isolate->initial_object_prototype(), Builtins::kIllegal); |
| 1515 InstallWithIntrinsicDefaultProto(isolate, error_fun, |
| 1516 Context::ERROR_FUNCTION_INDEX); |
| 1579 } | 1517 } |
| 1580 | 1518 |
| 1581 { // -- E v a l E r r o r | 1519 { // -- E v a l E r r o r |
| 1582 InstallError(isolate, global, factory->EvalError_string(), | 1520 Handle<JSFunction> eval_error_fun = InstallFunction( |
| 1583 Context::EVAL_ERROR_FUNCTION_INDEX); | 1521 global, "EvalError", JS_ERROR_TYPE, JSObject::kHeaderSize, |
| 1522 isolate->initial_object_prototype(), Builtins::kIllegal); |
| 1523 InstallWithIntrinsicDefaultProto(isolate, eval_error_fun, |
| 1524 Context::EVAL_ERROR_FUNCTION_INDEX); |
| 1584 } | 1525 } |
| 1585 | 1526 |
| 1586 { // -- R a n g e E r r o r | 1527 { // -- R a n g e E r r o r |
| 1587 InstallError(isolate, global, factory->RangeError_string(), | 1528 Handle<JSFunction> range_error_fun = InstallFunction( |
| 1588 Context::RANGE_ERROR_FUNCTION_INDEX); | 1529 global, "RangeError", JS_ERROR_TYPE, JSObject::kHeaderSize, |
| 1530 isolate->initial_object_prototype(), Builtins::kIllegal); |
| 1531 InstallWithIntrinsicDefaultProto(isolate, range_error_fun, |
| 1532 Context::RANGE_ERROR_FUNCTION_INDEX); |
| 1589 } | 1533 } |
| 1590 | 1534 |
| 1591 { // -- R e f e r e n c e E r r o r | 1535 { // -- R e f e r e n c e E r r o r |
| 1592 InstallError(isolate, global, factory->ReferenceError_string(), | 1536 Handle<JSFunction> reference_error_fun = InstallFunction( |
| 1593 Context::REFERENCE_ERROR_FUNCTION_INDEX); | 1537 global, "ReferenceError", JS_ERROR_TYPE, JSObject::kHeaderSize, |
| 1538 isolate->initial_object_prototype(), Builtins::kIllegal); |
| 1539 InstallWithIntrinsicDefaultProto(isolate, reference_error_fun, |
| 1540 Context::REFERENCE_ERROR_FUNCTION_INDEX); |
| 1594 } | 1541 } |
| 1595 | 1542 |
| 1596 { // -- S y n t a x E r r o r | 1543 { // -- S y n t a x E r r o r |
| 1597 InstallError(isolate, global, factory->SyntaxError_string(), | 1544 Handle<JSFunction> syntax_error_fun = InstallFunction( |
| 1598 Context::SYNTAX_ERROR_FUNCTION_INDEX); | 1545 global, "SyntaxError", JS_ERROR_TYPE, JSObject::kHeaderSize, |
| 1546 isolate->initial_object_prototype(), Builtins::kIllegal); |
| 1547 InstallWithIntrinsicDefaultProto(isolate, syntax_error_fun, |
| 1548 Context::SYNTAX_ERROR_FUNCTION_INDEX); |
| 1599 } | 1549 } |
| 1600 | 1550 |
| 1601 { // -- T y p e E r r o r | 1551 { // -- T y p e E r r o r |
| 1602 InstallError(isolate, global, factory->TypeError_string(), | 1552 Handle<JSFunction> type_error_fun = InstallFunction( |
| 1603 Context::TYPE_ERROR_FUNCTION_INDEX); | 1553 global, "TypeError", JS_ERROR_TYPE, JSObject::kHeaderSize, |
| 1554 isolate->initial_object_prototype(), Builtins::kIllegal); |
| 1555 InstallWithIntrinsicDefaultProto(isolate, type_error_fun, |
| 1556 Context::TYPE_ERROR_FUNCTION_INDEX); |
| 1604 } | 1557 } |
| 1605 | 1558 |
| 1606 { // -- U R I E r r o r | 1559 { // -- U R I E r r o r |
| 1607 InstallError(isolate, global, factory->URIError_string(), | 1560 Handle<JSFunction> uri_error_fun = InstallFunction( |
| 1608 Context::URI_ERROR_FUNCTION_INDEX); | 1561 global, "URIError", JS_ERROR_TYPE, JSObject::kHeaderSize, |
| 1562 isolate->initial_object_prototype(), Builtins::kIllegal); |
| 1563 InstallWithIntrinsicDefaultProto(isolate, uri_error_fun, |
| 1564 Context::URI_ERROR_FUNCTION_INDEX); |
| 1609 } | 1565 } |
| 1610 | 1566 |
| 1611 // Initialize the embedder data slot. | 1567 // Initialize the embedder data slot. |
| 1612 Handle<FixedArray> embedder_data = factory->NewFixedArray(3); | 1568 Handle<FixedArray> embedder_data = factory->NewFixedArray(3); |
| 1613 native_context()->set_embedder_data(*embedder_data); | 1569 native_context()->set_embedder_data(*embedder_data); |
| 1614 | 1570 |
| 1615 { // -- J S O N | 1571 { // -- J S O N |
| 1616 Handle<String> name = factory->InternalizeUtf8String("JSON"); | 1572 Handle<String> name = factory->InternalizeUtf8String("JSON"); |
| 1617 Handle<JSFunction> cons = factory->NewFunction(name); | 1573 Handle<JSFunction> cons = factory->NewFunction(name); |
| 1618 JSFunction::SetInstancePrototype(cons, | 1574 JSFunction::SetInstancePrototype(cons, |
| (...skipping 2376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3995 } | 3951 } |
| 3996 | 3952 |
| 3997 | 3953 |
| 3998 // Called when the top-level V8 mutex is destroyed. | 3954 // Called when the top-level V8 mutex is destroyed. |
| 3999 void Bootstrapper::FreeThreadResources() { | 3955 void Bootstrapper::FreeThreadResources() { |
| 4000 DCHECK(!IsActive()); | 3956 DCHECK(!IsActive()); |
| 4001 } | 3957 } |
| 4002 | 3958 |
| 4003 } // namespace internal | 3959 } // namespace internal |
| 4004 } // namespace v8 | 3960 } // namespace v8 |
| OLD | NEW |