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

Side by Side Diff: src/factory.cc

Issue 28783002: Handlify PropertyCell::SetValueInferType and friends. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments by Andreas Rossberg. Created 7 years, 2 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/factory.h ('k') | src/heap.h » ('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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 531
532 Handle<Cell> Factory::NewCell(Handle<Object> value) { 532 Handle<Cell> Factory::NewCell(Handle<Object> value) {
533 AllowDeferredHandleDereference convert_to_cell; 533 AllowDeferredHandleDereference convert_to_cell;
534 CALL_HEAP_FUNCTION( 534 CALL_HEAP_FUNCTION(
535 isolate(), 535 isolate(),
536 isolate()->heap()->AllocateCell(*value), 536 isolate()->heap()->AllocateCell(*value),
537 Cell); 537 Cell);
538 } 538 }
539 539
540 540
541 Handle<PropertyCell> Factory::NewPropertyCellWithHole() {
542 CALL_HEAP_FUNCTION(
543 isolate(),
544 isolate()->heap()->AllocatePropertyCell(),
545 PropertyCell);
546 }
547
548
541 Handle<PropertyCell> Factory::NewPropertyCell(Handle<Object> value) { 549 Handle<PropertyCell> Factory::NewPropertyCell(Handle<Object> value) {
542 AllowDeferredHandleDereference convert_to_cell; 550 AllowDeferredHandleDereference convert_to_cell;
543 CALL_HEAP_FUNCTION( 551 Handle<PropertyCell> cell = NewPropertyCellWithHole();
544 isolate(), 552 PropertyCell::SetValueInferType(cell, value);
545 isolate()->heap()->AllocatePropertyCell(*value), 553 return cell;
546 PropertyCell);
547 } 554 }
548 555
549 556
550 Handle<AllocationSite> Factory::NewAllocationSite() { 557 Handle<AllocationSite> Factory::NewAllocationSite() {
551 CALL_HEAP_FUNCTION( 558 CALL_HEAP_FUNCTION(
552 isolate(), 559 isolate(),
553 isolate()->heap()->AllocateAllocationSite(), 560 isolate()->heap()->AllocateAllocationSite(),
554 AllocationSite); 561 AllocationSite);
555 } 562 }
556 563
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 1052
1046 1053
1047 Handle<JSModule> Factory::NewJSModule(Handle<Context> context, 1054 Handle<JSModule> Factory::NewJSModule(Handle<Context> context,
1048 Handle<ScopeInfo> scope_info) { 1055 Handle<ScopeInfo> scope_info) {
1049 CALL_HEAP_FUNCTION( 1056 CALL_HEAP_FUNCTION(
1050 isolate(), 1057 isolate(),
1051 isolate()->heap()->AllocateJSModule(*context, *scope_info), JSModule); 1058 isolate()->heap()->AllocateJSModule(*context, *scope_info), JSModule);
1052 } 1059 }
1053 1060
1054 1061
1055 Handle<GlobalObject> Factory::NewGlobalObject( 1062 // TODO(mstarzinger): Temporary wrapper until handlified.
1056 Handle<JSFunction> constructor) { 1063 static Handle<NameDictionary> NameDictionaryAdd(Handle<NameDictionary> dict,
1057 CALL_HEAP_FUNCTION(isolate(), 1064 Handle<Name> name,
1058 isolate()->heap()->AllocateGlobalObject(*constructor), 1065 Handle<Object> value,
1066 PropertyDetails details) {
1067 CALL_HEAP_FUNCTION(dict->GetIsolate(),
1068 dict->Add(*name, *value, details),
1069 NameDictionary);
1070 }
1071
1072
1073 static Handle<GlobalObject> NewGlobalObjectFromMap(Isolate* isolate,
1074 Handle<Map> map) {
1075 CALL_HEAP_FUNCTION(isolate,
1076 isolate->heap()->Allocate(*map, OLD_POINTER_SPACE),
1059 GlobalObject); 1077 GlobalObject);
1060 } 1078 }
1061 1079
1062 1080
1081 Handle<GlobalObject> Factory::NewGlobalObject(Handle<JSFunction> constructor) {
1082 ASSERT(constructor->has_initial_map());
1083 Handle<Map> map(constructor->initial_map());
1084 ASSERT(map->is_dictionary_map());
1085
1086 // Make sure no field properties are described in the initial map.
1087 // This guarantees us that normalizing the properties does not
1088 // require us to change property values to PropertyCells.
1089 ASSERT(map->NextFreePropertyIndex() == 0);
1090
1091 // Make sure we don't have a ton of pre-allocated slots in the
1092 // global objects. They will be unused once we normalize the object.
1093 ASSERT(map->unused_property_fields() == 0);
1094 ASSERT(map->inobject_properties() == 0);
1095
1096 // Initial size of the backing store to avoid resize of the storage during
1097 // bootstrapping. The size differs between the JS global object ad the
1098 // builtins object.
1099 int initial_size = map->instance_type() == JS_GLOBAL_OBJECT_TYPE ? 64 : 512;
1100
1101 // Allocate a dictionary object for backing storage.
1102 int at_least_space_for = map->NumberOfOwnDescriptors() * 2 + initial_size;
1103 Handle<NameDictionary> dictionary = NewNameDictionary(at_least_space_for);
1104
1105 // The global object might be created from an object template with accessors.
1106 // Fill these accessors into the dictionary.
1107 Handle<DescriptorArray> descs(map->instance_descriptors());
1108 for (int i = 0; i < map->NumberOfOwnDescriptors(); i++) {
1109 PropertyDetails details = descs->GetDetails(i);
1110 ASSERT(details.type() == CALLBACKS); // Only accessors are expected.
1111 PropertyDetails d = PropertyDetails(details.attributes(), CALLBACKS, i + 1);
1112 Handle<Name> name(descs->GetKey(i));
1113 Handle<Object> value(descs->GetCallbacksObject(i), isolate());
1114 Handle<PropertyCell> cell = NewPropertyCell(value);
1115 NameDictionaryAdd(dictionary, name, cell, d);
1116 }
1117
1118 // Allocate the global object and initialize it with the backing store.
1119 Handle<GlobalObject> global = NewGlobalObjectFromMap(isolate(), map);
1120 isolate()->heap()->InitializeJSObjectFromMap(*global, *dictionary, *map);
1121
1122 // Create a new map for the global object.
1123 Handle<Map> new_map = Map::CopyDropDescriptors(map);
1124 new_map->set_dictionary_map(true);
1125
1126 // Set up the global object as a normalized object.
1127 global->set_map(*new_map);
1128 global->set_properties(*dictionary);
1129
1130 // Make sure result is a global object with properties in dictionary.
1131 ASSERT(global->IsGlobalObject() && !global->HasFastProperties());
1132 return global;
1133 }
1134
1063 1135
1064 Handle<JSObject> Factory::NewJSObjectFromMap(Handle<Map> map, 1136 Handle<JSObject> Factory::NewJSObjectFromMap(Handle<Map> map,
1065 PretenureFlag pretenure, 1137 PretenureFlag pretenure,
1066 bool alloc_props) { 1138 bool alloc_props) {
1067 CALL_HEAP_FUNCTION( 1139 CALL_HEAP_FUNCTION(
1068 isolate(), 1140 isolate(),
1069 isolate()->heap()->AllocateJSObjectFromMap(*map, pretenure, alloc_props), 1141 isolate()->heap()->AllocateJSObjectFromMap(*map, pretenure, alloc_props),
1070 JSObject); 1142 JSObject);
1071 } 1143 }
1072 1144
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
1667 return Handle<Object>::null(); 1739 return Handle<Object>::null();
1668 } 1740 }
1669 1741
1670 1742
1671 Handle<Object> Factory::ToBoolean(bool value) { 1743 Handle<Object> Factory::ToBoolean(bool value) {
1672 return value ? true_value() : false_value(); 1744 return value ? true_value() : false_value();
1673 } 1745 }
1674 1746
1675 1747
1676 } } // namespace v8::internal 1748 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/factory.h ('k') | src/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698