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 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1109 | 1109 |
1110 static void InstallWithIntrinsicDefaultProto(Isolate* isolate, | 1110 static void InstallWithIntrinsicDefaultProto(Isolate* isolate, |
1111 Handle<JSFunction> function, | 1111 Handle<JSFunction> function, |
1112 int context_index) { | 1112 int context_index) { |
1113 Handle<Smi> index(Smi::FromInt(context_index), isolate); | 1113 Handle<Smi> index(Smi::FromInt(context_index), isolate); |
1114 JSObject::AddProperty( | 1114 JSObject::AddProperty( |
1115 function, isolate->factory()->native_context_index_symbol(), index, NONE); | 1115 function, isolate->factory()->native_context_index_symbol(), index, NONE); |
1116 isolate->native_context()->set(context_index, *function); | 1116 isolate->native_context()->set(context_index, *function); |
1117 } | 1117 } |
1118 | 1118 |
1119 static void InstallError(Isolate* isolate, Handle<JSObject> global, | |
1120 Handle<String> name, int context_index) { | |
1121 Factory* factory = isolate->factory(); | |
1122 | |
1123 Handle<JSFunction> error_fun = | |
1124 InstallFunction(global, name, JS_ERROR_TYPE, JSObject::kHeaderSize, | |
1125 isolate->initial_object_prototype(), | |
1126 Builtins::kErrorConstructor, DONT_ENUM); | |
1127 error_fun->shared()->set_instance_class_name(*factory->Error_string()); | |
1128 error_fun->shared()->DontAdaptArguments(); | |
1129 error_fun->shared()->set_construct_stub( | |
1130 *isolate->builtins()->ErrorConstructor()); | |
1131 error_fun->shared()->set_length(1); | |
1132 error_fun->shared()->set_native(true); | |
1133 | |
1134 if (context_index == Context::ERROR_FUNCTION_INDEX) { | |
1135 Handle<JSFunction> capture_stack_trace_fun = | |
1136 SimpleInstallFunction(error_fun, "captureStackTrace", | |
1137 Builtins::kErrorCaptureStackTrace, 2, false); | |
1138 capture_stack_trace_fun->shared()->set_native(true); | |
1139 } | |
1140 | |
1141 InstallWithIntrinsicDefaultProto(isolate, error_fun, context_index); | |
1142 | |
1143 { | |
1144 Handle<JSObject> prototype = | |
1145 factory->NewJSObject(isolate->object_function(), TENURED); | |
1146 | |
1147 JSObject::AddProperty(prototype, factory->name_string(), name, DONT_ENUM); | |
1148 JSObject::AddProperty(prototype, factory->message_string(), | |
1149 factory->empty_string(), DONT_ENUM); | |
1150 JSObject::AddProperty(prototype, factory->constructor_string(), error_fun, | |
1151 DONT_ENUM); | |
1152 | |
1153 Handle<JSFunction> to_string_fun = | |
1154 SimpleInstallFunction(prototype, factory->toString_string(), | |
1155 Builtins::kErrorPrototypeToString, 0, true); | |
1156 to_string_fun->shared()->set_native(true); | |
1157 | |
1158 if (context_index != Context::ERROR_FUNCTION_INDEX) { | |
1159 Handle<JSFunction> globalError = isolate->error_function(); | |
Yang
2016/07/15 13:10:11
let's name this "global_error" to be consistent wi
jgruber
2016/07/18 13:06:11
Done.
| |
1160 CHECK(JSReceiver::SetPrototype(error_fun, globalError, false, | |
1161 Object::THROW_ON_ERROR) | |
1162 .FromMaybe(false)); | |
1163 CHECK(JSReceiver::SetPrototype(prototype, | |
1164 handle(globalError->prototype(), isolate), | |
1165 false, Object::THROW_ON_ERROR) | |
1166 .FromMaybe(false)); | |
1167 } | |
1168 | |
1169 Accessors::FunctionSetPrototype(error_fun, prototype).Assert(); | |
1170 } | |
1171 | |
1172 Handle<Map> initial_map(error_fun->initial_map()); | |
1173 Map::EnsureDescriptorSlack(initial_map, 1); | |
1174 | |
1175 PropertyAttributes attribs = DONT_ENUM; | |
1176 Handle<AccessorInfo> error_stack = | |
1177 Accessors::ErrorStackInfo(isolate, attribs); | |
1178 { | |
1179 AccessorConstantDescriptor d(Handle<Name>(Name::cast(error_stack->name())), | |
1180 error_stack, attribs); | |
1181 initial_map->AppendDescriptor(&d); | |
1182 } | |
1183 } | |
1119 | 1184 |
1120 // This is only called if we are not using snapshots. The equivalent | 1185 // This is only called if we are not using snapshots. The equivalent |
1121 // work in the snapshot case is done in HookUpGlobalObject. | 1186 // work in the snapshot case is done in HookUpGlobalObject. |
1122 void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, | 1187 void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, |
1123 Handle<JSFunction> empty_function, | 1188 Handle<JSFunction> empty_function, |
1124 GlobalContextType context_type) { | 1189 GlobalContextType context_type) { |
1125 // --- N a t i v e C o n t e x t --- | 1190 // --- N a t i v e C o n t e x t --- |
1126 // Use the empty function as closure (no scope info). | 1191 // Use the empty function as closure (no scope info). |
1127 native_context()->set_closure(*empty_function); | 1192 native_context()->set_closure(*empty_function); |
1128 native_context()->set_previous(NULL); | 1193 native_context()->set_previous(NULL); |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1652 initial_map->AppendDescriptor(&field); | 1717 initial_map->AppendDescriptor(&field); |
1653 | 1718 |
1654 static const int num_fields = JSRegExp::kInObjectFieldCount; | 1719 static const int num_fields = JSRegExp::kInObjectFieldCount; |
1655 initial_map->SetInObjectProperties(num_fields); | 1720 initial_map->SetInObjectProperties(num_fields); |
1656 initial_map->set_unused_property_fields(0); | 1721 initial_map->set_unused_property_fields(0); |
1657 initial_map->set_instance_size(initial_map->instance_size() + | 1722 initial_map->set_instance_size(initial_map->instance_size() + |
1658 num_fields * kPointerSize); | 1723 num_fields * kPointerSize); |
1659 } | 1724 } |
1660 | 1725 |
1661 { // -- E r r o r | 1726 { // -- E r r o r |
1662 Handle<JSFunction> error_fun = InstallFunction( | 1727 InstallError(isolate, global, factory->Error_string(), |
1663 global, "Error", JS_ERROR_TYPE, JSObject::kHeaderSize, | 1728 Context::ERROR_FUNCTION_INDEX); |
1664 isolate->initial_object_prototype(), Builtins::kIllegal); | |
1665 InstallWithIntrinsicDefaultProto(isolate, error_fun, | |
1666 Context::ERROR_FUNCTION_INDEX); | |
1667 } | 1729 } |
1668 | 1730 |
1669 { // -- E v a l E r r o r | 1731 { // -- E v a l E r r o r |
1670 Handle<JSFunction> eval_error_fun = InstallFunction( | 1732 InstallError(isolate, global, factory->EvalError_string(), |
1671 global, "EvalError", JS_ERROR_TYPE, JSObject::kHeaderSize, | 1733 Context::EVAL_ERROR_FUNCTION_INDEX); |
1672 isolate->initial_object_prototype(), Builtins::kIllegal); | |
1673 InstallWithIntrinsicDefaultProto(isolate, eval_error_fun, | |
1674 Context::EVAL_ERROR_FUNCTION_INDEX); | |
1675 } | 1734 } |
1676 | 1735 |
1677 { // -- R a n g e E r r o r | 1736 { // -- R a n g e E r r o r |
1678 Handle<JSFunction> range_error_fun = InstallFunction( | 1737 InstallError(isolate, global, factory->RangeError_string(), |
1679 global, "RangeError", JS_ERROR_TYPE, JSObject::kHeaderSize, | 1738 Context::RANGE_ERROR_FUNCTION_INDEX); |
1680 isolate->initial_object_prototype(), Builtins::kIllegal); | |
1681 InstallWithIntrinsicDefaultProto(isolate, range_error_fun, | |
1682 Context::RANGE_ERROR_FUNCTION_INDEX); | |
1683 } | 1739 } |
1684 | 1740 |
1685 { // -- R e f e r e n c e E r r o r | 1741 { // -- R e f e r e n c e E r r o r |
1686 Handle<JSFunction> reference_error_fun = InstallFunction( | 1742 InstallError(isolate, global, factory->ReferenceError_string(), |
1687 global, "ReferenceError", JS_ERROR_TYPE, JSObject::kHeaderSize, | 1743 Context::REFERENCE_ERROR_FUNCTION_INDEX); |
1688 isolate->initial_object_prototype(), Builtins::kIllegal); | |
1689 InstallWithIntrinsicDefaultProto(isolate, reference_error_fun, | |
1690 Context::REFERENCE_ERROR_FUNCTION_INDEX); | |
1691 } | 1744 } |
1692 | 1745 |
1693 { // -- S y n t a x E r r o r | 1746 { // -- S y n t a x E r r o r |
1694 Handle<JSFunction> syntax_error_fun = InstallFunction( | 1747 InstallError(isolate, global, factory->SyntaxError_string(), |
1695 global, "SyntaxError", JS_ERROR_TYPE, JSObject::kHeaderSize, | 1748 Context::SYNTAX_ERROR_FUNCTION_INDEX); |
1696 isolate->initial_object_prototype(), Builtins::kIllegal); | |
1697 InstallWithIntrinsicDefaultProto(isolate, syntax_error_fun, | |
1698 Context::SYNTAX_ERROR_FUNCTION_INDEX); | |
1699 } | 1749 } |
1700 | 1750 |
1701 { // -- T y p e E r r o r | 1751 { // -- T y p e E r r o r |
1702 Handle<JSFunction> type_error_fun = InstallFunction( | 1752 InstallError(isolate, global, factory->TypeError_string(), |
1703 global, "TypeError", JS_ERROR_TYPE, JSObject::kHeaderSize, | 1753 Context::TYPE_ERROR_FUNCTION_INDEX); |
1704 isolate->initial_object_prototype(), Builtins::kIllegal); | |
1705 InstallWithIntrinsicDefaultProto(isolate, type_error_fun, | |
1706 Context::TYPE_ERROR_FUNCTION_INDEX); | |
1707 } | 1754 } |
1708 | 1755 |
1709 { // -- U R I E r r o r | 1756 { // -- U R I E r r o r |
1710 Handle<JSFunction> uri_error_fun = InstallFunction( | 1757 InstallError(isolate, global, factory->URIError_string(), |
1711 global, "URIError", JS_ERROR_TYPE, JSObject::kHeaderSize, | 1758 Context::URI_ERROR_FUNCTION_INDEX); |
1712 isolate->initial_object_prototype(), Builtins::kIllegal); | |
1713 InstallWithIntrinsicDefaultProto(isolate, uri_error_fun, | |
1714 Context::URI_ERROR_FUNCTION_INDEX); | |
1715 } | 1759 } |
1716 | 1760 |
1717 // Initialize the embedder data slot. | 1761 // Initialize the embedder data slot. |
1718 Handle<FixedArray> embedder_data = factory->NewFixedArray(3); | 1762 Handle<FixedArray> embedder_data = factory->NewFixedArray(3); |
1719 native_context()->set_embedder_data(*embedder_data); | 1763 native_context()->set_embedder_data(*embedder_data); |
1720 | 1764 |
1721 { // -- J S O N | 1765 { // -- J S O N |
1722 Handle<String> name = factory->InternalizeUtf8String("JSON"); | 1766 Handle<String> name = factory->InternalizeUtf8String("JSON"); |
1723 Handle<JSFunction> cons = factory->NewFunction(name); | 1767 Handle<JSFunction> cons = factory->NewFunction(name); |
1724 JSFunction::SetInstancePrototype(cons, | 1768 JSFunction::SetInstancePrototype(cons, |
(...skipping 2376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4101 } | 4145 } |
4102 | 4146 |
4103 | 4147 |
4104 // Called when the top-level V8 mutex is destroyed. | 4148 // Called when the top-level V8 mutex is destroyed. |
4105 void Bootstrapper::FreeThreadResources() { | 4149 void Bootstrapper::FreeThreadResources() { |
4106 DCHECK(!IsActive()); | 4150 DCHECK(!IsActive()); |
4107 } | 4151 } |
4108 | 4152 |
4109 } // namespace internal | 4153 } // namespace internal |
4110 } // namespace v8 | 4154 } // namespace v8 |
OLD | NEW |