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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 SetObjectPrototype(global_proxy, factory->null_value()); | 357 SetObjectPrototype(global_proxy, factory->null_value()); |
358 global_proxy->map()->SetConstructor(*factory->null_value()); | 358 global_proxy->map()->SetConstructor(*factory->null_value()); |
359 if (FLAG_track_detached_contexts) { | 359 if (FLAG_track_detached_contexts) { |
360 env->GetIsolate()->AddDetachedContext(env); | 360 env->GetIsolate()->AddDetachedContext(env); |
361 } | 361 } |
362 } | 362 } |
363 | 363 |
364 | 364 |
365 namespace { | 365 namespace { |
366 | 366 |
367 Handle<JSFunction> InstallFunction(Handle<JSObject> target, | 367 void InstallFunction(Handle<JSObject> target, Handle<Name> property_name, |
368 Handle<Name> property_name, | 368 Handle<JSFunction> function, Handle<String> function_name, |
369 Handle<JSFunction> function, | 369 PropertyAttributes attributes = DONT_ENUM) { |
370 Handle<String> function_name, | |
371 PropertyAttributes attributes = DONT_ENUM) { | |
372 JSObject::AddProperty(target, property_name, function, attributes); | 370 JSObject::AddProperty(target, property_name, function, attributes); |
373 if (target->IsJSGlobalObject()) { | 371 if (target->IsJSGlobalObject()) { |
374 function->shared()->set_instance_class_name(*function_name); | 372 function->shared()->set_instance_class_name(*function_name); |
375 } | 373 } |
376 function->shared()->set_native(true); | 374 function->shared()->set_native(true); |
377 return function; | |
378 } | 375 } |
379 | 376 |
380 | 377 |
| 378 static void InstallFunction(Handle<JSObject> target, |
| 379 Handle<JSFunction> function, Handle<Name> name, |
| 380 PropertyAttributes attributes = DONT_ENUM) { |
| 381 Handle<String> name_string = Name::ToFunctionName(name).ToHandleChecked(); |
| 382 InstallFunction(target, name, function, name_string, attributes); |
| 383 } |
| 384 |
| 385 |
| 386 static Handle<JSFunction> CreateFunction(Isolate* isolate, Handle<String> name, |
| 387 InstanceType type, int instance_size, |
| 388 MaybeHandle<JSObject> maybe_prototype, |
| 389 Builtins::Name call, |
| 390 bool strict_function_map = false) { |
| 391 Factory* factory = isolate->factory(); |
| 392 Handle<Code> call_code(isolate->builtins()->builtin(call)); |
| 393 Handle<JSObject> prototype; |
| 394 static const bool kReadOnlyPrototype = false; |
| 395 static const bool kInstallConstructor = false; |
| 396 return maybe_prototype.ToHandle(&prototype) |
| 397 ? factory->NewFunction(name, call_code, prototype, type, |
| 398 instance_size, kReadOnlyPrototype, |
| 399 kInstallConstructor, strict_function_map) |
| 400 : factory->NewFunctionWithoutPrototype(name, call_code, |
| 401 strict_function_map); |
| 402 } |
| 403 |
| 404 |
381 Handle<JSFunction> InstallFunction(Handle<JSObject> target, Handle<Name> name, | 405 Handle<JSFunction> InstallFunction(Handle<JSObject> target, Handle<Name> name, |
382 InstanceType type, int instance_size, | 406 InstanceType type, int instance_size, |
383 MaybeHandle<JSObject> maybe_prototype, | 407 MaybeHandle<JSObject> maybe_prototype, |
384 Builtins::Name call, | 408 Builtins::Name call, |
385 PropertyAttributes attributes, | 409 PropertyAttributes attributes, |
386 bool strict_function_map = false) { | 410 bool strict_function_map = false) { |
387 Isolate* isolate = target->GetIsolate(); | |
388 Factory* factory = isolate->factory(); | |
389 Handle<String> name_string = Name::ToFunctionName(name).ToHandleChecked(); | 411 Handle<String> name_string = Name::ToFunctionName(name).ToHandleChecked(); |
390 Handle<Code> call_code(isolate->builtins()->builtin(call)); | |
391 Handle<JSObject> prototype; | |
392 static const bool kReadOnlyPrototype = false; | |
393 static const bool kInstallConstructor = false; | |
394 Handle<JSFunction> function = | 412 Handle<JSFunction> function = |
395 maybe_prototype.ToHandle(&prototype) | 413 CreateFunction(target->GetIsolate(), name_string, type, instance_size, |
396 ? factory->NewFunction(name_string, call_code, prototype, type, | 414 maybe_prototype, call, strict_function_map); |
397 instance_size, kReadOnlyPrototype, | 415 InstallFunction(target, name, function, name_string, attributes); |
398 kInstallConstructor, strict_function_map) | 416 return function; |
399 : factory->NewFunctionWithoutPrototype(name_string, call_code, | |
400 strict_function_map); | |
401 return InstallFunction(target, name, function, name_string, attributes); | |
402 } | 417 } |
403 | 418 |
404 | 419 |
405 Handle<JSFunction> InstallFunction(Handle<JSObject> target, const char* name, | 420 Handle<JSFunction> InstallFunction(Handle<JSObject> target, const char* name, |
406 InstanceType type, int instance_size, | 421 InstanceType type, int instance_size, |
407 MaybeHandle<JSObject> maybe_prototype, | 422 MaybeHandle<JSObject> maybe_prototype, |
408 Builtins::Name call, | 423 Builtins::Name call, |
409 bool strict_function_map = false) { | 424 bool strict_function_map = false) { |
410 Factory* const factory = target->GetIsolate()->factory(); | 425 Factory* const factory = target->GetIsolate()->factory(); |
411 PropertyAttributes attributes = DONT_ENUM; | 426 PropertyAttributes attributes = DONT_ENUM; |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 Handle<JSGlobalObject> global_object_from_snapshot( | 1036 Handle<JSGlobalObject> global_object_from_snapshot( |
1022 JSGlobalObject::cast(native_context()->extension())); | 1037 JSGlobalObject::cast(native_context()->extension())); |
1023 native_context()->set_extension(*global_object); | 1038 native_context()->set_extension(*global_object); |
1024 native_context()->set_security_token(*global_object); | 1039 native_context()->set_security_token(*global_object); |
1025 | 1040 |
1026 TransferNamedProperties(global_object_from_snapshot, global_object); | 1041 TransferNamedProperties(global_object_from_snapshot, global_object); |
1027 TransferIndexedProperties(global_object_from_snapshot, global_object); | 1042 TransferIndexedProperties(global_object_from_snapshot, global_object); |
1028 } | 1043 } |
1029 | 1044 |
1030 | 1045 |
1031 static void SimpleInstallFunction(Handle<JSObject> base, Handle<Name> name, | 1046 static Handle<JSFunction> SimpleCreateFunction(Isolate* isolate, |
1032 Builtins::Name call, int len, bool adapt) { | 1047 Handle<String> name, |
| 1048 Builtins::Name call, int len, |
| 1049 bool adapt) { |
1033 Handle<JSFunction> fun = | 1050 Handle<JSFunction> fun = |
1034 InstallFunction(base, name, JS_OBJECT_TYPE, JSObject::kHeaderSize, | 1051 CreateFunction(isolate, name, JS_OBJECT_TYPE, JSObject::kHeaderSize, |
1035 MaybeHandle<JSObject>(), call, DONT_ENUM); | 1052 MaybeHandle<JSObject>(), call); |
1036 if (adapt) { | 1053 if (adapt) { |
1037 fun->shared()->set_internal_formal_parameter_count(len); | 1054 fun->shared()->set_internal_formal_parameter_count(len); |
1038 } else { | 1055 } else { |
1039 fun->shared()->DontAdaptArguments(); | 1056 fun->shared()->DontAdaptArguments(); |
1040 } | 1057 } |
1041 fun->shared()->set_length(len); | 1058 fun->shared()->set_length(len); |
| 1059 return fun; |
1042 } | 1060 } |
1043 | 1061 |
1044 | 1062 |
| 1063 static Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base, |
| 1064 Handle<String> name, |
| 1065 Builtins::Name call, int len, |
| 1066 bool adapt) { |
| 1067 Handle<JSFunction> fun = |
| 1068 SimpleCreateFunction(base->GetIsolate(), name, call, len, adapt); |
| 1069 InstallFunction(base, fun, name, DONT_ENUM); |
| 1070 return fun; |
| 1071 } |
| 1072 |
| 1073 |
1045 static void InstallWithIntrinsicDefaultProto(Isolate* isolate, | 1074 static void InstallWithIntrinsicDefaultProto(Isolate* isolate, |
1046 Handle<JSFunction> function, | 1075 Handle<JSFunction> function, |
1047 int context_index) { | 1076 int context_index) { |
1048 Handle<Smi> index(Smi::FromInt(context_index), isolate); | 1077 Handle<Smi> index(Smi::FromInt(context_index), isolate); |
1049 JSObject::AddProperty( | 1078 JSObject::AddProperty( |
1050 function, isolate->factory()->native_context_index_symbol(), index, NONE); | 1079 function, isolate->factory()->native_context_index_symbol(), index, NONE); |
1051 isolate->native_context()->set(context_index, *function); | 1080 isolate->native_context()->set(context_index, *function); |
1052 } | 1081 } |
1053 | 1082 |
1054 | 1083 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1139 CacheInitialJSArrayMaps(native_context(), initial_map); | 1168 CacheInitialJSArrayMaps(native_context(), initial_map); |
1140 ArrayConstructorStub array_constructor_stub(isolate); | 1169 ArrayConstructorStub array_constructor_stub(isolate); |
1141 Handle<Code> code = array_constructor_stub.GetCode(); | 1170 Handle<Code> code = array_constructor_stub.GetCode(); |
1142 array_function->shared()->set_construct_stub(*code); | 1171 array_function->shared()->set_construct_stub(*code); |
1143 | 1172 |
1144 Handle<Map> initial_strong_map = | 1173 Handle<Map> initial_strong_map = |
1145 Map::Copy(initial_map, "SetInstancePrototype"); | 1174 Map::Copy(initial_map, "SetInstancePrototype"); |
1146 initial_strong_map->set_is_strong(); | 1175 initial_strong_map->set_is_strong(); |
1147 CacheInitialJSArrayMaps(native_context(), initial_strong_map); | 1176 CacheInitialJSArrayMaps(native_context(), initial_strong_map); |
1148 | 1177 |
1149 SimpleInstallFunction(array_function, | 1178 Handle<JSFunction> is_arraylike = SimpleInstallFunction( |
1150 isolate->factory()->InternalizeUtf8String("isArray"), | 1179 array_function, isolate->factory()->InternalizeUtf8String("isArray"), |
1151 Builtins::kArrayIsArray, 1, true); | 1180 Builtins::kArrayIsArray, 1, true); |
| 1181 native_context()->set_is_arraylike(*is_arraylike); |
1152 } | 1182 } |
1153 | 1183 |
1154 { // --- N u m b e r --- | 1184 { // --- N u m b e r --- |
1155 Handle<JSFunction> number_fun = | 1185 Handle<JSFunction> number_fun = |
1156 InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize, | 1186 InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize, |
1157 isolate->initial_object_prototype(), | 1187 isolate->initial_object_prototype(), |
1158 Builtins::kIllegal); | 1188 Builtins::kIllegal); |
1159 InstallWithIntrinsicDefaultProto(isolate, number_fun, | 1189 InstallWithIntrinsicDefaultProto(isolate, number_fun, |
1160 Context::NUMBER_FUNCTION_INDEX); | 1190 Context::NUMBER_FUNCTION_INDEX); |
1161 number_fun->shared()->set_construct_stub( | 1191 number_fun->shared()->set_construct_stub( |
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2150 InstallPublicSymbol(factory(), native_context(), "replace", | 2180 InstallPublicSymbol(factory(), native_context(), "replace", |
2151 factory()->replace_symbol()); | 2181 factory()->replace_symbol()); |
2152 InstallPublicSymbol(factory(), native_context(), "search", | 2182 InstallPublicSymbol(factory(), native_context(), "search", |
2153 factory()->search_symbol()); | 2183 factory()->search_symbol()); |
2154 InstallPublicSymbol(factory(), native_context(), "split", | 2184 InstallPublicSymbol(factory(), native_context(), "split", |
2155 factory()->split_symbol()); | 2185 factory()->split_symbol()); |
2156 } | 2186 } |
2157 | 2187 |
2158 | 2188 |
2159 void Genesis::InitializeGlobal_harmony_reflect() { | 2189 void Genesis::InitializeGlobal_harmony_reflect() { |
| 2190 Factory* factory = isolate()->factory(); |
| 2191 |
| 2192 // We currently use some of the Reflect functions internally, even when |
| 2193 // the --harmony-reflect flag is not given. |
| 2194 |
| 2195 Handle<JSFunction> define_property = |
| 2196 SimpleCreateFunction(isolate(), factory->defineProperty_string(), |
| 2197 Builtins::kReflectDefineProperty, 3, true); |
| 2198 native_context()->set_reflect_define_property(*define_property); |
| 2199 |
| 2200 Handle<JSFunction> delete_property = |
| 2201 SimpleCreateFunction(isolate(), factory->deleteProperty_string(), |
| 2202 Builtins::kReflectDeleteProperty, 2, true); |
| 2203 native_context()->set_reflect_delete_property(*delete_property); |
| 2204 |
2160 if (!FLAG_harmony_reflect) return; | 2205 if (!FLAG_harmony_reflect) return; |
2161 | 2206 |
2162 Factory* factory = isolate()->factory(); | |
2163 Handle<JSGlobalObject> global(JSGlobalObject::cast( | 2207 Handle<JSGlobalObject> global(JSGlobalObject::cast( |
2164 native_context()->global_object())); | 2208 native_context()->global_object())); |
2165 Handle<String> reflect_string = factory->NewStringFromStaticChars("Reflect"); | 2209 Handle<String> reflect_string = factory->NewStringFromStaticChars("Reflect"); |
2166 Handle<JSObject> reflect = | 2210 Handle<JSObject> reflect = |
2167 factory->NewJSObject(isolate()->object_function(), TENURED); | 2211 factory->NewJSObject(isolate()->object_function(), TENURED); |
2168 JSObject::AddProperty(global, reflect_string, reflect, DONT_ENUM); | 2212 JSObject::AddProperty(global, reflect_string, reflect, DONT_ENUM); |
2169 | 2213 |
2170 SimpleInstallFunction(reflect, factory->defineProperty_string(), | 2214 InstallFunction(reflect, define_property, factory->defineProperty_string()); |
2171 Builtins::kReflectDefineProperty, 3, true); | 2215 InstallFunction(reflect, delete_property, factory->deleteProperty_string()); |
2172 SimpleInstallFunction(reflect, factory->deleteProperty_string(), | 2216 |
2173 Builtins::kReflectDeleteProperty, 2, true); | |
2174 SimpleInstallFunction(reflect, factory->get_string(), | 2217 SimpleInstallFunction(reflect, factory->get_string(), |
2175 Builtins::kReflectGet, 2, false); | 2218 Builtins::kReflectGet, 2, false); |
2176 SimpleInstallFunction(reflect, factory->getOwnPropertyDescriptor_string(), | 2219 SimpleInstallFunction(reflect, factory->getOwnPropertyDescriptor_string(), |
2177 Builtins::kReflectGetOwnPropertyDescriptor, 2, true); | 2220 Builtins::kReflectGetOwnPropertyDescriptor, 2, true); |
2178 SimpleInstallFunction(reflect, factory->getPrototypeOf_string(), | 2221 SimpleInstallFunction(reflect, factory->getPrototypeOf_string(), |
2179 Builtins::kReflectGetPrototypeOf, 1, true); | 2222 Builtins::kReflectGetPrototypeOf, 1, true); |
2180 SimpleInstallFunction(reflect, factory->has_string(), | 2223 SimpleInstallFunction(reflect, factory->has_string(), |
2181 Builtins::kReflectHas, 2, true); | 2224 Builtins::kReflectHas, 2, true); |
2182 SimpleInstallFunction(reflect, factory->isExtensible_string(), | 2225 SimpleInstallFunction(reflect, factory->isExtensible_string(), |
2183 Builtins::kReflectIsExtensible, 1, true); | 2226 Builtins::kReflectIsExtensible, 1, true); |
(...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3320 } | 3363 } |
3321 | 3364 |
3322 | 3365 |
3323 // Called when the top-level V8 mutex is destroyed. | 3366 // Called when the top-level V8 mutex is destroyed. |
3324 void Bootstrapper::FreeThreadResources() { | 3367 void Bootstrapper::FreeThreadResources() { |
3325 DCHECK(!IsActive()); | 3368 DCHECK(!IsActive()); |
3326 } | 3369 } |
3327 | 3370 |
3328 } // namespace internal | 3371 } // namespace internal |
3329 } // namespace v8 | 3372 } // namespace v8 |
OLD | NEW |