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/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/extensions/externalize-string-extension.h" | 10 #include "src/extensions/externalize-string-extension.h" |
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1007 Handle<JSGlobalObject> global_object_from_snapshot( | 1007 Handle<JSGlobalObject> global_object_from_snapshot( |
1008 JSGlobalObject::cast(native_context()->extension())); | 1008 JSGlobalObject::cast(native_context()->extension())); |
1009 native_context()->set_extension(*global_object); | 1009 native_context()->set_extension(*global_object); |
1010 native_context()->set_security_token(*global_object); | 1010 native_context()->set_security_token(*global_object); |
1011 | 1011 |
1012 TransferNamedProperties(global_object_from_snapshot, global_object); | 1012 TransferNamedProperties(global_object_from_snapshot, global_object); |
1013 TransferIndexedProperties(global_object_from_snapshot, global_object); | 1013 TransferIndexedProperties(global_object_from_snapshot, global_object); |
1014 } | 1014 } |
1015 | 1015 |
1016 | 1016 |
1017 static void SimpleInstallFunction(Handle<JSObject> base, Handle<Name> name, | 1017 static Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base, |
1018 Builtins::Name call, int len, bool adapt) { | 1018 Handle<Name> name, |
| 1019 Builtins::Name call, int len, |
| 1020 bool adapt, |
| 1021 bool with_prototype = false) { |
| 1022 Isolate* isolate = base->GetIsolate(); |
| 1023 MaybeHandle<JSObject> prototype = |
| 1024 with_prototype |
| 1025 ? isolate->factory()->NewJSObject(isolate->object_function(), TENURED) |
| 1026 : MaybeHandle<JSObject>(); |
| 1027 |
1019 Handle<JSFunction> fun = | 1028 Handle<JSFunction> fun = |
1020 InstallFunction(base, name, JS_OBJECT_TYPE, JSObject::kHeaderSize, | 1029 InstallFunction(base, name, JS_OBJECT_TYPE, JSObject::kHeaderSize, |
1021 MaybeHandle<JSObject>(), call, DONT_ENUM); | 1030 prototype, call, DONT_ENUM); |
1022 if (adapt) { | 1031 if (adapt) { |
1023 fun->shared()->set_internal_formal_parameter_count(len); | 1032 fun->shared()->set_internal_formal_parameter_count(len); |
1024 } else { | 1033 } else { |
1025 fun->shared()->DontAdaptArguments(); | 1034 fun->shared()->DontAdaptArguments(); |
1026 } | 1035 } |
1027 fun->shared()->set_length(len); | 1036 fun->shared()->set_length(len); |
| 1037 return fun; |
1028 } | 1038 } |
1029 | 1039 |
1030 | 1040 |
| 1041 static Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base, |
| 1042 const char* name, |
| 1043 Builtins::Name call, int len, |
| 1044 bool adapt, |
| 1045 bool with_prototype = false) { |
| 1046 return SimpleInstallFunction( |
| 1047 base, base->GetIsolate()->factory()->InternalizeUtf8String(name), call, |
| 1048 len, adapt, with_prototype); |
| 1049 } |
| 1050 |
| 1051 |
1031 static void InstallWithIntrinsicDefaultProto(Isolate* isolate, | 1052 static void InstallWithIntrinsicDefaultProto(Isolate* isolate, |
1032 Handle<JSFunction> function, | 1053 Handle<JSFunction> function, |
1033 int context_index) { | 1054 int context_index) { |
1034 Handle<Smi> index(Smi::FromInt(context_index), isolate); | 1055 Handle<Smi> index(Smi::FromInt(context_index), isolate); |
1035 JSObject::AddProperty( | 1056 JSObject::AddProperty( |
1036 function, isolate->factory()->native_context_index_symbol(), index, NONE); | 1057 function, isolate->factory()->native_context_index_symbol(), index, NONE); |
1037 isolate->native_context()->set(context_index, *function); | 1058 isolate->native_context()->set(context_index, *function); |
1038 } | 1059 } |
1039 | 1060 |
1040 | 1061 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1119 CacheInitialJSArrayMaps(native_context(), initial_map); | 1140 CacheInitialJSArrayMaps(native_context(), initial_map); |
1120 ArrayConstructorStub array_constructor_stub(isolate); | 1141 ArrayConstructorStub array_constructor_stub(isolate); |
1121 Handle<Code> code = array_constructor_stub.GetCode(); | 1142 Handle<Code> code = array_constructor_stub.GetCode(); |
1122 array_function->shared()->set_construct_stub(*code); | 1143 array_function->shared()->set_construct_stub(*code); |
1123 | 1144 |
1124 Handle<Map> initial_strong_map = | 1145 Handle<Map> initial_strong_map = |
1125 Map::Copy(initial_map, "SetInstancePrototype"); | 1146 Map::Copy(initial_map, "SetInstancePrototype"); |
1126 initial_strong_map->set_is_strong(); | 1147 initial_strong_map->set_is_strong(); |
1127 CacheInitialJSArrayMaps(native_context(), initial_strong_map); | 1148 CacheInitialJSArrayMaps(native_context(), initial_strong_map); |
1128 | 1149 |
1129 SimpleInstallFunction(array_function, | 1150 SimpleInstallFunction(array_function, "isArray", Builtins::kArrayIsArray, 1, |
1130 factory->NewStringFromAsciiChecked("isArray"), | 1151 true); |
1131 Builtins::kArrayIsArray, 1, true); | |
1132 } | 1152 } |
1133 | 1153 |
1134 { // --- N u m b e r --- | 1154 { // --- N u m b e r --- |
1135 Handle<JSFunction> number_fun = | 1155 Handle<JSFunction> number_fun = |
1136 InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize, | 1156 InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize, |
1137 isolate->initial_object_prototype(), | 1157 isolate->initial_object_prototype(), |
1138 Builtins::kIllegal); | 1158 Builtins::kIllegal); |
1139 InstallWithIntrinsicDefaultProto(isolate, number_fun, | 1159 InstallWithIntrinsicDefaultProto(isolate, number_fun, |
1140 Context::NUMBER_FUNCTION_INDEX); | 1160 Context::NUMBER_FUNCTION_INDEX); |
1141 number_fun->shared()->set_construct_stub( | 1161 number_fun->shared()->set_construct_stub( |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 Representation::Tagged()); | 1247 Representation::Tagged()); |
1228 initial_map->AppendDescriptor(&field); | 1248 initial_map->AppendDescriptor(&field); |
1229 | 1249 |
1230 static const int num_fields = JSRegExp::kInObjectFieldCount; | 1250 static const int num_fields = JSRegExp::kInObjectFieldCount; |
1231 initial_map->SetInObjectProperties(num_fields); | 1251 initial_map->SetInObjectProperties(num_fields); |
1232 initial_map->set_unused_property_fields(0); | 1252 initial_map->set_unused_property_fields(0); |
1233 initial_map->set_instance_size(initial_map->instance_size() + | 1253 initial_map->set_instance_size(initial_map->instance_size() + |
1234 num_fields * kPointerSize); | 1254 num_fields * kPointerSize); |
1235 } | 1255 } |
1236 | 1256 |
| 1257 { // -- E r r o r |
| 1258 Handle<JSFunction> error_fun = SimpleInstallFunction( |
| 1259 global, "Error", Builtins::kIllegal, 0, true, true); |
| 1260 InstallWithIntrinsicDefaultProto(isolate, error_fun, |
| 1261 Context::ERROR_FUNCTION_INDEX); |
| 1262 } |
| 1263 |
| 1264 { // -- E v a l E r r o r |
| 1265 Handle<JSFunction> eval_error_fun = SimpleInstallFunction( |
| 1266 global, "EvalError", Builtins::kIllegal, 0, true, true); |
| 1267 InstallWithIntrinsicDefaultProto(isolate, eval_error_fun, |
| 1268 Context::EVAL_ERROR_FUNCTION_INDEX); |
| 1269 } |
| 1270 |
| 1271 { // -- R a n g e E r r o r |
| 1272 Handle<JSFunction> range_error_fun = SimpleInstallFunction( |
| 1273 global, "RangeError", Builtins::kIllegal, 0, true, true); |
| 1274 InstallWithIntrinsicDefaultProto(isolate, range_error_fun, |
| 1275 Context::RANGE_ERROR_FUNCTION_INDEX); |
| 1276 } |
| 1277 |
| 1278 { // -- R e f e r e n c e E r r o r |
| 1279 Handle<JSFunction> reference_error_fun = SimpleInstallFunction( |
| 1280 global, "ReferenceError", Builtins::kIllegal, 0, true, true); |
| 1281 InstallWithIntrinsicDefaultProto(isolate, reference_error_fun, |
| 1282 Context::REFERENCE_ERROR_FUNCTION_INDEX); |
| 1283 } |
| 1284 |
| 1285 { // -- S y n t a x E r r o r |
| 1286 Handle<JSFunction> syntax_error_fun = SimpleInstallFunction( |
| 1287 global, "SyntaxError", Builtins::kIllegal, 0, true, true); |
| 1288 InstallWithIntrinsicDefaultProto(isolate, syntax_error_fun, |
| 1289 Context::SYNTAX_ERROR_FUNCTION_INDEX); |
| 1290 } |
| 1291 |
| 1292 { // -- T y p e E r r o r |
| 1293 Handle<JSFunction> type_error_fun = SimpleInstallFunction( |
| 1294 global, "TypeError", Builtins::kIllegal, 0, true, true); |
| 1295 InstallWithIntrinsicDefaultProto(isolate, type_error_fun, |
| 1296 Context::TYPE_ERROR_FUNCTION_INDEX); |
| 1297 } |
| 1298 |
| 1299 { // -- U R I E r r o r |
| 1300 Handle<JSFunction> uri_error_fun = SimpleInstallFunction( |
| 1301 global, "URIError", Builtins::kIllegal, 0, true, true); |
| 1302 InstallWithIntrinsicDefaultProto(isolate, uri_error_fun, |
| 1303 Context::URI_ERROR_FUNCTION_INDEX); |
| 1304 } |
| 1305 |
1237 // Initialize the embedder data slot. | 1306 // Initialize the embedder data slot. |
1238 Handle<FixedArray> embedder_data = factory->NewFixedArray(3); | 1307 Handle<FixedArray> embedder_data = factory->NewFixedArray(3); |
1239 native_context()->set_embedder_data(*embedder_data); | 1308 native_context()->set_embedder_data(*embedder_data); |
1240 | 1309 |
1241 if (context_type == THIN_CONTEXT) return; | 1310 if (context_type == THIN_CONTEXT) return; |
1242 | 1311 |
1243 { // -- J S O N | 1312 { // -- J S O N |
1244 Handle<String> name = factory->InternalizeUtf8String("JSON"); | 1313 Handle<String> name = factory->InternalizeUtf8String("JSON"); |
1245 Handle<JSFunction> cons = factory->NewFunction(name); | 1314 Handle<JSFunction> cons = factory->NewFunction(name); |
1246 JSFunction::SetInstancePrototype(cons, | 1315 JSFunction::SetInstancePrototype(cons, |
(...skipping 1936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3183 } | 3252 } |
3184 | 3253 |
3185 | 3254 |
3186 // Called when the top-level V8 mutex is destroyed. | 3255 // Called when the top-level V8 mutex is destroyed. |
3187 void Bootstrapper::FreeThreadResources() { | 3256 void Bootstrapper::FreeThreadResources() { |
3188 DCHECK(!IsActive()); | 3257 DCHECK(!IsActive()); |
3189 } | 3258 } |
3190 | 3259 |
3191 } // namespace internal | 3260 } // namespace internal |
3192 } // namespace v8 | 3261 } // namespace v8 |
OLD | NEW |