Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: src/bootstrapper.cc

Issue 1005393004: Handlify Map::SetPrototype() (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebased Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/factory.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 return Handle<Context>(); 321 return Handle<Context>();
322 } 322 }
323 return scope.CloseAndEscape(env); 323 return scope.CloseAndEscape(env);
324 } 324 }
325 325
326 326
327 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) { 327 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) {
328 // object.__proto__ = proto; 328 // object.__proto__ = proto;
329 Handle<Map> old_map = Handle<Map>(object->map()); 329 Handle<Map> old_map = Handle<Map>(object->map());
330 Handle<Map> new_map = Map::Copy(old_map, "SetObjectPrototype"); 330 Handle<Map> new_map = Map::Copy(old_map, "SetObjectPrototype");
331 new_map->SetPrototype(proto, FAST_PROTOTYPE); 331 Map::SetPrototype(new_map, proto, FAST_PROTOTYPE);
332 JSObject::MigrateToMap(object, new_map); 332 JSObject::MigrateToMap(object, new_map);
333 } 333 }
334 334
335 335
336 void Bootstrapper::DetachGlobal(Handle<Context> env) { 336 void Bootstrapper::DetachGlobal(Handle<Context> env) {
337 Factory* factory = env->GetIsolate()->factory(); 337 Factory* factory = env->GetIsolate()->factory();
338 Handle<JSGlobalProxy> global_proxy(JSGlobalProxy::cast(env->global_proxy())); 338 Handle<JSGlobalProxy> global_proxy(JSGlobalProxy::cast(env->global_proxy()));
339 global_proxy->set_native_context(*factory->null_value()); 339 global_proxy->set_native_context(*factory->null_value());
340 SetObjectPrototype(global_proxy, factory->null_value()); 340 SetObjectPrototype(global_proxy, factory->null_value());
341 global_proxy->map()->SetConstructor(*factory->null_value()); 341 global_proxy->map()->SetConstructor(*factory->null_value());
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 Handle<String> empty_string = 505 Handle<String> empty_string =
506 factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("Empty")); 506 factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("Empty"));
507 Handle<Code> code(isolate->builtins()->builtin(Builtins::kEmptyFunction)); 507 Handle<Code> code(isolate->builtins()->builtin(Builtins::kEmptyFunction));
508 Handle<JSFunction> empty_function = factory->NewFunctionWithoutPrototype( 508 Handle<JSFunction> empty_function = factory->NewFunctionWithoutPrototype(
509 empty_string, code); 509 empty_string, code);
510 510
511 // Allocate the function map first and then patch the prototype later 511 // Allocate the function map first and then patch the prototype later
512 Handle<Map> empty_function_map = 512 Handle<Map> empty_function_map =
513 CreateSloppyFunctionMap(FUNCTION_WITHOUT_PROTOTYPE); 513 CreateSloppyFunctionMap(FUNCTION_WITHOUT_PROTOTYPE);
514 DCHECK(!empty_function_map->is_dictionary_map()); 514 DCHECK(!empty_function_map->is_dictionary_map());
515 empty_function_map->SetPrototype(object_function_prototype); 515 Map::SetPrototype(empty_function_map, object_function_prototype);
516 empty_function_map->set_is_prototype_map(true); 516 empty_function_map->set_is_prototype_map(true);
517 517
518 empty_function->set_map(*empty_function_map); 518 empty_function->set_map(*empty_function_map);
519 519
520 // --- E m p t y --- 520 // --- E m p t y ---
521 Handle<String> source = factory->NewStringFromStaticChars("() {}"); 521 Handle<String> source = factory->NewStringFromStaticChars("() {}");
522 Handle<Script> script = factory->NewScript(source); 522 Handle<Script> script = factory->NewScript(source);
523 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); 523 script->set_type(Smi::FromInt(Script::TYPE_NATIVE));
524 empty_function->shared()->set_script(*script); 524 empty_function->shared()->set_script(*script);
525 empty_function->shared()->set_start_position(0); 525 empty_function->shared()->set_start_position(0);
526 empty_function->shared()->set_end_position(source->length()); 526 empty_function->shared()->set_end_position(source->length());
527 empty_function->shared()->DontAdaptArguments(); 527 empty_function->shared()->DontAdaptArguments();
528 528
529 // Set prototypes for the function maps. 529 // Set prototypes for the function maps.
530 native_context()->sloppy_function_map()->SetPrototype(empty_function); 530 Handle<Map> sloppy_function_map(native_context()->sloppy_function_map(),
531 native_context()->sloppy_function_without_prototype_map()->SetPrototype( 531 isolate);
532 empty_function); 532 Handle<Map> sloppy_function_without_prototype_map(
533 533 native_context()->sloppy_function_without_prototype_map(), isolate);
534 sloppy_function_map_writable_prototype_->SetPrototype(empty_function); 534 Map::SetPrototype(sloppy_function_map, empty_function);
535 Map::SetPrototype(sloppy_function_without_prototype_map, empty_function);
536 Map::SetPrototype(sloppy_function_map_writable_prototype_, empty_function);
535 537
536 // ES6 draft 03-17-2015, section 8.2.2 step 12 538 // ES6 draft 03-17-2015, section 8.2.2 step 12
537 AddRestrictedFunctionProperties(empty_function_map); 539 AddRestrictedFunctionProperties(empty_function_map);
538 540
539 return empty_function; 541 return empty_function;
540 } 542 }
541 543
542 544
543 void Genesis::SetStrictFunctionInstanceDescriptor(Handle<Map> map, 545 void Genesis::SetStrictFunctionInstanceDescriptor(Handle<Map> map,
544 FunctionMode function_mode) { 546 FunctionMode function_mode) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 } 647 }
646 return strict_poison_function; 648 return strict_poison_function;
647 } 649 }
648 650
649 651
650 Handle<Map> Genesis::CreateStrictFunctionMap( 652 Handle<Map> Genesis::CreateStrictFunctionMap(
651 FunctionMode function_mode, Handle<JSFunction> empty_function) { 653 FunctionMode function_mode, Handle<JSFunction> empty_function) {
652 Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); 654 Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize);
653 SetStrictFunctionInstanceDescriptor(map, function_mode); 655 SetStrictFunctionInstanceDescriptor(map, function_mode);
654 map->set_function_with_prototype(IsFunctionModeWithPrototype(function_mode)); 656 map->set_function_with_prototype(IsFunctionModeWithPrototype(function_mode));
655 map->SetPrototype(empty_function); 657 Map::SetPrototype(map, empty_function);
656 return map; 658 return map;
657 } 659 }
658 660
659 661
660 Handle<Map> Genesis::CreateStrongFunctionMap( 662 Handle<Map> Genesis::CreateStrongFunctionMap(
661 Handle<JSFunction> empty_function, bool is_constructor) { 663 Handle<JSFunction> empty_function, bool is_constructor) {
662 Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); 664 Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize);
663 SetStrongFunctionInstanceDescriptor(map); 665 SetStrongFunctionInstanceDescriptor(map);
664 map->set_function_with_prototype(is_constructor); 666 map->set_function_with_prototype(is_constructor);
665 map->SetPrototype(empty_function); 667 Map::SetPrototype(map, empty_function);
666 map->set_is_extensible(is_constructor); 668 map->set_is_extensible(is_constructor);
667 // TODO(rossberg): mark strong 669 // TODO(rossberg): mark strong
668 return map; 670 return map;
669 } 671 }
670 672
671 673
672 void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) { 674 void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) {
673 // Allocate map for the prototype-less strict mode instances. 675 // Allocate map for the prototype-less strict mode instances.
674 Handle<Map> strict_function_without_prototype_map = 676 Handle<Map> strict_function_without_prototype_map =
675 CreateStrictFunctionMap(FUNCTION_WITHOUT_PROTOTYPE, empty); 677 CreateStrictFunctionMap(FUNCTION_WITHOUT_PROTOTYPE, empty);
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 proto->InObjectPropertyAtPut(JSRegExp::kGlobalFieldIndex, 1108 proto->InObjectPropertyAtPut(JSRegExp::kGlobalFieldIndex,
1107 heap->false_value()); 1109 heap->false_value());
1108 proto->InObjectPropertyAtPut(JSRegExp::kIgnoreCaseFieldIndex, 1110 proto->InObjectPropertyAtPut(JSRegExp::kIgnoreCaseFieldIndex,
1109 heap->false_value()); 1111 heap->false_value());
1110 proto->InObjectPropertyAtPut(JSRegExp::kMultilineFieldIndex, 1112 proto->InObjectPropertyAtPut(JSRegExp::kMultilineFieldIndex,
1111 heap->false_value()); 1113 heap->false_value());
1112 proto->InObjectPropertyAtPut(JSRegExp::kLastIndexFieldIndex, 1114 proto->InObjectPropertyAtPut(JSRegExp::kLastIndexFieldIndex,
1113 Smi::FromInt(0), 1115 Smi::FromInt(0),
1114 SKIP_WRITE_BARRIER); // It's a Smi. 1116 SKIP_WRITE_BARRIER); // It's a Smi.
1115 proto_map->set_is_prototype_map(true); 1117 proto_map->set_is_prototype_map(true);
1116 initial_map->SetPrototype(proto); 1118 Map::SetPrototype(initial_map, proto);
1117 factory->SetRegExpIrregexpData(Handle<JSRegExp>::cast(proto), 1119 factory->SetRegExpIrregexpData(Handle<JSRegExp>::cast(proto),
1118 JSRegExp::IRREGEXP, factory->empty_string(), 1120 JSRegExp::IRREGEXP, factory->empty_string(),
1119 JSRegExp::Flags(0), 0); 1121 JSRegExp::Flags(0), 0);
1120 } 1122 }
1121 1123
1122 { // -- J S O N 1124 { // -- J S O N
1123 Handle<String> name = factory->InternalizeUtf8String("JSON"); 1125 Handle<String> name = factory->InternalizeUtf8String("JSON");
1124 Handle<JSFunction> cons = factory->NewFunction(name); 1126 Handle<JSFunction> cons = factory->NewFunction(name);
1125 JSFunction::SetInstancePrototype(cons, 1127 JSFunction::SetInstancePrototype(cons,
1126 Handle<Object>(native_context()->initial_object_prototype(), isolate)); 1128 Handle<Object>(native_context()->initial_object_prototype(), isolate));
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1295 { // caller 1297 { // caller
1296 AccessorConstantDescriptor d(factory->caller_string(), caller, 1298 AccessorConstantDescriptor d(factory->caller_string(), caller,
1297 attributes); 1299 attributes);
1298 map->AppendDescriptor(&d); 1300 map->AppendDescriptor(&d);
1299 } 1301 }
1300 // @@iterator method is added later. 1302 // @@iterator method is added later.
1301 1303
1302 map->set_function_with_prototype(true); 1304 map->set_function_with_prototype(true);
1303 DCHECK_EQ(native_context()->object_function()->prototype(), 1305 DCHECK_EQ(native_context()->object_function()->prototype(),
1304 *isolate->initial_object_prototype()); 1306 *isolate->initial_object_prototype());
1305 map->SetPrototype(isolate->initial_object_prototype()); 1307 Map::SetPrototype(map, isolate->initial_object_prototype());
1306 map->set_pre_allocated_property_fields(1); 1308 map->set_pre_allocated_property_fields(1);
1307 map->set_inobject_properties(1); 1309 map->set_inobject_properties(1);
1308 1310
1309 // Copy constructor from the sloppy arguments boilerplate. 1311 // Copy constructor from the sloppy arguments boilerplate.
1310 map->SetConstructor( 1312 map->SetConstructor(
1311 native_context()->sloppy_arguments_map()->GetConstructor()); 1313 native_context()->sloppy_arguments_map()->GetConstructor());
1312 1314
1313 native_context()->set_strict_arguments_map(*map); 1315 native_context()->set_strict_arguments_map(*map);
1314 1316
1315 DCHECK(map->inobject_properties() > Heap::kArgumentsLengthIndex); 1317 DCHECK(map->inobject_properties() > Heap::kArgumentsLengthIndex);
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
2079 InstallFunction(builtins, "GeneratorFunction", JS_FUNCTION_TYPE, 2081 InstallFunction(builtins, "GeneratorFunction", JS_FUNCTION_TYPE,
2080 JSFunction::kSize, generator_function_prototype, 2082 JSFunction::kSize, generator_function_prototype,
2081 Builtins::kIllegal, kUseStrictFunctionMap); 2083 Builtins::kIllegal, kUseStrictFunctionMap);
2082 2084
2083 // Create maps for generator functions and their prototypes. Store those 2085 // Create maps for generator functions and their prototypes. Store those
2084 // maps in the native context. Generator functions do not have writable 2086 // maps in the native context. Generator functions do not have writable
2085 // prototypes, nor do they have "caller" or "arguments" accessors. 2087 // prototypes, nor do they have "caller" or "arguments" accessors.
2086 Handle<Map> strict_function_map(native_context()->strict_function_map()); 2088 Handle<Map> strict_function_map(native_context()->strict_function_map());
2087 Handle<Map> sloppy_generator_function_map = 2089 Handle<Map> sloppy_generator_function_map =
2088 Map::Copy(strict_function_map, "SloppyGeneratorFunction"); 2090 Map::Copy(strict_function_map, "SloppyGeneratorFunction");
2089 sloppy_generator_function_map->SetPrototype(generator_function_prototype); 2091 Map::SetPrototype(sloppy_generator_function_map,
2092 generator_function_prototype);
2090 native_context()->set_sloppy_generator_function_map( 2093 native_context()->set_sloppy_generator_function_map(
2091 *sloppy_generator_function_map); 2094 *sloppy_generator_function_map);
2092 2095
2093 Handle<Map> strict_generator_function_map = 2096 Handle<Map> strict_generator_function_map =
2094 Map::Copy(strict_function_map, "StrictGeneratorFunction"); 2097 Map::Copy(strict_function_map, "StrictGeneratorFunction");
2095 strict_generator_function_map->SetPrototype(generator_function_prototype); 2098 Map::SetPrototype(strict_generator_function_map,
2099 generator_function_prototype);
2096 native_context()->set_strict_generator_function_map( 2100 native_context()->set_strict_generator_function_map(
2097 *strict_generator_function_map); 2101 *strict_generator_function_map);
2098 2102
2099 Handle<Map> strong_function_map(native_context()->strong_function_map()); 2103 Handle<Map> strong_function_map(native_context()->strong_function_map());
2100 Handle<Map> strong_generator_function_map = 2104 Handle<Map> strong_generator_function_map =
2101 Map::Copy(strong_function_map, "StrongGeneratorFunction"); 2105 Map::Copy(strong_function_map, "StrongGeneratorFunction");
2102 strong_generator_function_map->SetPrototype(generator_function_prototype); 2106 Map::SetPrototype(strong_generator_function_map,
2107 generator_function_prototype);
2103 native_context()->set_strong_generator_function_map( 2108 native_context()->set_strong_generator_function_map(
2104 *strong_generator_function_map); 2109 *strong_generator_function_map);
2105 2110
2106 Handle<JSFunction> object_function(native_context()->object_function()); 2111 Handle<JSFunction> object_function(native_context()->object_function());
2107 Handle<Map> generator_object_prototype_map = Map::Create(isolate(), 0); 2112 Handle<Map> generator_object_prototype_map = Map::Create(isolate(), 0);
2108 generator_object_prototype_map->SetPrototype(generator_object_prototype); 2113 Map::SetPrototype(generator_object_prototype_map,
2114 generator_object_prototype);
2109 native_context()->set_generator_object_prototype_map( 2115 native_context()->set_generator_object_prototype_map(
2110 *generator_object_prototype_map); 2116 *generator_object_prototype_map);
2111 } 2117 }
2112 2118
2113 if (FLAG_disable_native_files) { 2119 if (FLAG_disable_native_files) {
2114 PrintF("Warning: Running without installed natives!\n"); 2120 PrintF("Warning: Running without installed natives!\n");
2115 return true; 2121 return true;
2116 } 2122 }
2117 2123
2118 // Install public symbols. 2124 // Install public symbols.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
2200 Handle<JSObject> array_prototype( 2206 Handle<JSObject> array_prototype(
2201 JSObject::cast(array_constructor->instance_prototype())); 2207 JSObject::cast(array_constructor->instance_prototype()));
2202 2208
2203 // Add initial map. 2209 // Add initial map.
2204 Handle<Map> initial_map = 2210 Handle<Map> initial_map =
2205 factory()->NewMap(JS_ARRAY_TYPE, JSRegExpResult::kSize); 2211 factory()->NewMap(JS_ARRAY_TYPE, JSRegExpResult::kSize);
2206 initial_map->SetConstructor(*array_constructor); 2212 initial_map->SetConstructor(*array_constructor);
2207 2213
2208 // Set prototype on map. 2214 // Set prototype on map.
2209 initial_map->set_non_instance_prototype(false); 2215 initial_map->set_non_instance_prototype(false);
2210 initial_map->SetPrototype(array_prototype); 2216 Map::SetPrototype(initial_map, array_prototype);
2211 2217
2212 // Update map with length accessor from Array and add "index" and "input". 2218 // Update map with length accessor from Array and add "index" and "input".
2213 Map::EnsureDescriptorSlack(initial_map, 3); 2219 Map::EnsureDescriptorSlack(initial_map, 3);
2214 2220
2215 { 2221 {
2216 JSFunction* array_function = native_context()->array_function(); 2222 JSFunction* array_function = native_context()->array_function();
2217 Handle<DescriptorArray> array_descriptors( 2223 Handle<DescriptorArray> array_descriptors(
2218 array_function->initial_map()->instance_descriptors()); 2224 array_function->initial_map()->instance_descriptors());
2219 Handle<String> length = factory()->length_string(); 2225 Handle<String> length = factory()->length_string();
2220 int old = array_descriptors->SearchWithCache( 2226 int old = array_descriptors->SearchWithCache(
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after
2942 return from + sizeof(NestingCounterType); 2948 return from + sizeof(NestingCounterType);
2943 } 2949 }
2944 2950
2945 2951
2946 // Called when the top-level V8 mutex is destroyed. 2952 // Called when the top-level V8 mutex is destroyed.
2947 void Bootstrapper::FreeThreadResources() { 2953 void Bootstrapper::FreeThreadResources() {
2948 DCHECK(!IsActive()); 2954 DCHECK(!IsActive());
2949 } 2955 }
2950 2956
2951 } } // namespace v8::internal 2957 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698