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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 // 'from'. | 262 // 'from'. |
263 void TransferObject(Handle<JSObject> from, Handle<JSObject> to); | 263 void TransferObject(Handle<JSObject> from, Handle<JSObject> to); |
264 void TransferNamedProperties(Handle<JSObject> from, Handle<JSObject> to); | 264 void TransferNamedProperties(Handle<JSObject> from, Handle<JSObject> to); |
265 void TransferIndexedProperties(Handle<JSObject> from, Handle<JSObject> to); | 265 void TransferIndexedProperties(Handle<JSObject> from, Handle<JSObject> to); |
266 | 266 |
267 enum FunctionMode { | 267 enum FunctionMode { |
268 // With prototype. | 268 // With prototype. |
269 FUNCTION_WITH_WRITEABLE_PROTOTYPE, | 269 FUNCTION_WITH_WRITEABLE_PROTOTYPE, |
270 FUNCTION_WITH_READONLY_PROTOTYPE, | 270 FUNCTION_WITH_READONLY_PROTOTYPE, |
271 // Without prototype. | 271 // Without prototype. |
272 FUNCTION_WITHOUT_PROTOTYPE, | 272 FUNCTION_WITHOUT_PROTOTYPE |
273 BOUND_FUNCTION | |
274 }; | 273 }; |
275 | 274 |
276 static bool IsFunctionModeWithPrototype(FunctionMode function_mode) { | 275 static bool IsFunctionModeWithPrototype(FunctionMode function_mode) { |
277 return (function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE || | 276 return (function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE || |
278 function_mode == FUNCTION_WITH_READONLY_PROTOTYPE); | 277 function_mode == FUNCTION_WITH_READONLY_PROTOTYPE); |
279 } | 278 } |
280 | 279 |
281 Handle<Map> CreateSloppyFunctionMap(FunctionMode function_mode); | 280 Handle<Map> CreateSloppyFunctionMap(FunctionMode function_mode); |
282 | 281 |
283 void SetFunctionInstanceDescriptor(Handle<Map> map, | 282 void SetFunctionInstanceDescriptor(Handle<Map> map, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 if (target->IsJSGlobalObject()) { | 370 if (target->IsJSGlobalObject()) { |
372 function->shared()->set_instance_class_name(*function_name); | 371 function->shared()->set_instance_class_name(*function_name); |
373 } | 372 } |
374 function->shared()->set_native(true); | 373 function->shared()->set_native(true); |
375 } | 374 } |
376 | 375 |
377 | 376 |
378 static void InstallFunction(Handle<JSObject> target, | 377 static void InstallFunction(Handle<JSObject> target, |
379 Handle<JSFunction> function, Handle<Name> name, | 378 Handle<JSFunction> function, Handle<Name> name, |
380 PropertyAttributes attributes = DONT_ENUM) { | 379 PropertyAttributes attributes = DONT_ENUM) { |
381 Handle<String> name_string = Name::ToFunctionName(name).ToHandleChecked(); | 380 Isolate* const isolate = target->GetIsolate(); |
| 381 Handle<String> name_string = |
| 382 Name::ToFunctionName(name, isolate->factory()->empty_string()) |
| 383 .ToHandleChecked(); |
382 InstallFunction(target, name, function, name_string, attributes); | 384 InstallFunction(target, name, function, name_string, attributes); |
383 } | 385 } |
384 | 386 |
385 | 387 |
386 static Handle<JSFunction> CreateFunction(Isolate* isolate, Handle<String> name, | 388 static Handle<JSFunction> CreateFunction(Isolate* isolate, Handle<String> name, |
387 InstanceType type, int instance_size, | 389 InstanceType type, int instance_size, |
388 MaybeHandle<JSObject> maybe_prototype, | 390 MaybeHandle<JSObject> maybe_prototype, |
389 Builtins::Name call, | 391 Builtins::Name call, |
390 bool strict_function_map = false) { | 392 bool strict_function_map = false) { |
391 Factory* factory = isolate->factory(); | 393 Factory* factory = isolate->factory(); |
392 Handle<Code> call_code(isolate->builtins()->builtin(call)); | 394 Handle<Code> call_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 return maybe_prototype.ToHandle(&prototype) | 398 return maybe_prototype.ToHandle(&prototype) |
397 ? factory->NewFunction(name, call_code, prototype, type, | 399 ? factory->NewFunction(name, call_code, prototype, type, |
398 instance_size, kReadOnlyPrototype, | 400 instance_size, kReadOnlyPrototype, |
399 kInstallConstructor, strict_function_map) | 401 kInstallConstructor, strict_function_map) |
400 : factory->NewFunctionWithoutPrototype(name, call_code, | 402 : factory->NewFunctionWithoutPrototype(name, call_code, |
401 strict_function_map); | 403 strict_function_map); |
402 } | 404 } |
403 | 405 |
404 | 406 |
405 Handle<JSFunction> InstallFunction(Handle<JSObject> target, Handle<Name> name, | 407 Handle<JSFunction> InstallFunction(Handle<JSObject> target, Handle<Name> name, |
406 InstanceType type, int instance_size, | 408 InstanceType type, int instance_size, |
407 MaybeHandle<JSObject> maybe_prototype, | 409 MaybeHandle<JSObject> maybe_prototype, |
408 Builtins::Name call, | 410 Builtins::Name call, |
409 PropertyAttributes attributes, | 411 PropertyAttributes attributes, |
410 bool strict_function_map = false) { | 412 bool strict_function_map = false) { |
411 Handle<String> name_string = Name::ToFunctionName(name).ToHandleChecked(); | 413 Isolate* const isolate = target->GetIsolate(); |
| 414 Handle<String> name_string = |
| 415 Name::ToFunctionName(name, isolate->factory()->empty_string()) |
| 416 .ToHandleChecked(); |
412 Handle<JSFunction> function = | 417 Handle<JSFunction> function = |
413 CreateFunction(target->GetIsolate(), name_string, type, instance_size, | 418 CreateFunction(target->GetIsolate(), name_string, type, instance_size, |
414 maybe_prototype, call, strict_function_map); | 419 maybe_prototype, call, strict_function_map); |
415 InstallFunction(target, name, function, name_string, attributes); | 420 InstallFunction(target, name, function, name_string, attributes); |
416 return function; | 421 return function; |
417 } | 422 } |
418 | 423 |
419 | 424 |
420 Handle<JSFunction> InstallFunction(Handle<JSObject> target, const char* name, | 425 Handle<JSFunction> InstallFunction(Handle<JSObject> target, const char* name, |
421 InstanceType type, int instance_size, | 426 InstanceType type, int instance_size, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())), | 484 AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())), |
480 prototype, ro_attribs); | 485 prototype, ro_attribs); |
481 map->AppendDescriptor(&d); | 486 map->AppendDescriptor(&d); |
482 } | 487 } |
483 } | 488 } |
484 | 489 |
485 | 490 |
486 Handle<Map> Genesis::CreateSloppyFunctionMap(FunctionMode function_mode) { | 491 Handle<Map> Genesis::CreateSloppyFunctionMap(FunctionMode function_mode) { |
487 Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); | 492 Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); |
488 SetFunctionInstanceDescriptor(map, function_mode); | 493 SetFunctionInstanceDescriptor(map, function_mode); |
489 map->set_is_constructor(IsFunctionModeWithPrototype(function_mode)); | 494 if (IsFunctionModeWithPrototype(function_mode)) map->set_is_constructor(); |
490 map->set_is_callable(); | 495 map->set_is_callable(); |
491 return map; | 496 return map; |
492 } | 497 } |
493 | 498 |
494 | 499 |
495 Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) { | 500 Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) { |
496 // Allocate the map for function instances. Maps are allocated first and their | 501 // Allocate the map for function instances. Maps are allocated first and their |
497 // prototypes patched later, once empty function is created. | 502 // prototypes patched later, once empty function is created. |
498 | 503 |
499 // Functions with this map will not have a 'prototype' property, and | 504 // Functions with this map will not have a 'prototype' property, and |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 int size = IsFunctionModeWithPrototype(function_mode) ? 3 : 2; | 607 int size = IsFunctionModeWithPrototype(function_mode) ? 3 : 2; |
603 Map::EnsureDescriptorSlack(map, size); | 608 Map::EnsureDescriptorSlack(map, size); |
604 | 609 |
605 PropertyAttributes rw_attribs = | 610 PropertyAttributes rw_attribs = |
606 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); | 611 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); |
607 PropertyAttributes ro_attribs = | 612 PropertyAttributes ro_attribs = |
608 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); | 613 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
609 PropertyAttributes roc_attribs = | 614 PropertyAttributes roc_attribs = |
610 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); | 615 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); |
611 | 616 |
612 if (function_mode == BOUND_FUNCTION) { | 617 DCHECK(function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE || |
613 { // Add length. | 618 function_mode == FUNCTION_WITH_READONLY_PROTOTYPE || |
614 Handle<String> length_string = isolate()->factory()->length_string(); | 619 function_mode == FUNCTION_WITHOUT_PROTOTYPE); |
615 DataDescriptor d(length_string, 0, roc_attribs, Representation::Tagged()); | 620 { // Add length. |
616 map->AppendDescriptor(&d); | 621 Handle<AccessorInfo> length = |
617 } | 622 Accessors::FunctionLengthInfo(isolate(), roc_attribs); |
618 { // Add name. | 623 AccessorConstantDescriptor d(Handle<Name>(Name::cast(length->name())), |
619 Handle<String> name_string = isolate()->factory()->name_string(); | 624 length, roc_attribs); |
620 DataDescriptor d(name_string, 1, roc_attribs, Representation::Tagged()); | 625 map->AppendDescriptor(&d); |
621 map->AppendDescriptor(&d); | 626 } |
622 } | 627 { // Add name. |
623 } else { | 628 Handle<AccessorInfo> name = |
624 DCHECK(function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE || | 629 Accessors::FunctionNameInfo(isolate(), roc_attribs); |
625 function_mode == FUNCTION_WITH_READONLY_PROTOTYPE || | 630 AccessorConstantDescriptor d(Handle<Name>(Name::cast(name->name())), name, |
626 function_mode == FUNCTION_WITHOUT_PROTOTYPE); | 631 roc_attribs); |
627 { // Add length. | 632 map->AppendDescriptor(&d); |
628 Handle<AccessorInfo> length = | |
629 Accessors::FunctionLengthInfo(isolate(), roc_attribs); | |
630 AccessorConstantDescriptor d(Handle<Name>(Name::cast(length->name())), | |
631 length, roc_attribs); | |
632 map->AppendDescriptor(&d); | |
633 } | |
634 { // Add name. | |
635 Handle<AccessorInfo> name = | |
636 Accessors::FunctionNameInfo(isolate(), roc_attribs); | |
637 AccessorConstantDescriptor d(Handle<Name>(Name::cast(name->name())), name, | |
638 roc_attribs); | |
639 map->AppendDescriptor(&d); | |
640 } | |
641 } | 633 } |
642 if (IsFunctionModeWithPrototype(function_mode)) { | 634 if (IsFunctionModeWithPrototype(function_mode)) { |
643 // Add prototype. | 635 // Add prototype. |
644 PropertyAttributes attribs = | 636 PropertyAttributes attribs = |
645 function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE ? rw_attribs | 637 function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE ? rw_attribs |
646 : ro_attribs; | 638 : ro_attribs; |
647 Handle<AccessorInfo> prototype = | 639 Handle<AccessorInfo> prototype = |
648 Accessors::FunctionPrototypeInfo(isolate(), attribs); | 640 Accessors::FunctionPrototypeInfo(isolate(), attribs); |
649 AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())), | 641 AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())), |
650 prototype, attribs); | 642 prototype, attribs); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 Builtins::kRestrictedStrictArgumentsPropertiesThrower); | 717 Builtins::kRestrictedStrictArgumentsPropertiesThrower); |
726 } | 718 } |
727 return strict_poison_function_; | 719 return strict_poison_function_; |
728 } | 720 } |
729 | 721 |
730 | 722 |
731 Handle<Map> Genesis::CreateStrictFunctionMap( | 723 Handle<Map> Genesis::CreateStrictFunctionMap( |
732 FunctionMode function_mode, Handle<JSFunction> empty_function) { | 724 FunctionMode function_mode, Handle<JSFunction> empty_function) { |
733 Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); | 725 Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); |
734 SetStrictFunctionInstanceDescriptor(map, function_mode); | 726 SetStrictFunctionInstanceDescriptor(map, function_mode); |
735 map->set_is_constructor(IsFunctionModeWithPrototype(function_mode)); | 727 if (IsFunctionModeWithPrototype(function_mode)) map->set_is_constructor(); |
736 map->set_is_callable(); | 728 map->set_is_callable(); |
737 Map::SetPrototype(map, empty_function); | 729 Map::SetPrototype(map, empty_function); |
738 return map; | 730 return map; |
739 } | 731 } |
740 | 732 |
741 | 733 |
742 Handle<Map> Genesis::CreateStrongFunctionMap( | 734 Handle<Map> Genesis::CreateStrongFunctionMap( |
743 Handle<JSFunction> empty_function, bool is_constructor) { | 735 Handle<JSFunction> empty_function, bool is_constructor) { |
744 Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); | 736 Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); |
745 SetStrongFunctionInstanceDescriptor(map); | 737 SetStrongFunctionInstanceDescriptor(map); |
746 map->set_is_constructor(is_constructor); | 738 if (is_constructor) map->set_is_constructor(); |
747 Map::SetPrototype(map, empty_function); | 739 Map::SetPrototype(map, empty_function); |
748 map->set_is_callable(); | 740 map->set_is_callable(); |
749 map->set_is_extensible(is_constructor); | 741 map->set_is_extensible(is_constructor); |
750 map->set_is_strong(); | 742 map->set_is_strong(); |
751 return map; | 743 return map; |
752 } | 744 } |
753 | 745 |
754 | 746 |
755 void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) { | 747 void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) { |
756 // Allocate map for the prototype-less strict mode instances. | 748 // Allocate map for the prototype-less strict mode instances. |
757 Handle<Map> strict_function_without_prototype_map = | 749 Handle<Map> strict_function_without_prototype_map = |
758 CreateStrictFunctionMap(FUNCTION_WITHOUT_PROTOTYPE, empty); | 750 CreateStrictFunctionMap(FUNCTION_WITHOUT_PROTOTYPE, empty); |
759 native_context()->set_strict_function_without_prototype_map( | 751 native_context()->set_strict_function_without_prototype_map( |
760 *strict_function_without_prototype_map); | 752 *strict_function_without_prototype_map); |
761 | 753 |
762 // Allocate map for the strict mode functions. This map is temporary, used | 754 // Allocate map for the strict mode functions. This map is temporary, used |
763 // only for processing of builtins. | 755 // only for processing of builtins. |
764 // Later the map is replaced with writable prototype map, allocated below. | 756 // Later the map is replaced with writable prototype map, allocated below. |
765 Handle<Map> strict_function_map = | 757 Handle<Map> strict_function_map = |
766 CreateStrictFunctionMap(FUNCTION_WITH_READONLY_PROTOTYPE, empty); | 758 CreateStrictFunctionMap(FUNCTION_WITH_READONLY_PROTOTYPE, empty); |
767 native_context()->set_strict_function_map(*strict_function_map); | 759 native_context()->set_strict_function_map(*strict_function_map); |
768 | 760 |
769 // The final map for the strict mode functions. Writeable prototype. | 761 // The final map for the strict mode functions. Writeable prototype. |
770 // This map is installed in MakeFunctionInstancePrototypeWritable. | 762 // This map is installed in MakeFunctionInstancePrototypeWritable. |
771 strict_function_map_writable_prototype_ = | 763 strict_function_map_writable_prototype_ = |
772 CreateStrictFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE, empty); | 764 CreateStrictFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE, empty); |
773 | |
774 // Special map for non-constructor bound functions. | |
775 // TODO(bmeurer): Bound functions should not be represented as JSFunctions. | |
776 Handle<Map> bound_function_without_constructor_map = | |
777 CreateStrictFunctionMap(BOUND_FUNCTION, empty); | |
778 native_context()->set_bound_function_without_constructor_map( | |
779 *bound_function_without_constructor_map); | |
780 | |
781 // Special map for constructor bound functions. | |
782 // TODO(bmeurer): Bound functions should not be represented as JSFunctions. | |
783 Handle<Map> bound_function_with_constructor_map = | |
784 Map::Copy(bound_function_without_constructor_map, "IsConstructor"); | |
785 bound_function_with_constructor_map->set_is_constructor(true); | |
786 native_context()->set_bound_function_with_constructor_map( | |
787 *bound_function_with_constructor_map); | |
788 } | 765 } |
789 | 766 |
790 | 767 |
791 void Genesis::CreateStrongModeFunctionMaps(Handle<JSFunction> empty) { | 768 void Genesis::CreateStrongModeFunctionMaps(Handle<JSFunction> empty) { |
792 // Allocate map for strong mode instances, which never have prototypes. | 769 // Allocate map for strong mode instances, which never have prototypes. |
793 Handle<Map> strong_function_map = CreateStrongFunctionMap(empty, false); | 770 Handle<Map> strong_function_map = CreateStrongFunctionMap(empty, false); |
794 native_context()->set_strong_function_map(*strong_function_map); | 771 native_context()->set_strong_function_map(*strong_function_map); |
795 // Constructors do, though. | 772 // Constructors do, though. |
796 Handle<Map> strong_constructor_map = CreateStrongFunctionMap(empty, true); | 773 Handle<Map> strong_constructor_map = CreateStrongFunctionMap(empty, true); |
797 native_context()->set_strong_constructor_map(*strong_constructor_map); | 774 native_context()->set_strong_constructor_map(*strong_constructor_map); |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1452 } | 1429 } |
1453 | 1430 |
1454 { // -- W e a k S e t | 1431 { // -- W e a k S e t |
1455 Handle<JSFunction> js_weak_set_fun = InstallFunction( | 1432 Handle<JSFunction> js_weak_set_fun = InstallFunction( |
1456 global, "WeakSet", JS_WEAK_SET_TYPE, JSWeakSet::kSize, | 1433 global, "WeakSet", JS_WEAK_SET_TYPE, JSWeakSet::kSize, |
1457 isolate->initial_object_prototype(), Builtins::kIllegal); | 1434 isolate->initial_object_prototype(), Builtins::kIllegal); |
1458 InstallWithIntrinsicDefaultProto(isolate, js_weak_set_fun, | 1435 InstallWithIntrinsicDefaultProto(isolate, js_weak_set_fun, |
1459 Context::JS_WEAK_SET_FUN_INDEX); | 1436 Context::JS_WEAK_SET_FUN_INDEX); |
1460 } | 1437 } |
1461 | 1438 |
| 1439 { // --- B o u n d F u n c t i o n |
| 1440 Handle<Map> map = |
| 1441 factory->NewMap(JS_BOUND_FUNCTION_TYPE, JSBoundFunction::kSize); |
| 1442 map->set_is_callable(); |
| 1443 Map::SetPrototype(map, empty_function); |
| 1444 |
| 1445 PropertyAttributes roc_attribs = |
| 1446 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); |
| 1447 Map::EnsureDescriptorSlack(map, 2); |
| 1448 |
| 1449 { // length |
| 1450 DataDescriptor d(factory->length_string(), JSBoundFunction::kLengthIndex, |
| 1451 roc_attribs, Representation::Tagged()); |
| 1452 map->AppendDescriptor(&d); |
| 1453 } |
| 1454 { // name |
| 1455 DataDescriptor d(factory->name_string(), JSBoundFunction::kNameIndex, |
| 1456 roc_attribs, Representation::Tagged()); |
| 1457 map->AppendDescriptor(&d); |
| 1458 } |
| 1459 |
| 1460 map->SetInObjectProperties(2); |
| 1461 native_context()->set_bound_function_without_constructor_map(*map); |
| 1462 |
| 1463 map = Map::Copy(map, "IsConstructor"); |
| 1464 map->set_is_constructor(); |
| 1465 native_context()->set_bound_function_with_constructor_map(*map); |
| 1466 } |
| 1467 |
1462 { // --- sloppy arguments map | 1468 { // --- sloppy arguments map |
1463 // Make sure we can recognize argument objects at runtime. | 1469 // Make sure we can recognize argument objects at runtime. |
1464 // This is done by introducing an anonymous function with | 1470 // This is done by introducing an anonymous function with |
1465 // class_name equals 'Arguments'. | 1471 // class_name equals 'Arguments'. |
1466 Handle<String> arguments_string = factory->Arguments_string(); | 1472 Handle<String> arguments_string = factory->Arguments_string(); |
1467 Handle<Code> code = isolate->builtins()->Illegal(); | 1473 Handle<Code> code = isolate->builtins()->Illegal(); |
1468 Handle<JSFunction> function = factory->NewFunctionWithoutPrototype( | 1474 Handle<JSFunction> function = factory->NewFunctionWithoutPrototype( |
1469 arguments_string, code); | 1475 arguments_string, code); |
1470 function->shared()->set_instance_class_name(*arguments_string); | 1476 function->shared()->set_instance_class_name(*arguments_string); |
1471 | 1477 |
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2278 } | 2284 } |
2279 | 2285 |
2280 | 2286 |
2281 void Genesis::InstallJSProxyMaps() { | 2287 void Genesis::InstallJSProxyMaps() { |
2282 // Allocate the different maps for all Proxy types. | 2288 // Allocate the different maps for all Proxy types. |
2283 // Next to the default proxy, we need maps indicating callable and | 2289 // Next to the default proxy, we need maps indicating callable and |
2284 // constructable proxies. | 2290 // constructable proxies. |
2285 | 2291 |
2286 Handle<Map> proxy_function_map = | 2292 Handle<Map> proxy_function_map = |
2287 Map::Copy(isolate()->sloppy_function_without_prototype_map(), "Proxy"); | 2293 Map::Copy(isolate()->sloppy_function_without_prototype_map(), "Proxy"); |
2288 proxy_function_map->set_is_constructor(true); | 2294 proxy_function_map->set_is_constructor(); |
2289 native_context()->set_proxy_function_map(*proxy_function_map); | 2295 native_context()->set_proxy_function_map(*proxy_function_map); |
2290 | 2296 |
2291 Handle<Map> proxy_map = | 2297 Handle<Map> proxy_map = |
2292 factory()->NewMap(JS_PROXY_TYPE, JSProxy::kSize, FAST_ELEMENTS); | 2298 factory()->NewMap(JS_PROXY_TYPE, JSProxy::kSize, FAST_ELEMENTS); |
2293 native_context()->set_proxy_map(*proxy_map); | 2299 native_context()->set_proxy_map(*proxy_map); |
2294 | 2300 |
2295 Handle<Map> proxy_callable_map = Map::Copy(proxy_map, "callable Proxy"); | 2301 Handle<Map> proxy_callable_map = Map::Copy(proxy_map, "callable Proxy"); |
2296 proxy_callable_map->set_is_callable(); | 2302 proxy_callable_map->set_is_callable(); |
2297 native_context()->set_proxy_callable_map(*proxy_callable_map); | 2303 native_context()->set_proxy_callable_map(*proxy_callable_map); |
2298 proxy_callable_map->SetConstructor(native_context()->function_function()); | 2304 proxy_callable_map->SetConstructor(native_context()->function_function()); |
2299 | 2305 |
2300 Handle<Map> proxy_constructor_map = | 2306 Handle<Map> proxy_constructor_map = |
2301 Map::Copy(proxy_callable_map, "constructor Proxy"); | 2307 Map::Copy(proxy_callable_map, "constructor Proxy"); |
2302 proxy_constructor_map->set_is_constructor(true); | 2308 proxy_constructor_map->set_is_constructor(); |
2303 native_context()->set_proxy_constructor_map(*proxy_constructor_map); | 2309 native_context()->set_proxy_constructor_map(*proxy_constructor_map); |
2304 } | 2310 } |
2305 | 2311 |
2306 | 2312 |
2307 void Genesis::InitializeGlobal_harmony_proxies() { | 2313 void Genesis::InitializeGlobal_harmony_proxies() { |
2308 if (!FLAG_harmony_proxies) return; | 2314 if (!FLAG_harmony_proxies) return; |
2309 Handle<JSGlobalObject> global( | 2315 Handle<JSGlobalObject> global( |
2310 JSGlobalObject::cast(native_context()->global_object())); | 2316 JSGlobalObject::cast(native_context()->global_object())); |
2311 Isolate* isolate = global->GetIsolate(); | 2317 Isolate* isolate = global->GetIsolate(); |
2312 Factory* factory = isolate->factory(); | 2318 Factory* factory = isolate->factory(); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2518 MaybeHandle<JSObject>(), Builtins::kArrayConcat); | 2524 MaybeHandle<JSObject>(), Builtins::kArrayConcat); |
2519 | 2525 |
2520 // Make sure that InternalArray.prototype.concat appears to be compiled. | 2526 // Make sure that InternalArray.prototype.concat appears to be compiled. |
2521 // The code will never be called, but inline caching for call will | 2527 // The code will never be called, but inline caching for call will |
2522 // only work if it appears to be compiled. | 2528 // only work if it appears to be compiled. |
2523 concat->shared()->DontAdaptArguments(); | 2529 concat->shared()->DontAdaptArguments(); |
2524 DCHECK(concat->is_compiled()); | 2530 DCHECK(concat->is_compiled()); |
2525 // Set the lengths for the functions to satisfy ECMA-262. | 2531 // Set the lengths for the functions to satisfy ECMA-262. |
2526 concat->shared()->set_length(1); | 2532 concat->shared()->set_length(1); |
2527 } | 2533 } |
2528 // Install Function.prototype.apply, call, and toString. | 2534 |
| 2535 // Install Function.prototype.apply, bind, call, and toString. |
2529 { | 2536 { |
2530 Handle<String> key = factory()->Function_string(); | 2537 Handle<String> key = factory()->Function_string(); |
2531 Handle<JSFunction> function = | 2538 Handle<JSFunction> function = |
2532 Handle<JSFunction>::cast(Object::GetProperty( | 2539 Handle<JSFunction>::cast(Object::GetProperty( |
2533 handle(native_context()->global_object()), key).ToHandleChecked()); | 2540 handle(native_context()->global_object()), key).ToHandleChecked()); |
2534 Handle<JSObject> proto = | 2541 Handle<JSObject> proto = |
2535 Handle<JSObject>(JSObject::cast(function->instance_prototype())); | 2542 Handle<JSObject>(JSObject::cast(function->instance_prototype())); |
2536 | 2543 |
2537 // Install the apply, call and toString functions. | 2544 // Install the apply, bind, call and toString functions. |
2538 SimpleInstallFunction(proto, factory()->apply_string(), | 2545 SimpleInstallFunction(proto, factory()->apply_string(), |
2539 Builtins::kFunctionPrototypeApply, 2, false); | 2546 Builtins::kFunctionPrototypeApply, 2, false); |
| 2547 SimpleInstallFunction(proto, factory()->bind_string(), |
| 2548 Builtins::kFunctionPrototypeBind, 1, false); |
2540 SimpleInstallFunction(proto, factory()->call_string(), | 2549 SimpleInstallFunction(proto, factory()->call_string(), |
2541 Builtins::kFunctionPrototypeCall, 1, false); | 2550 Builtins::kFunctionPrototypeCall, 1, false); |
2542 SimpleInstallFunction(proto, factory()->toString_string(), | 2551 SimpleInstallFunction(proto, factory()->toString_string(), |
2543 Builtins::kFunctionPrototypeToString, 0, false); | 2552 Builtins::kFunctionPrototypeToString, 0, false); |
2544 } | 2553 } |
2545 | 2554 |
2546 // Set up the Promise constructor. | 2555 // Set up the Promise constructor. |
2547 { | 2556 { |
2548 Handle<String> key = factory()->Promise_string(); | 2557 Handle<String> key = factory()->Promise_string(); |
2549 Handle<JSFunction> function = Handle<JSFunction>::cast( | 2558 Handle<JSFunction> function = Handle<JSFunction>::cast( |
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3353 } | 3362 } |
3354 | 3363 |
3355 | 3364 |
3356 // Called when the top-level V8 mutex is destroyed. | 3365 // Called when the top-level V8 mutex is destroyed. |
3357 void Bootstrapper::FreeThreadResources() { | 3366 void Bootstrapper::FreeThreadResources() { |
3358 DCHECK(!IsActive()); | 3367 DCHECK(!IsActive()); |
3359 } | 3368 } |
3360 | 3369 |
3361 } // namespace internal | 3370 } // namespace internal |
3362 } // namespace v8 | 3371 } // namespace v8 |
OLD | NEW |