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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 211 |
212 void InstallTypedArray(const char* name, ElementsKind elements_kind, | 212 void InstallTypedArray(const char* name, ElementsKind elements_kind, |
213 Handle<JSFunction>* fun); | 213 Handle<JSFunction>* fun); |
214 bool InstallExperimentalNatives(); | 214 bool InstallExperimentalNatives(); |
215 bool InstallExtraNatives(); | 215 bool InstallExtraNatives(); |
216 bool InstallExperimentalExtraNatives(); | 216 bool InstallExperimentalExtraNatives(); |
217 bool InstallDebuggerNatives(); | 217 bool InstallDebuggerNatives(); |
218 void InstallBuiltinFunctionIds(); | 218 void InstallBuiltinFunctionIds(); |
219 void InstallExperimentalBuiltinFunctionIds(); | 219 void InstallExperimentalBuiltinFunctionIds(); |
220 void InitializeNormalizedMapCaches(); | 220 void InitializeNormalizedMapCaches(); |
| 221 void InstallJSProxyMaps(); |
221 | 222 |
222 enum ExtensionTraversalState { | 223 enum ExtensionTraversalState { |
223 UNVISITED, VISITED, INSTALLED | 224 UNVISITED, VISITED, INSTALLED |
224 }; | 225 }; |
225 | 226 |
226 class ExtensionStates { | 227 class ExtensionStates { |
227 public: | 228 public: |
228 ExtensionStates(); | 229 ExtensionStates(); |
229 ExtensionTraversalState get_state(RegisteredExtension* extension); | 230 ExtensionTraversalState get_state(RegisteredExtension* extension); |
230 void set_state(RegisteredExtension* extension, | 231 void set_state(RegisteredExtension* extension, |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 SetObjectPrototype(global_proxy, factory->null_value()); | 356 SetObjectPrototype(global_proxy, factory->null_value()); |
356 global_proxy->map()->SetConstructor(*factory->null_value()); | 357 global_proxy->map()->SetConstructor(*factory->null_value()); |
357 if (FLAG_track_detached_contexts) { | 358 if (FLAG_track_detached_contexts) { |
358 env->GetIsolate()->AddDetachedContext(env); | 359 env->GetIsolate()->AddDetachedContext(env); |
359 } | 360 } |
360 } | 361 } |
361 | 362 |
362 | 363 |
363 namespace { | 364 namespace { |
364 | 365 |
| 366 Handle<JSFunction> InstallFunction(Handle<JSObject> target, |
| 367 Handle<Name> property_name, |
| 368 Handle<JSFunction> function, |
| 369 Handle<String> function_name, |
| 370 PropertyAttributes attributes = DONT_ENUM) { |
| 371 JSObject::AddProperty(target, property_name, function, attributes); |
| 372 if (target->IsJSGlobalObject()) { |
| 373 function->shared()->set_instance_class_name(*function_name); |
| 374 } |
| 375 function->shared()->set_native(true); |
| 376 return function; |
| 377 } |
| 378 |
| 379 |
365 Handle<JSFunction> InstallFunction(Handle<JSObject> target, Handle<Name> name, | 380 Handle<JSFunction> InstallFunction(Handle<JSObject> target, Handle<Name> name, |
366 InstanceType type, int instance_size, | 381 InstanceType type, int instance_size, |
367 MaybeHandle<JSObject> maybe_prototype, | 382 MaybeHandle<JSObject> maybe_prototype, |
368 Builtins::Name call, | 383 Builtins::Name call, |
369 PropertyAttributes attributes, | 384 PropertyAttributes attributes, |
370 bool strict_function_map = false) { | 385 bool strict_function_map = false) { |
371 Isolate* isolate = target->GetIsolate(); | 386 Isolate* isolate = target->GetIsolate(); |
372 Factory* factory = isolate->factory(); | 387 Factory* factory = isolate->factory(); |
373 Handle<String> name_string = Name::ToFunctionName(name).ToHandleChecked(); | 388 Handle<String> name_string = Name::ToFunctionName(name).ToHandleChecked(); |
374 Handle<Code> call_code(isolate->builtins()->builtin(call)); | 389 Handle<Code> call_code(isolate->builtins()->builtin(call)); |
375 Handle<JSObject> prototype; | 390 Handle<JSObject> prototype; |
376 static const bool kReadOnlyPrototype = false; | 391 static const bool kReadOnlyPrototype = false; |
377 static const bool kInstallConstructor = false; | 392 static const bool kInstallConstructor = false; |
378 Handle<JSFunction> function = | 393 Handle<JSFunction> function = |
379 maybe_prototype.ToHandle(&prototype) | 394 maybe_prototype.ToHandle(&prototype) |
380 ? factory->NewFunction(name_string, call_code, prototype, type, | 395 ? factory->NewFunction(name_string, call_code, prototype, type, |
381 instance_size, kReadOnlyPrototype, | 396 instance_size, kReadOnlyPrototype, |
382 kInstallConstructor, strict_function_map) | 397 kInstallConstructor, strict_function_map) |
383 : factory->NewFunctionWithoutPrototype(name_string, call_code, | 398 : factory->NewFunctionWithoutPrototype(name_string, call_code, |
384 strict_function_map); | 399 strict_function_map); |
385 JSObject::AddProperty(target, name, function, attributes); | 400 return InstallFunction(target, name, function, name_string, attributes); |
386 if (target->IsJSGlobalObject()) { | |
387 function->shared()->set_instance_class_name(*name_string); | |
388 } | |
389 function->shared()->set_native(true); | |
390 return function; | |
391 } | 401 } |
392 | 402 |
393 | 403 |
394 Handle<JSFunction> InstallFunction(Handle<JSObject> target, const char* name, | 404 Handle<JSFunction> InstallFunction(Handle<JSObject> target, const char* name, |
395 InstanceType type, int instance_size, | 405 InstanceType type, int instance_size, |
396 MaybeHandle<JSObject> maybe_prototype, | 406 MaybeHandle<JSObject> maybe_prototype, |
397 Builtins::Name call, | 407 Builtins::Name call, |
398 bool strict_function_map = false) { | 408 bool strict_function_map = false) { |
399 Factory* const factory = target->GetIsolate()->factory(); | 409 Factory* const factory = target->GetIsolate()->factory(); |
400 PropertyAttributes attributes = DONT_ENUM; | 410 PropertyAttributes attributes = DONT_ENUM; |
(...skipping 1702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2103 Handle<JSFunction> type##_function = InstallFunction( \ | 2113 Handle<JSFunction> type##_function = InstallFunction( \ |
2104 simd_object, #Type, JS_VALUE_TYPE, JSValue::kSize, \ | 2114 simd_object, #Type, JS_VALUE_TYPE, JSValue::kSize, \ |
2105 isolate->initial_object_prototype(), Builtins::kIllegal); \ | 2115 isolate->initial_object_prototype(), Builtins::kIllegal); \ |
2106 native_context()->set_##type##_function(*type##_function); \ | 2116 native_context()->set_##type##_function(*type##_function); \ |
2107 type##_function->shared()->set_instance_class_name(*factory->Type##_string()); | 2117 type##_function->shared()->set_instance_class_name(*factory->Type##_string()); |
2108 SIMD128_TYPES(SIMD128_INSTALL_FUNCTION) | 2118 SIMD128_TYPES(SIMD128_INSTALL_FUNCTION) |
2109 #undef SIMD128_INSTALL_FUNCTION | 2119 #undef SIMD128_INSTALL_FUNCTION |
2110 } | 2120 } |
2111 | 2121 |
2112 | 2122 |
| 2123 void Genesis::InstallJSProxyMaps() { |
| 2124 // Allocate the different maps for all Proxy types. |
| 2125 // Next to the default proxy, we need maps indicating callable and |
| 2126 // constructable proxies. |
| 2127 |
| 2128 Handle<Map> proxy_function_map = |
| 2129 Map::Copy(isolate()->sloppy_function_without_prototype_map(), "Proxy"); |
| 2130 proxy_function_map->set_is_constructor(true); |
| 2131 native_context()->set_proxy_function_map(*proxy_function_map); |
| 2132 |
| 2133 Handle<Map> proxy_map = |
| 2134 factory()->NewMap(JS_PROXY_TYPE, JSProxy::kSize, FAST_ELEMENTS); |
| 2135 native_context()->set_proxy_map(*proxy_map); |
| 2136 |
| 2137 Handle<Map> proxy_callable_map = Map::Copy(proxy_map, "callable Proxy"); |
| 2138 proxy_callable_map->set_is_callable(); |
| 2139 native_context()->set_proxy_callable_map(*proxy_callable_map); |
| 2140 |
| 2141 Handle<Map> proxy_constructor_map = |
| 2142 Map::Copy(proxy_callable_map, "constructor Proxy"); |
| 2143 proxy_constructor_map->set_is_constructor(true); |
| 2144 native_context()->set_proxy_constructor_map(*proxy_constructor_map); |
| 2145 } |
| 2146 |
| 2147 |
2113 void Genesis::InitializeGlobal_harmony_proxies() { | 2148 void Genesis::InitializeGlobal_harmony_proxies() { |
2114 if (!FLAG_harmony_proxies) return; | 2149 if (!FLAG_harmony_proxies) return; |
2115 Handle<JSGlobalObject> global( | 2150 Handle<JSGlobalObject> global( |
2116 JSGlobalObject::cast(native_context()->global_object())); | 2151 JSGlobalObject::cast(native_context()->global_object())); |
2117 Isolate* isolate = global->GetIsolate(); | 2152 Isolate* isolate = global->GetIsolate(); |
2118 Handle<JSFunction> proxy_fun = InstallFunction( | 2153 Factory* factory = isolate->factory(); |
2119 global, "Proxy", JS_PROXY_TYPE, JSProxy::kSize, | 2154 |
2120 isolate->initial_object_prototype(), Builtins::kProxyConstructor); | 2155 InstallJSProxyMaps(); |
2121 // TODO(verwaest): Set to null in InstallFunction. | 2156 |
2122 proxy_fun->initial_map()->set_prototype(isolate->heap()->null_value()); | 2157 // Create the Proxy object. |
2123 proxy_fun->shared()->set_construct_stub( | 2158 Handle<String> name = factory->Proxy_string(); |
| 2159 Handle<Code> code(isolate->builtins()->ProxyConstructor()); |
| 2160 |
| 2161 Handle<JSFunction> proxy_function = |
| 2162 factory->NewFunction(isolate->proxy_function_map(), name, code); |
| 2163 |
| 2164 JSFunction::SetInitialMap(proxy_function, |
| 2165 Handle<Map>(native_context()->proxy_map(), isolate), |
| 2166 factory->null_value()); |
| 2167 |
| 2168 proxy_function->shared()->set_construct_stub( |
2124 *isolate->builtins()->ProxyConstructor_ConstructStub()); | 2169 *isolate->builtins()->ProxyConstructor_ConstructStub()); |
2125 proxy_fun->shared()->set_internal_formal_parameter_count(2); | 2170 proxy_function->shared()->set_internal_formal_parameter_count(2); |
2126 proxy_fun->shared()->set_length(2); | 2171 proxy_function->shared()->set_length(2); |
2127 native_context()->set_proxy_function(*proxy_fun); | 2172 |
| 2173 native_context()->set_proxy_function(*proxy_function); |
| 2174 InstallFunction(global, name, proxy_function, name); |
2128 } | 2175 } |
2129 | 2176 |
2130 | 2177 |
2131 Handle<JSFunction> Genesis::InstallInternalArray(Handle<JSObject> target, | 2178 Handle<JSFunction> Genesis::InstallInternalArray(Handle<JSObject> target, |
2132 const char* name, | 2179 const char* name, |
2133 ElementsKind elements_kind) { | 2180 ElementsKind elements_kind) { |
2134 // --- I n t e r n a l A r r a y --- | 2181 // --- I n t e r n a l A r r a y --- |
2135 // An array constructor on the builtins object that works like | 2182 // An array constructor on the builtins object that works like |
2136 // the public Array constructor, except that its prototype | 2183 // the public Array constructor, except that its prototype |
2137 // doesn't inherit from Object.prototype. | 2184 // doesn't inherit from Object.prototype. |
(...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3151 } | 3198 } |
3152 | 3199 |
3153 | 3200 |
3154 // Called when the top-level V8 mutex is destroyed. | 3201 // Called when the top-level V8 mutex is destroyed. |
3155 void Bootstrapper::FreeThreadResources() { | 3202 void Bootstrapper::FreeThreadResources() { |
3156 DCHECK(!IsActive()); | 3203 DCHECK(!IsActive()); |
3157 } | 3204 } |
3158 | 3205 |
3159 } // namespace internal | 3206 } // namespace internal |
3160 } // namespace v8 | 3207 } // namespace v8 |
OLD | NEW |