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/utils/random-number-generator.h" | 9 #include "src/base/utils/random-number-generator.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 Handle<JSGlobalProxy> global_proxy(JSGlobalProxy::cast(env->global_proxy())); | 373 Handle<JSGlobalProxy> global_proxy(JSGlobalProxy::cast(env->global_proxy())); |
374 global_proxy->set_native_context(*factory->null_value()); | 374 global_proxy->set_native_context(*factory->null_value()); |
375 SetObjectPrototype(global_proxy, factory->null_value()); | 375 SetObjectPrototype(global_proxy, factory->null_value()); |
376 global_proxy->map()->SetConstructor(*factory->null_value()); | 376 global_proxy->map()->SetConstructor(*factory->null_value()); |
377 if (FLAG_track_detached_contexts) { | 377 if (FLAG_track_detached_contexts) { |
378 env->GetIsolate()->AddDetachedContext(env); | 378 env->GetIsolate()->AddDetachedContext(env); |
379 } | 379 } |
380 } | 380 } |
381 | 381 |
382 | 382 |
383 static Handle<JSFunction> InstallFunction(Handle<JSObject> target, | 383 namespace { |
384 const char* name, InstanceType type, | 384 |
385 int instance_size, | 385 Handle<JSFunction> InstallFunction(Handle<JSObject> target, Handle<Name> name, |
386 MaybeHandle<JSObject> maybe_prototype, | 386 InstanceType type, int instance_size, |
387 Builtins::Name call, | 387 MaybeHandle<JSObject> maybe_prototype, |
388 bool strict_function_map = false) { | 388 Builtins::Name call, |
| 389 PropertyAttributes attributes, |
| 390 bool strict_function_map = false) { |
389 Isolate* isolate = target->GetIsolate(); | 391 Isolate* isolate = target->GetIsolate(); |
390 Factory* factory = isolate->factory(); | 392 Factory* factory = isolate->factory(); |
391 Handle<String> internalized_name = factory->InternalizeUtf8String(name); | 393 Handle<String> name_string = Name::ToFunctionName(name).ToHandleChecked(); |
392 Handle<Code> call_code = Handle<Code>(isolate->builtins()->builtin(call)); | 394 Handle<Code> call_code = Handle<Code>(isolate->builtins()->builtin(call)); |
393 Handle<JSObject> prototype; | 395 Handle<JSObject> prototype; |
394 static const bool kReadOnlyPrototype = false; | 396 static const bool kReadOnlyPrototype = false; |
395 static const bool kInstallConstructor = false; | 397 static const bool kInstallConstructor = false; |
396 Handle<JSFunction> function = | 398 Handle<JSFunction> function = |
397 maybe_prototype.ToHandle(&prototype) | 399 maybe_prototype.ToHandle(&prototype) |
398 ? factory->NewFunction(internalized_name, call_code, prototype, type, | 400 ? factory->NewFunction(name_string, call_code, prototype, type, |
399 instance_size, kReadOnlyPrototype, | 401 instance_size, kReadOnlyPrototype, |
400 kInstallConstructor, strict_function_map) | 402 kInstallConstructor, strict_function_map) |
401 : factory->NewFunctionWithoutPrototype(internalized_name, call_code, | 403 : factory->NewFunctionWithoutPrototype(name_string, call_code, |
402 strict_function_map); | 404 strict_function_map); |
| 405 JSObject::AddProperty(target, name, function, attributes); |
| 406 if (target->IsJSGlobalObject()) { |
| 407 function->shared()->set_instance_class_name(*name_string); |
| 408 } |
| 409 function->shared()->set_native(true); |
| 410 return function; |
| 411 } |
| 412 |
| 413 |
| 414 Handle<JSFunction> InstallFunction(Handle<JSObject> target, const char* name, |
| 415 InstanceType type, int instance_size, |
| 416 MaybeHandle<JSObject> maybe_prototype, |
| 417 Builtins::Name call, |
| 418 bool strict_function_map = false) { |
| 419 Factory* const factory = target->GetIsolate()->factory(); |
403 PropertyAttributes attributes; | 420 PropertyAttributes attributes; |
404 if (target->IsJSBuiltinsObject()) { | 421 if (target->IsJSBuiltinsObject()) { |
405 attributes = | 422 attributes = |
406 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); | 423 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
407 } else { | 424 } else { |
408 attributes = DONT_ENUM; | 425 attributes = DONT_ENUM; |
409 } | 426 } |
410 JSObject::AddProperty(target, internalized_name, function, attributes); | 427 return InstallFunction(target, factory->InternalizeUtf8String(name), type, |
411 if (target->IsJSGlobalObject()) { | 428 instance_size, maybe_prototype, call, attributes, |
412 function->shared()->set_instance_class_name(*internalized_name); | 429 strict_function_map); |
413 } | |
414 function->shared()->set_native(true); | |
415 return function; | |
416 } | 430 } |
417 | 431 |
| 432 } // namespace |
| 433 |
418 | 434 |
419 void Genesis::SetFunctionInstanceDescriptor(Handle<Map> map, | 435 void Genesis::SetFunctionInstanceDescriptor(Handle<Map> map, |
420 FunctionMode function_mode) { | 436 FunctionMode function_mode) { |
421 int size = IsFunctionModeWithPrototype(function_mode) ? 5 : 4; | 437 int size = IsFunctionModeWithPrototype(function_mode) ? 5 : 4; |
422 Map::EnsureDescriptorSlack(map, size); | 438 Map::EnsureDescriptorSlack(map, size); |
423 | 439 |
424 PropertyAttributes ro_attribs = | 440 PropertyAttributes ro_attribs = |
425 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); | 441 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
426 PropertyAttributes roc_attribs = | 442 PropertyAttributes roc_attribs = |
427 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); | 443 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); |
(...skipping 1856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2284 native_context()->set_function_cache(*function_cache); | 2300 native_context()->set_function_cache(*function_cache); |
2285 | 2301 |
2286 // Store the map for the string prototype after the natives has been compiled | 2302 // Store the map for the string prototype after the natives has been compiled |
2287 // and the String function has been set up. | 2303 // and the String function has been set up. |
2288 Handle<JSFunction> string_function(native_context()->string_function()); | 2304 Handle<JSFunction> string_function(native_context()->string_function()); |
2289 DCHECK(JSObject::cast( | 2305 DCHECK(JSObject::cast( |
2290 string_function->initial_map()->prototype())->HasFastProperties()); | 2306 string_function->initial_map()->prototype())->HasFastProperties()); |
2291 native_context()->set_string_function_prototype_map( | 2307 native_context()->set_string_function_prototype_map( |
2292 HeapObject::cast(string_function->initial_map()->prototype())->map()); | 2308 HeapObject::cast(string_function->initial_map()->prototype())->map()); |
2293 | 2309 |
| 2310 // Install Date.prototype[@@toPrimitive]. |
| 2311 { |
| 2312 Handle<String> key = factory()->Date_string(); |
| 2313 Handle<JSFunction> date = Handle<JSFunction>::cast( |
| 2314 Object::GetProperty(handle(native_context()->global_object()), key) |
| 2315 .ToHandleChecked()); |
| 2316 Handle<JSObject> proto = |
| 2317 Handle<JSObject>(JSObject::cast(date->instance_prototype())); |
| 2318 |
| 2319 // Install the @@toPrimitive function. |
| 2320 Handle<JSFunction> to_primitive = |
| 2321 InstallFunction(proto, factory()->to_primitive_symbol(), JS_OBJECT_TYPE, |
| 2322 JSObject::kHeaderSize, MaybeHandle<JSObject>(), |
| 2323 Builtins::kDateToPrimitive, |
| 2324 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); |
| 2325 |
| 2326 // Set the expected parameters for @@toPrimitive to 1; required by builtin. |
| 2327 to_primitive->shared()->set_internal_formal_parameter_count(1); |
| 2328 |
| 2329 // Set the length for the function to satisfy ECMA-262. |
| 2330 to_primitive->shared()->set_length(1); |
| 2331 } |
| 2332 |
2294 // Install Function.prototype.call and apply. | 2333 // Install Function.prototype.call and apply. |
2295 { | 2334 { |
2296 Handle<String> key = factory()->Function_string(); | 2335 Handle<String> key = factory()->Function_string(); |
2297 Handle<JSFunction> function = | 2336 Handle<JSFunction> function = |
2298 Handle<JSFunction>::cast(Object::GetProperty( | 2337 Handle<JSFunction>::cast(Object::GetProperty( |
2299 handle(native_context()->global_object()), key).ToHandleChecked()); | 2338 handle(native_context()->global_object()), key).ToHandleChecked()); |
2300 Handle<JSObject> proto = | 2339 Handle<JSObject> proto = |
2301 Handle<JSObject>(JSObject::cast(function->instance_prototype())); | 2340 Handle<JSObject>(JSObject::cast(function->instance_prototype())); |
2302 | 2341 |
2303 // Install the call and the apply functions. | 2342 // Install the call and the apply functions. |
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3151 } | 3190 } |
3152 | 3191 |
3153 | 3192 |
3154 // Called when the top-level V8 mutex is destroyed. | 3193 // Called when the top-level V8 mutex is destroyed. |
3155 void Bootstrapper::FreeThreadResources() { | 3194 void Bootstrapper::FreeThreadResources() { |
3156 DCHECK(!IsActive()); | 3195 DCHECK(!IsActive()); |
3157 } | 3196 } |
3158 | 3197 |
3159 } // namespace internal | 3198 } // namespace internal |
3160 } // namespace v8 | 3199 } // namespace v8 |
OLD | NEW |