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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 // Without prototype. | 250 // Without prototype. |
251 FUNCTION_WITHOUT_PROTOTYPE, | 251 FUNCTION_WITHOUT_PROTOTYPE, |
252 BOUND_FUNCTION | 252 BOUND_FUNCTION |
253 }; | 253 }; |
254 | 254 |
255 static bool IsFunctionModeWithPrototype(FunctionMode function_mode) { | 255 static bool IsFunctionModeWithPrototype(FunctionMode function_mode) { |
256 return (function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE || | 256 return (function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE || |
257 function_mode == FUNCTION_WITH_READONLY_PROTOTYPE); | 257 function_mode == FUNCTION_WITH_READONLY_PROTOTYPE); |
258 } | 258 } |
259 | 259 |
260 Handle<Map> CreateSloppyFunctionMap(FunctionMode function_mode); | 260 Handle<Map> CreateSloppyFunctionMap(FunctionMode function_mode, |
261 bool add_restricted_props = true); | |
261 | 262 |
262 void SetFunctionInstanceDescriptor(Handle<Map> map, | 263 void SetFunctionInstanceDescriptor(Handle<Map> map, |
263 FunctionMode function_mode); | 264 FunctionMode function_mode, |
265 bool add_restricted_props = true); | |
264 void MakeFunctionInstancePrototypeWritable(); | 266 void MakeFunctionInstancePrototypeWritable(); |
265 | 267 |
266 Handle<Map> CreateStrictFunctionMap(FunctionMode function_mode, | 268 Handle<Map> CreateStrictFunctionMap(FunctionMode function_mode, |
267 Handle<JSFunction> empty_function); | 269 Handle<JSFunction> empty_function); |
268 Handle<Map> CreateStrongFunctionMap(Handle<JSFunction> empty_function, | 270 Handle<Map> CreateStrongFunctionMap(Handle<JSFunction> empty_function, |
269 bool is_constructor); | 271 bool is_constructor); |
270 | 272 |
271 | 273 |
272 void SetStrictFunctionInstanceDescriptor(Handle<Map> map, | 274 void SetStrictFunctionInstanceDescriptor(Handle<Map> map, |
273 FunctionMode function_mode); | 275 FunctionMode function_mode); |
(...skipping 15 matching lines...) Expand all Loading... | |
289 Isolate* isolate_; | 291 Isolate* isolate_; |
290 Handle<Context> result_; | 292 Handle<Context> result_; |
291 Handle<Context> native_context_; | 293 Handle<Context> native_context_; |
292 | 294 |
293 // Function maps. Function maps are created initially with a read only | 295 // Function maps. Function maps are created initially with a read only |
294 // prototype for the processing of JS builtins. Later the function maps are | 296 // prototype for the processing of JS builtins. Later the function maps are |
295 // replaced in order to make prototype writable. These are the final, writable | 297 // replaced in order to make prototype writable. These are the final, writable |
296 // prototype, maps. | 298 // prototype, maps. |
297 Handle<Map> sloppy_function_map_writable_prototype_; | 299 Handle<Map> sloppy_function_map_writable_prototype_; |
298 Handle<Map> strict_function_map_writable_prototype_; | 300 Handle<Map> strict_function_map_writable_prototype_; |
301 Handle<Map> plain_function_map_writable_prototype_; | |
arv (Not doing code reviews)
2015/03/25 13:36:47
Can you rename these. Right now it is not clear ho
caitp (gmail)
2015/03/25 13:42:59
what would be better here? "newstyle_..."? "unpois
| |
299 Handle<JSFunction> strict_poison_function; | 302 Handle<JSFunction> strict_poison_function; |
300 Handle<JSFunction> generator_poison_function; | 303 Handle<JSFunction> generator_poison_function; |
301 | 304 |
302 BootstrapperActive active_; | 305 BootstrapperActive active_; |
303 friend class Bootstrapper; | 306 friend class Bootstrapper; |
304 }; | 307 }; |
305 | 308 |
306 | 309 |
307 void Bootstrapper::Iterate(ObjectVisitor* v) { | 310 void Bootstrapper::Iterate(ObjectVisitor* v) { |
308 extensions_cache_.Iterate(v); | 311 extensions_cache_.Iterate(v); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
370 } | 373 } |
371 JSObject::AddProperty(target, internalized_name, function, attributes); | 374 JSObject::AddProperty(target, internalized_name, function, attributes); |
372 if (target->IsJSGlobalObject()) { | 375 if (target->IsJSGlobalObject()) { |
373 function->shared()->set_instance_class_name(*internalized_name); | 376 function->shared()->set_instance_class_name(*internalized_name); |
374 } | 377 } |
375 function->shared()->set_native(true); | 378 function->shared()->set_native(true); |
376 return function; | 379 return function; |
377 } | 380 } |
378 | 381 |
379 | 382 |
380 void Genesis::SetFunctionInstanceDescriptor( | 383 void Genesis::SetFunctionInstanceDescriptor(Handle<Map> map, |
381 Handle<Map> map, FunctionMode function_mode) { | 384 FunctionMode function_mode, |
385 bool add_restricted_props) { | |
382 int size = IsFunctionModeWithPrototype(function_mode) ? 5 : 4; | 386 int size = IsFunctionModeWithPrototype(function_mode) ? 5 : 4; |
383 Map::EnsureDescriptorSlack(map, size); | 387 Map::EnsureDescriptorSlack(map, size); |
384 | 388 |
385 PropertyAttributes ro_attribs = | 389 PropertyAttributes ro_attribs = |
386 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); | 390 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
387 PropertyAttributes roc_attribs = | 391 PropertyAttributes roc_attribs = |
388 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); | 392 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); |
389 | 393 |
390 Handle<AccessorInfo> length = | 394 Handle<AccessorInfo> length = |
391 Accessors::FunctionLengthInfo(isolate(), roc_attribs); | 395 Accessors::FunctionLengthInfo(isolate(), roc_attribs); |
392 { // Add length. | 396 { // Add length. |
393 AccessorConstantDescriptor d(Handle<Name>(Name::cast(length->name())), | 397 AccessorConstantDescriptor d(Handle<Name>(Name::cast(length->name())), |
394 length, roc_attribs); | 398 length, roc_attribs); |
395 map->AppendDescriptor(&d); | 399 map->AppendDescriptor(&d); |
396 } | 400 } |
397 Handle<AccessorInfo> name = | 401 Handle<AccessorInfo> name = |
398 Accessors::FunctionNameInfo(isolate(), ro_attribs); | 402 Accessors::FunctionNameInfo(isolate(), ro_attribs); |
399 { // Add name. | 403 { // Add name. |
400 AccessorConstantDescriptor d(Handle<Name>(Name::cast(name->name())), name, | 404 AccessorConstantDescriptor d(Handle<Name>(Name::cast(name->name())), name, |
401 roc_attribs); | 405 roc_attribs); |
402 map->AppendDescriptor(&d); | 406 map->AppendDescriptor(&d); |
403 } | 407 } |
404 Handle<AccessorInfo> args = | 408 if (add_restricted_props) { // Add arguments. |
405 Accessors::FunctionArgumentsInfo(isolate(), ro_attribs); | 409 Handle<AccessorInfo> args = |
406 { // Add arguments. | 410 Accessors::FunctionArgumentsInfo(isolate(), ro_attribs); |
407 AccessorConstantDescriptor d(Handle<Name>(Name::cast(args->name())), args, | 411 AccessorConstantDescriptor d(Handle<Name>(Name::cast(args->name())), args, |
408 ro_attribs); | 412 ro_attribs); |
409 map->AppendDescriptor(&d); | 413 map->AppendDescriptor(&d); |
410 } | 414 } |
411 Handle<AccessorInfo> caller = | 415 if (add_restricted_props) { // Add caller. |
arv (Not doing code reviews)
2015/03/25 13:36:47
Maybe
if (add_restricted_props) {
{
...
}
| |
412 Accessors::FunctionCallerInfo(isolate(), ro_attribs); | 416 Handle<AccessorInfo> caller = |
413 { // Add caller. | 417 Accessors::FunctionCallerInfo(isolate(), ro_attribs); |
414 AccessorConstantDescriptor d(Handle<Name>(Name::cast(caller->name())), | 418 AccessorConstantDescriptor d(Handle<Name>(Name::cast(caller->name())), |
415 caller, ro_attribs); | 419 caller, ro_attribs); |
416 map->AppendDescriptor(&d); | 420 map->AppendDescriptor(&d); |
417 } | 421 } |
418 if (IsFunctionModeWithPrototype(function_mode)) { | 422 if (IsFunctionModeWithPrototype(function_mode)) { |
419 if (function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE) { | 423 if (function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE) { |
420 ro_attribs = static_cast<PropertyAttributes>(ro_attribs & ~READ_ONLY); | 424 ro_attribs = static_cast<PropertyAttributes>(ro_attribs & ~READ_ONLY); |
421 } | 425 } |
422 Handle<AccessorInfo> prototype = | 426 Handle<AccessorInfo> prototype = |
423 Accessors::FunctionPrototypeInfo(isolate(), ro_attribs); | 427 Accessors::FunctionPrototypeInfo(isolate(), ro_attribs); |
424 AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())), | 428 AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())), |
425 prototype, ro_attribs); | 429 prototype, ro_attribs); |
426 map->AppendDescriptor(&d); | 430 map->AppendDescriptor(&d); |
427 } | 431 } |
428 } | 432 } |
429 | 433 |
430 | 434 |
431 Handle<Map> Genesis::CreateSloppyFunctionMap(FunctionMode function_mode) { | 435 Handle<Map> Genesis::CreateSloppyFunctionMap(FunctionMode function_mode, |
436 bool add_restricted_props) { | |
432 Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); | 437 Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); |
433 SetFunctionInstanceDescriptor(map, function_mode); | 438 SetFunctionInstanceDescriptor(map, function_mode, add_restricted_props); |
434 map->set_function_with_prototype(IsFunctionModeWithPrototype(function_mode)); | 439 map->set_function_with_prototype(IsFunctionModeWithPrototype(function_mode)); |
435 return map; | 440 return map; |
436 } | 441 } |
437 | 442 |
438 | 443 |
439 Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) { | 444 Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) { |
440 // Allocate the map for function instances. Maps are allocated first and their | 445 // Allocate the map for function instances. Maps are allocated first and their |
441 // prototypes patched later, once empty function is created. | 446 // prototypes patched later, once empty function is created. |
442 | 447 |
443 // Functions with this map will not have a 'prototype' property, and | 448 // Functions with this map will not have a 'prototype' property, and |
444 // can not be used as constructors. | 449 // can not be used as constructors. |
445 Handle<Map> function_without_prototype_map = | 450 Handle<Map> function_without_prototype_map = |
446 CreateSloppyFunctionMap(FUNCTION_WITHOUT_PROTOTYPE); | 451 CreateSloppyFunctionMap(FUNCTION_WITHOUT_PROTOTYPE); |
447 native_context()->set_sloppy_function_without_prototype_map( | 452 native_context()->set_sloppy_function_without_prototype_map( |
448 *function_without_prototype_map); | 453 *function_without_prototype_map); |
449 | 454 |
455 Handle<Map> plain_function_without_prototype_map = | |
456 CreateSloppyFunctionMap(FUNCTION_WITHOUT_PROTOTYPE, false); | |
457 native_context()->set_plain_function_without_prototype_map( | |
458 *plain_function_without_prototype_map); | |
459 | |
450 // Allocate the function map. This map is temporary, used only for processing | 460 // Allocate the function map. This map is temporary, used only for processing |
451 // of builtins. | 461 // of builtins. |
452 // Later the map is replaced with writable prototype map, allocated below. | 462 // Later the map is replaced with writable prototype map, allocated below. |
453 Handle<Map> function_map = | 463 Handle<Map> function_map = |
454 CreateSloppyFunctionMap(FUNCTION_WITH_READONLY_PROTOTYPE); | 464 CreateSloppyFunctionMap(FUNCTION_WITH_READONLY_PROTOTYPE); |
455 native_context()->set_sloppy_function_map(*function_map); | 465 native_context()->set_sloppy_function_map(*function_map); |
456 native_context()->set_sloppy_function_with_readonly_prototype_map( | 466 native_context()->set_sloppy_function_with_readonly_prototype_map( |
457 *function_map); | 467 *function_map); |
458 | 468 |
469 Handle<Map> plain_function_map = | |
470 CreateSloppyFunctionMap(FUNCTION_WITH_READONLY_PROTOTYPE, false); | |
471 native_context()->set_plain_function_map(*plain_function_map); | |
472 | |
459 // The final map for functions. Writeable prototype. | 473 // The final map for functions. Writeable prototype. |
460 // This map is installed in MakeFunctionInstancePrototypeWritable. | 474 // This map is installed in MakeFunctionInstancePrototypeWritable. |
461 sloppy_function_map_writable_prototype_ = | 475 sloppy_function_map_writable_prototype_ = |
462 CreateSloppyFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE); | 476 CreateSloppyFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE); |
463 | 477 plain_function_map_writable_prototype_ = |
478 CreateSloppyFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE, false); | |
464 Factory* factory = isolate->factory(); | 479 Factory* factory = isolate->factory(); |
465 | 480 |
466 Handle<String> object_name = factory->Object_string(); | 481 Handle<String> object_name = factory->Object_string(); |
467 | 482 |
468 Handle<JSObject> object_function_prototype; | 483 Handle<JSObject> object_function_prototype; |
469 | 484 |
470 { // --- O b j e c t --- | 485 { // --- O b j e c t --- |
471 Handle<JSFunction> object_fun = factory->NewFunction(object_name); | 486 Handle<JSFunction> object_fun = factory->NewFunction(object_name); |
472 int unused = JSObject::kInitialGlobalObjectUnusedPropertiesCount; | 487 int unused = JSObject::kInitialGlobalObjectUnusedPropertiesCount; |
473 int instance_size = JSObject::kHeaderSize + kPointerSize * unused; | 488 int instance_size = JSObject::kHeaderSize + kPointerSize * unused; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); | 534 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); |
520 empty_function->shared()->set_script(*script); | 535 empty_function->shared()->set_script(*script); |
521 empty_function->shared()->set_start_position(0); | 536 empty_function->shared()->set_start_position(0); |
522 empty_function->shared()->set_end_position(source->length()); | 537 empty_function->shared()->set_end_position(source->length()); |
523 empty_function->shared()->DontAdaptArguments(); | 538 empty_function->shared()->DontAdaptArguments(); |
524 | 539 |
525 // Set prototypes for the function maps. | 540 // Set prototypes for the function maps. |
526 native_context()->sloppy_function_map()->SetPrototype(empty_function); | 541 native_context()->sloppy_function_map()->SetPrototype(empty_function); |
527 native_context()->sloppy_function_without_prototype_map()->SetPrototype( | 542 native_context()->sloppy_function_without_prototype_map()->SetPrototype( |
528 empty_function); | 543 empty_function); |
544 native_context()->plain_function_map()->SetPrototype(empty_function); | |
545 native_context()->plain_function_without_prototype_map()->SetPrototype( | |
546 empty_function); | |
529 sloppy_function_map_writable_prototype_->SetPrototype(empty_function); | 547 sloppy_function_map_writable_prototype_->SetPrototype(empty_function); |
548 plain_function_map_writable_prototype_->SetPrototype(empty_function); | |
530 return empty_function; | 549 return empty_function; |
531 } | 550 } |
532 | 551 |
533 | 552 |
534 void Genesis::SetStrictFunctionInstanceDescriptor( | 553 void Genesis::SetStrictFunctionInstanceDescriptor(Handle<Map> map, |
535 Handle<Map> map, FunctionMode function_mode) { | 554 FunctionMode function_mode) { |
536 int size = IsFunctionModeWithPrototype(function_mode) ? 5 : 4; | 555 int size = IsFunctionModeWithPrototype(function_mode) ? 5 : 4; |
537 Map::EnsureDescriptorSlack(map, size); | 556 Map::EnsureDescriptorSlack(map, size); |
538 | 557 |
539 Handle<AccessorPair> arguments(factory()->NewAccessorPair()); | 558 Handle<AccessorPair> arguments(factory()->NewAccessorPair()); |
540 Handle<AccessorPair> caller(factory()->NewAccessorPair()); | 559 Handle<AccessorPair> caller(factory()->NewAccessorPair()); |
541 PropertyAttributes rw_attribs = | 560 PropertyAttributes rw_attribs = |
542 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); | 561 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); |
543 PropertyAttributes ro_attribs = | 562 PropertyAttributes ro_attribs = |
544 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); | 563 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
545 PropertyAttributes roc_attribs = | 564 PropertyAttributes roc_attribs = |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
642 generator_poison_function->set_map(native_context()->sloppy_function_map()); | 661 generator_poison_function->set_map(native_context()->sloppy_function_map()); |
643 generator_poison_function->shared()->DontAdaptArguments(); | 662 generator_poison_function->shared()->DontAdaptArguments(); |
644 | 663 |
645 JSObject::PreventExtensions(generator_poison_function).Assert(); | 664 JSObject::PreventExtensions(generator_poison_function).Assert(); |
646 } | 665 } |
647 return generator_poison_function; | 666 return generator_poison_function; |
648 } | 667 } |
649 | 668 |
650 | 669 |
651 Handle<Map> Genesis::CreateStrictFunctionMap( | 670 Handle<Map> Genesis::CreateStrictFunctionMap( |
652 FunctionMode function_mode, | 671 FunctionMode function_mode, Handle<JSFunction> empty_function) { |
653 Handle<JSFunction> empty_function) { | |
654 Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); | 672 Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); |
655 SetStrictFunctionInstanceDescriptor(map, function_mode); | 673 SetStrictFunctionInstanceDescriptor(map, function_mode); |
656 map->set_function_with_prototype(IsFunctionModeWithPrototype(function_mode)); | 674 map->set_function_with_prototype(IsFunctionModeWithPrototype(function_mode)); |
657 map->SetPrototype(empty_function); | 675 map->SetPrototype(empty_function); |
658 return map; | 676 return map; |
659 } | 677 } |
660 | 678 |
661 | 679 |
662 Handle<Map> Genesis::CreateStrongFunctionMap( | 680 Handle<Map> Genesis::CreateStrongFunctionMap( |
663 Handle<JSFunction> empty_function, bool is_constructor) { | 681 Handle<JSFunction> empty_function, bool is_constructor) { |
(...skipping 18 matching lines...) Expand all Loading... | |
682 // only for processing of builtins. | 700 // only for processing of builtins. |
683 // Later the map is replaced with writable prototype map, allocated below. | 701 // Later the map is replaced with writable prototype map, allocated below. |
684 Handle<Map> strict_function_map = | 702 Handle<Map> strict_function_map = |
685 CreateStrictFunctionMap(FUNCTION_WITH_READONLY_PROTOTYPE, empty); | 703 CreateStrictFunctionMap(FUNCTION_WITH_READONLY_PROTOTYPE, empty); |
686 native_context()->set_strict_function_map(*strict_function_map); | 704 native_context()->set_strict_function_map(*strict_function_map); |
687 | 705 |
688 // The final map for the strict mode functions. Writeable prototype. | 706 // The final map for the strict mode functions. Writeable prototype. |
689 // This map is installed in MakeFunctionInstancePrototypeWritable. | 707 // This map is installed in MakeFunctionInstancePrototypeWritable. |
690 strict_function_map_writable_prototype_ = | 708 strict_function_map_writable_prototype_ = |
691 CreateStrictFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE, empty); | 709 CreateStrictFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE, empty); |
710 | |
692 // Special map for bound functions. | 711 // Special map for bound functions. |
693 Handle<Map> bound_function_map = | 712 Handle<Map> bound_function_map = |
694 CreateStrictFunctionMap(BOUND_FUNCTION, empty); | 713 CreateStrictFunctionMap(BOUND_FUNCTION, empty); |
695 native_context()->set_bound_function_map(*bound_function_map); | 714 native_context()->set_bound_function_map(*bound_function_map); |
696 | 715 |
697 // Complete the callbacks. | 716 // Complete the callbacks. |
698 PoisonArgumentsAndCaller(strict_function_without_prototype_map); | 717 PoisonArgumentsAndCaller(strict_function_without_prototype_map); |
699 PoisonArgumentsAndCaller(strict_function_map); | 718 PoisonArgumentsAndCaller(strict_function_map); |
700 PoisonArgumentsAndCaller(strict_function_map_writable_prototype_); | 719 PoisonArgumentsAndCaller(strict_function_map_writable_prototype_); |
701 PoisonArgumentsAndCaller(bound_function_map); | 720 PoisonArgumentsAndCaller(bound_function_map); |
(...skipping 14 matching lines...) Expand all Loading... | |
716 Handle<String> name, | 735 Handle<String> name, |
717 Handle<JSFunction> func) { | 736 Handle<JSFunction> func) { |
718 DescriptorArray* descs = map->instance_descriptors(); | 737 DescriptorArray* descs = map->instance_descriptors(); |
719 int number = descs->SearchWithCache(*name, *map); | 738 int number = descs->SearchWithCache(*name, *map); |
720 AccessorPair* accessors = AccessorPair::cast(descs->GetValue(number)); | 739 AccessorPair* accessors = AccessorPair::cast(descs->GetValue(number)); |
721 accessors->set_getter(*func); | 740 accessors->set_getter(*func); |
722 accessors->set_setter(*func); | 741 accessors->set_setter(*func); |
723 } | 742 } |
724 | 743 |
725 | 744 |
726 static void ReplaceAccessors(Handle<Map> map, | |
727 Handle<String> name, | |
728 PropertyAttributes attributes, | |
729 Handle<AccessorPair> accessor_pair) { | |
730 DescriptorArray* descriptors = map->instance_descriptors(); | |
731 int idx = descriptors->SearchWithCache(*name, *map); | |
732 AccessorConstantDescriptor descriptor(name, accessor_pair, attributes); | |
733 descriptors->Replace(idx, &descriptor); | |
734 } | |
735 | |
736 | |
737 void Genesis::PoisonArgumentsAndCaller(Handle<Map> map) { | 745 void Genesis::PoisonArgumentsAndCaller(Handle<Map> map) { |
738 SetAccessors(map, factory()->arguments_string(), GetStrictPoisonFunction()); | 746 SetAccessors(map, factory()->arguments_string(), GetStrictPoisonFunction()); |
739 SetAccessors(map, factory()->caller_string(), GetStrictPoisonFunction()); | 747 SetAccessors(map, factory()->caller_string(), GetStrictPoisonFunction()); |
740 } | 748 } |
741 | 749 |
742 | 750 |
743 static void AddToWeakNativeContextList(Context* context) { | 751 static void AddToWeakNativeContextList(Context* context) { |
744 DCHECK(context->IsNativeContext()); | 752 DCHECK(context->IsNativeContext()); |
745 Heap* heap = context->GetIsolate()->heap(); | 753 Heap* heap = context->GetIsolate()->heap(); |
746 #ifdef DEBUG | 754 #ifdef DEBUG |
(...skipping 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2065 InstallFunction(builtins, "GeneratorFunctionPrototype", | 2073 InstallFunction(builtins, "GeneratorFunctionPrototype", |
2066 JS_FUNCTION_TYPE, JSFunction::kHeaderSize, | 2074 JS_FUNCTION_TYPE, JSFunction::kHeaderSize, |
2067 generator_object_prototype, Builtins::kIllegal); | 2075 generator_object_prototype, Builtins::kIllegal); |
2068 InstallFunction(builtins, "GeneratorFunction", JS_FUNCTION_TYPE, | 2076 InstallFunction(builtins, "GeneratorFunction", JS_FUNCTION_TYPE, |
2069 JSFunction::kSize, generator_function_prototype, | 2077 JSFunction::kSize, generator_function_prototype, |
2070 Builtins::kIllegal); | 2078 Builtins::kIllegal); |
2071 | 2079 |
2072 // Create maps for generator functions and their prototypes. Store those | 2080 // Create maps for generator functions and their prototypes. Store those |
2073 // maps in the native context. | 2081 // maps in the native context. |
2074 Handle<Map> generator_function_map = | 2082 Handle<Map> generator_function_map = |
2075 Map::Copy(sloppy_function_map_writable_prototype_, "GeneratorFunction"); | 2083 Map::Copy(plain_function_map_writable_prototype_, "GeneratorFunction"); |
2076 generator_function_map->SetPrototype(generator_function_prototype); | 2084 generator_function_map->SetPrototype(generator_function_prototype); |
2077 native_context()->set_sloppy_generator_function_map( | 2085 native_context()->set_generator_function_map(*generator_function_map); |
2078 *generator_function_map); | |
2079 | |
2080 // The "arguments" and "caller" instance properties aren't specified, so | |
2081 // technically we could leave them out. They make even less sense for | |
2082 // generators than for functions. Still, the same argument that it makes | |
2083 // sense to keep them around but poisoned in strict mode applies to | |
2084 // generators as well. With poisoned accessors, naive callers can still | |
2085 // iterate over the properties without accessing them. | |
2086 // | |
2087 // We can't use PoisonArgumentsAndCaller because that mutates accessor pairs | |
2088 // in place, and the initial state of the generator function map shares the | |
2089 // accessor pair with sloppy functions. Also the error message should be | |
2090 // different. Also unhappily, we can't use the API accessors to implement | |
2091 // poisoning, because API accessors present themselves as data properties, | |
2092 // not accessor properties, and so getOwnPropertyDescriptor raises an | |
2093 // exception as it tries to get the values. Sadness. | |
2094 Handle<AccessorPair> poison_pair(factory()->NewAccessorPair()); | |
2095 PropertyAttributes rw_attribs = | |
2096 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); | |
2097 Handle<JSFunction> poison_function = GetGeneratorPoisonFunction(); | |
2098 poison_pair->set_getter(*poison_function); | |
2099 poison_pair->set_setter(*poison_function); | |
2100 ReplaceAccessors(generator_function_map, factory()->arguments_string(), | |
2101 rw_attribs, poison_pair); | |
2102 ReplaceAccessors(generator_function_map, factory()->caller_string(), | |
2103 rw_attribs, poison_pair); | |
2104 | |
2105 Handle<Map> strict_function_map(native_context()->strict_function_map()); | |
2106 Handle<Map> strict_generator_function_map = | |
2107 Map::Copy(strict_function_map, "StrictGeneratorFunction"); | |
2108 // "arguments" and "caller" already poisoned. | |
2109 strict_generator_function_map->SetPrototype(generator_function_prototype); | |
2110 native_context()->set_strict_generator_function_map( | |
2111 *strict_generator_function_map); | |
2112 | 2086 |
2113 Handle<Map> strong_function_map(native_context()->strong_function_map()); | 2087 Handle<Map> strong_function_map(native_context()->strong_function_map()); |
2114 Handle<Map> strong_generator_function_map = | 2088 Handle<Map> strong_generator_function_map = |
2115 Map::Copy(strong_function_map, "StrongGeneratorFunction"); | 2089 Map::Copy(strong_function_map, "StrongGeneratorFunction"); |
2116 strong_generator_function_map->SetPrototype(generator_function_prototype); | 2090 strong_generator_function_map->SetPrototype(generator_function_prototype); |
2117 native_context()->set_strong_generator_function_map( | 2091 native_context()->set_strong_generator_function_map( |
2118 *strong_generator_function_map); | 2092 *strong_generator_function_map); |
2119 | 2093 |
2120 Handle<JSFunction> object_function(native_context()->object_function()); | 2094 Handle<JSFunction> object_function(native_context()->object_function()); |
2121 Handle<Map> generator_object_prototype_map = Map::Create(isolate(), 0); | 2095 Handle<Map> generator_object_prototype_map = Map::Create(isolate(), 0); |
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2955 return from + sizeof(NestingCounterType); | 2929 return from + sizeof(NestingCounterType); |
2956 } | 2930 } |
2957 | 2931 |
2958 | 2932 |
2959 // Called when the top-level V8 mutex is destroyed. | 2933 // Called when the top-level V8 mutex is destroyed. |
2960 void Bootstrapper::FreeThreadResources() { | 2934 void Bootstrapper::FreeThreadResources() { |
2961 DCHECK(!IsActive()); | 2935 DCHECK(!IsActive()); |
2962 } | 2936 } |
2963 | 2937 |
2964 } } // namespace v8::internal | 2938 } } // namespace v8::internal |
OLD | NEW |