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

Side by Side Diff: src/bootstrapper.cc

Issue 450303003: Tag all prototypes as proto, except those set using __proto__ (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Remove is_shared from Map Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « src/apinatives.js ('k') | 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/code-stubs.h" 8 #include "src/code-stubs.h"
9 #include "src/extensions/externalize-string-extension.h" 9 #include "src/extensions/externalize-string-extension.h"
10 #include "src/extensions/free-buffer-extension.h" 10 #include "src/extensions/free-buffer-extension.h"
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 CreateFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE); 473 CreateFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE);
474 474
475 Factory* factory = isolate->factory(); 475 Factory* factory = isolate->factory();
476 476
477 Handle<String> object_name = factory->Object_string(); 477 Handle<String> object_name = factory->Object_string();
478 478
479 { // --- O b j e c t --- 479 { // --- O b j e c t ---
480 Handle<JSFunction> object_fun = factory->NewFunction(object_name); 480 Handle<JSFunction> object_fun = factory->NewFunction(object_name);
481 Handle<Map> object_function_map = 481 Handle<Map> object_function_map =
482 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 482 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
483 JSFunction::SetInitialMap(object_fun, object_function_map); 483 JSFunction::SetInitialMap(object_fun, object_function_map,
484 isolate->factory()->null_value());
484 object_function_map->set_unused_property_fields( 485 object_function_map->set_unused_property_fields(
485 JSObject::kInitialGlobalObjectUnusedPropertiesCount); 486 JSObject::kInitialGlobalObjectUnusedPropertiesCount);
486 487
487 native_context()->set_object_function(*object_fun); 488 native_context()->set_object_function(*object_fun);
488 489
489 // Allocate a new prototype for the object function. 490 // Allocate a new prototype for the object function.
490 Handle<JSObject> prototype = factory->NewJSObject( 491 Handle<JSObject> prototype = factory->NewJSObject(
491 isolate->object_function(), 492 isolate->object_function(),
492 TENURED); 493 TENURED);
494 Handle<Map> map = Map::Copy(handle(prototype->map()));
495 map->set_is_prototype_map(true);
496 prototype->set_map(*map);
493 497
494 native_context()->set_initial_object_prototype(*prototype); 498 native_context()->set_initial_object_prototype(*prototype);
495 // For bootstrapping set the array prototype to be the same as the object 499 // For bootstrapping set the array prototype to be the same as the object
496 // prototype, otherwise the missing initial_array_prototype will cause 500 // prototype, otherwise the missing initial_array_prototype will cause
497 // assertions during startup. 501 // assertions during startup.
498 native_context()->set_initial_array_prototype(*prototype); 502 native_context()->set_initial_array_prototype(*prototype);
499 Accessors::FunctionSetPrototype(object_fun, prototype); 503 Accessors::FunctionSetPrototype(object_fun, prototype);
500 } 504 }
501 505
502 // Allocate the empty function as the prototype for function ECMAScript 506 // Allocate the empty function as the prototype for function ECMAScript
503 // 262 15.3.4. 507 // 262 15.3.4.
504 Handle<String> empty_string = 508 Handle<String> empty_string =
505 factory->InternalizeOneByteString(STATIC_ASCII_VECTOR("Empty")); 509 factory->InternalizeOneByteString(STATIC_ASCII_VECTOR("Empty"));
506 Handle<Code> code(isolate->builtins()->builtin(Builtins::kEmptyFunction)); 510 Handle<Code> code(isolate->builtins()->builtin(Builtins::kEmptyFunction));
507 Handle<JSFunction> empty_function = factory->NewFunctionWithoutPrototype( 511 Handle<JSFunction> empty_function = factory->NewFunctionWithoutPrototype(
508 empty_string, code); 512 empty_string, code);
509 513
514 // Allocate the function map first and then patch the prototype later
515 Handle<Map> empty_function_map =
516 CreateFunctionMap(FUNCTION_WITHOUT_PROTOTYPE);
517 DCHECK(!empty_function_map->is_dictionary_map());
518 empty_function_map->set_prototype(
519 native_context()->object_function()->prototype());
520 empty_function_map->set_is_prototype_map(true);
521 empty_function->set_map(*empty_function_map);
522
510 // --- E m p t y --- 523 // --- E m p t y ---
511 Handle<String> source = factory->NewStringFromStaticAscii("() {}"); 524 Handle<String> source = factory->NewStringFromStaticAscii("() {}");
512 Handle<Script> script = factory->NewScript(source); 525 Handle<Script> script = factory->NewScript(source);
513 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); 526 script->set_type(Smi::FromInt(Script::TYPE_NATIVE));
514 empty_function->shared()->set_script(*script); 527 empty_function->shared()->set_script(*script);
515 empty_function->shared()->set_start_position(0); 528 empty_function->shared()->set_start_position(0);
516 empty_function->shared()->set_end_position(source->length()); 529 empty_function->shared()->set_end_position(source->length());
517 empty_function->shared()->DontAdaptArguments(); 530 empty_function->shared()->DontAdaptArguments();
518 531
519 // Set prototypes for the function maps. 532 // Set prototypes for the function maps.
520 native_context()->sloppy_function_map()->set_prototype(*empty_function); 533 native_context()->sloppy_function_map()->set_prototype(*empty_function);
521 native_context()->sloppy_function_without_prototype_map()-> 534 native_context()->sloppy_function_without_prototype_map()->
522 set_prototype(*empty_function); 535 set_prototype(*empty_function);
523 sloppy_function_map_writable_prototype_->set_prototype(*empty_function); 536 sloppy_function_map_writable_prototype_->set_prototype(*empty_function);
524
525 // Allocate the function map first and then patch the prototype later
526 Handle<Map> empty_function_map =
527 CreateFunctionMap(FUNCTION_WITHOUT_PROTOTYPE);
528 empty_function_map->set_prototype(
529 native_context()->object_function()->prototype());
530 empty_function->set_map(*empty_function_map);
531 return empty_function; 537 return empty_function;
532 } 538 }
533 539
534 540
535 void Genesis::SetStrictFunctionInstanceDescriptor( 541 void Genesis::SetStrictFunctionInstanceDescriptor(
536 Handle<Map> map, FunctionMode function_mode) { 542 Handle<Map> map, FunctionMode function_mode) {
537 int size = IsFunctionModeWithPrototype(function_mode) ? 5 : 4; 543 int size = IsFunctionModeWithPrototype(function_mode) ? 5 : 4;
538 Map::EnsureDescriptorSlack(map, size); 544 Map::EnsureDescriptorSlack(map, size);
539 545
540 Handle<AccessorPair> arguments(factory()->NewAccessorPair()); 546 Handle<AccessorPair> arguments(factory()->NewAccessorPair());
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 heap->query_colon_string()); 1081 heap->query_colon_string());
1076 proto->InObjectPropertyAtPut(JSRegExp::kGlobalFieldIndex, 1082 proto->InObjectPropertyAtPut(JSRegExp::kGlobalFieldIndex,
1077 heap->false_value()); 1083 heap->false_value());
1078 proto->InObjectPropertyAtPut(JSRegExp::kIgnoreCaseFieldIndex, 1084 proto->InObjectPropertyAtPut(JSRegExp::kIgnoreCaseFieldIndex,
1079 heap->false_value()); 1085 heap->false_value());
1080 proto->InObjectPropertyAtPut(JSRegExp::kMultilineFieldIndex, 1086 proto->InObjectPropertyAtPut(JSRegExp::kMultilineFieldIndex,
1081 heap->false_value()); 1087 heap->false_value());
1082 proto->InObjectPropertyAtPut(JSRegExp::kLastIndexFieldIndex, 1088 proto->InObjectPropertyAtPut(JSRegExp::kLastIndexFieldIndex,
1083 Smi::FromInt(0), 1089 Smi::FromInt(0),
1084 SKIP_WRITE_BARRIER); // It's a Smi. 1090 SKIP_WRITE_BARRIER); // It's a Smi.
1091 proto_map->set_is_prototype_map(true);
1085 initial_map->set_prototype(*proto); 1092 initial_map->set_prototype(*proto);
1086 factory->SetRegExpIrregexpData(Handle<JSRegExp>::cast(proto), 1093 factory->SetRegExpIrregexpData(Handle<JSRegExp>::cast(proto),
1087 JSRegExp::IRREGEXP, factory->empty_string(), 1094 JSRegExp::IRREGEXP, factory->empty_string(),
1088 JSRegExp::Flags(0), 0); 1095 JSRegExp::Flags(0), 0);
1089 } 1096 }
1090 1097
1091 { // -- J S O N 1098 { // -- J S O N
1092 Handle<String> name = factory->InternalizeUtf8String("JSON"); 1099 Handle<String> name = factory->InternalizeUtf8String("JSON");
1093 Handle<JSFunction> cons = factory->NewFunction(name); 1100 Handle<JSFunction> cons = factory->NewFunction(name);
1094 JSFunction::SetInstancePrototype(cons, 1101 JSFunction::SetInstancePrototype(cons,
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 DONT_ENUM, Representation::Tagged()); 1204 DONT_ENUM, Representation::Tagged());
1198 map->AppendDescriptor(&d); 1205 map->AppendDescriptor(&d);
1199 } 1206 }
1200 { // callee 1207 { // callee
1201 FieldDescriptor d(factory->callee_string(), Heap::kArgumentsCalleeIndex, 1208 FieldDescriptor d(factory->callee_string(), Heap::kArgumentsCalleeIndex,
1202 DONT_ENUM, Representation::Tagged()); 1209 DONT_ENUM, Representation::Tagged());
1203 map->AppendDescriptor(&d); 1210 map->AppendDescriptor(&d);
1204 } 1211 }
1205 1212
1206 map->set_function_with_prototype(true); 1213 map->set_function_with_prototype(true);
1207 map->set_prototype(native_context()->object_function()->prototype());
1208 map->set_pre_allocated_property_fields(2); 1214 map->set_pre_allocated_property_fields(2);
1209 map->set_inobject_properties(2); 1215 map->set_inobject_properties(2);
1210 native_context()->set_sloppy_arguments_map(*map); 1216 native_context()->set_sloppy_arguments_map(*map);
1211 1217
1212 DCHECK(!function->has_initial_map()); 1218 DCHECK(!function->has_initial_map());
1213 JSFunction::SetInitialMap(function, map); 1219 JSFunction::SetInitialMap(function, map,
1220 isolate->initial_object_prototype());
1214 1221
1215 DCHECK(map->inobject_properties() > Heap::kArgumentsCalleeIndex); 1222 DCHECK(map->inobject_properties() > Heap::kArgumentsCalleeIndex);
1216 DCHECK(map->inobject_properties() > Heap::kArgumentsLengthIndex); 1223 DCHECK(map->inobject_properties() > Heap::kArgumentsLengthIndex);
1217 DCHECK(!map->is_dictionary_map()); 1224 DCHECK(!map->is_dictionary_map());
1218 DCHECK(IsFastObjectElementsKind(map->elements_kind())); 1225 DCHECK(IsFastObjectElementsKind(map->elements_kind()));
1219 } 1226 }
1220 1227
1221 { // --- aliased arguments map 1228 { // --- aliased arguments map
1222 Handle<Map> map = Map::Copy(isolate->sloppy_arguments_map()); 1229 Handle<Map> map = Map::Copy(isolate->sloppy_arguments_map());
1223 map->set_elements_kind(SLOPPY_ARGUMENTS_ELEMENTS); 1230 map->set_elements_kind(SLOPPY_ARGUMENTS_ELEMENTS);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 Handle<Map>* external_map) { 1334 Handle<Map>* external_map) {
1328 Handle<JSObject> global = Handle<JSObject>(native_context()->global_object()); 1335 Handle<JSObject> global = Handle<JSObject>(native_context()->global_object());
1329 Handle<JSFunction> result = InstallFunction( 1336 Handle<JSFunction> result = InstallFunction(
1330 global, name, JS_TYPED_ARRAY_TYPE, JSTypedArray::kSize, 1337 global, name, JS_TYPED_ARRAY_TYPE, JSTypedArray::kSize,
1331 isolate()->initial_object_prototype(), Builtins::kIllegal); 1338 isolate()->initial_object_prototype(), Builtins::kIllegal);
1332 1339
1333 Handle<Map> initial_map = isolate()->factory()->NewMap( 1340 Handle<Map> initial_map = isolate()->factory()->NewMap(
1334 JS_TYPED_ARRAY_TYPE, 1341 JS_TYPED_ARRAY_TYPE,
1335 JSTypedArray::kSizeWithInternalFields, 1342 JSTypedArray::kSizeWithInternalFields,
1336 elements_kind); 1343 elements_kind);
1337 JSFunction::SetInitialMap(result, initial_map); 1344 JSFunction::SetInitialMap(result, initial_map,
1345 handle(initial_map->prototype(), isolate()));
1338 *fun = result; 1346 *fun = result;
1339 1347
1340 ElementsKind external_kind = GetNextTransitionElementsKind(elements_kind); 1348 ElementsKind external_kind = GetNextTransitionElementsKind(elements_kind);
1341 *external_map = Map::AsElementsKind(initial_map, external_kind); 1349 *external_map = Map::AsElementsKind(initial_map, external_kind);
1342 } 1350 }
1343 1351
1344 1352
1345 void Genesis::InitializeExperimentalGlobal() { 1353 void Genesis::InitializeExperimentalGlobal() {
1346 // TODO(mstarzinger): Move this into Genesis::InitializeGlobal once we no 1354 // TODO(mstarzinger): Move this into Genesis::InitializeGlobal once we no
1347 // longer need to live behind flags, so functions get added to the snapshot. 1355 // longer need to live behind flags, so functions get added to the snapshot.
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1645 prototype, Builtins::kInternalArrayCode); 1653 prototype, Builtins::kInternalArrayCode);
1646 1654
1647 InternalArrayConstructorStub internal_array_constructor_stub(isolate()); 1655 InternalArrayConstructorStub internal_array_constructor_stub(isolate());
1648 Handle<Code> code = internal_array_constructor_stub.GetCode(); 1656 Handle<Code> code = internal_array_constructor_stub.GetCode();
1649 array_function->shared()->set_construct_stub(*code); 1657 array_function->shared()->set_construct_stub(*code);
1650 array_function->shared()->DontAdaptArguments(); 1658 array_function->shared()->DontAdaptArguments();
1651 1659
1652 Handle<Map> original_map(array_function->initial_map()); 1660 Handle<Map> original_map(array_function->initial_map());
1653 Handle<Map> initial_map = Map::Copy(original_map); 1661 Handle<Map> initial_map = Map::Copy(original_map);
1654 initial_map->set_elements_kind(elements_kind); 1662 initial_map->set_elements_kind(elements_kind);
1655 JSFunction::SetInitialMap(array_function, initial_map); 1663 JSFunction::SetInitialMap(array_function, initial_map, prototype);
1656 1664
1657 // Make "length" magic on instances. 1665 // Make "length" magic on instances.
1658 Map::EnsureDescriptorSlack(initial_map, 1); 1666 Map::EnsureDescriptorSlack(initial_map, 1);
1659 1667
1660 PropertyAttributes attribs = static_cast<PropertyAttributes>( 1668 PropertyAttributes attribs = static_cast<PropertyAttributes>(
1661 DONT_ENUM | DONT_DELETE); 1669 DONT_ENUM | DONT_DELETE);
1662 1670
1663 Handle<AccessorInfo> array_length = 1671 Handle<AccessorInfo> array_length =
1664 Accessors::ArrayLengthInfo(isolate(), attribs); 1672 Accessors::ArrayLengthInfo(isolate(), attribs);
1665 { // Add length. 1673 { // Add length.
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after
2689 return from + sizeof(NestingCounterType); 2697 return from + sizeof(NestingCounterType);
2690 } 2698 }
2691 2699
2692 2700
2693 // Called when the top-level V8 mutex is destroyed. 2701 // Called when the top-level V8 mutex is destroyed.
2694 void Bootstrapper::FreeThreadResources() { 2702 void Bootstrapper::FreeThreadResources() {
2695 DCHECK(!IsActive()); 2703 DCHECK(!IsActive());
2696 } 2704 }
2697 2705
2698 } } // namespace v8::internal 2706 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/apinatives.js ('k') | src/factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698