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

Side by Side Diff: src/bootstrapper.cc

Issue 660095: Merge revision 3813 to 3930 from bleeding_edge to partial snapshots branch. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/partial_snapshots/
Patch Set: '' Created 10 years, 10 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/bootstrapper.h ('k') | src/builtins.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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 delete_these_arrays_on_tear_down->at(i) = NULL; 170 delete_these_arrays_on_tear_down->at(i) = NULL;
171 } 171 }
172 delete delete_these_arrays_on_tear_down; 172 delete delete_these_arrays_on_tear_down;
173 delete_these_arrays_on_tear_down = NULL; 173 delete_these_arrays_on_tear_down = NULL;
174 } 174 }
175 175
176 extensions_cache.Initialize(false); // Yes, symmetrical 176 extensions_cache.Initialize(false); // Yes, symmetrical
177 } 177 }
178 178
179 179
180 // Pending fixups are code positions that refer to builtin code
181 // objects that were not available at the time the code was generated.
182 // The pending list is processed whenever an environment has been
183 // created.
184 class PendingFixups : public AllStatic {
185 public:
186 static void Add(Code* code, MacroAssembler* masm);
187 static bool Process(Handle<JSBuiltinsObject> builtins);
188
189 static void Iterate(ObjectVisitor* v);
190
191 private:
192 static List<Object*> code_;
193 static List<const char*> name_;
194 static List<int> pc_;
195 static List<uint32_t> flags_;
196
197 static void Clear();
198 };
199
200
201 List<Object*> PendingFixups::code_(0);
202 List<const char*> PendingFixups::name_(0);
203 List<int> PendingFixups::pc_(0);
204 List<uint32_t> PendingFixups::flags_(0);
205
206
207 void PendingFixups::Add(Code* code, MacroAssembler* masm) {
208 // Note this code is not only called during bootstrapping.
209 List<MacroAssembler::Unresolved>* unresolved = masm->unresolved();
210 int n = unresolved->length();
211 for (int i = 0; i < n; i++) {
212 const char* name = unresolved->at(i).name;
213 code_.Add(code);
214 name_.Add(name);
215 pc_.Add(unresolved->at(i).pc);
216 flags_.Add(unresolved->at(i).flags);
217 LOG(StringEvent("unresolved", name));
218 }
219 }
220
221
222 bool PendingFixups::Process(Handle<JSBuiltinsObject> builtins) {
223 HandleScope scope;
224 // NOTE: Extra fixups may be added to the list during the iteration
225 // due to lazy compilation of functions during the processing. Do not
226 // cache the result of getting the length of the code list.
227 for (int i = 0; i < code_.length(); i++) {
228 const char* name = name_[i];
229 uint32_t flags = flags_[i];
230 Handle<String> symbol = Factory::LookupAsciiSymbol(name);
231 Object* o = builtins->GetProperty(*symbol);
232 #ifdef DEBUG
233 if (!o->IsJSFunction()) {
234 V8_Fatal(__FILE__, __LINE__, "Cannot resolve call to builtin %s", name);
235 }
236 #endif
237 Handle<SharedFunctionInfo> shared(JSFunction::cast(o)->shared());
238 // Make sure the number of parameters match the formal parameter count.
239 int argc = Bootstrapper::FixupFlagsArgumentsCount::decode(flags);
240 USE(argc);
241 ASSERT(shared->formal_parameter_count() == argc);
242 // Do lazy compilation if necessary and check for stack overflows.
243 if (!EnsureCompiled(shared, CLEAR_EXCEPTION)) {
244 Clear();
245 return false;
246 }
247 Code* code = Code::cast(code_[i]);
248 Address pc = code->instruction_start() + pc_[i];
249 RelocInfo target(pc, RelocInfo::CODE_TARGET, 0);
250 bool use_code_object = Bootstrapper::FixupFlagsUseCodeObject::decode(flags);
251 if (use_code_object) {
252 target.set_target_object(shared->code());
253 } else {
254 target.set_target_address(shared->code()->instruction_start());
255 }
256 LOG(StringEvent("resolved", name));
257 }
258 Clear();
259
260 // TODO(1240818): We should probably try to avoid doing this for all
261 // the V8 builtin JS files. It should only happen after running
262 // runtime.js - just like there shouldn't be any fixups left after
263 // that.
264 for (int i = 0; i < Builtins::NumberOfJavaScriptBuiltins(); i++) {
265 Builtins::JavaScript id = static_cast<Builtins::JavaScript>(i);
266 Handle<String> name = Factory::LookupAsciiSymbol(Builtins::GetName(id));
267 JSFunction* function = JSFunction::cast(builtins->GetProperty(*name));
268 builtins->set_javascript_builtin(id, function);
269 }
270
271 return true;
272 }
273
274
275 void PendingFixups::Clear() {
276 code_.Clear();
277 name_.Clear();
278 pc_.Clear();
279 flags_.Clear();
280 }
281
282
283 void PendingFixups::Iterate(ObjectVisitor* v) {
284 if (!code_.is_empty()) {
285 v->VisitPointers(&code_[0], &code_[0] + code_.length());
286 }
287 }
288
289
290 class Genesis BASE_EMBEDDED { 180 class Genesis BASE_EMBEDDED {
291 public: 181 public:
292 Genesis(Handle<Object> global_object, 182 Genesis(Handle<Object> global_object,
293 v8::Handle<v8::ObjectTemplate> global_template, 183 v8::Handle<v8::ObjectTemplate> global_template,
294 v8::ExtensionConfiguration* extensions); 184 v8::ExtensionConfiguration* extensions);
295 ~Genesis() { } 185 ~Genesis() { }
296 186
297 Handle<Context> result() { return result_; } 187 Handle<Context> result() { return result_; }
298 188
299 Genesis* previous() { return previous_; } 189 Genesis* previous() { return previous_; }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 // Used for creating a context from scratch. 224 // Used for creating a context from scratch.
335 void InstallNativeFunctions(); 225 void InstallNativeFunctions();
336 bool InstallNatives(); 226 bool InstallNatives();
337 // Used both for deserialized and from-scratch contexts to add the extensions 227 // Used both for deserialized and from-scratch contexts to add the extensions
338 // provided. 228 // provided.
339 static bool InstallExtensions(Handle<Context> global_context, 229 static bool InstallExtensions(Handle<Context> global_context,
340 v8::ExtensionConfiguration* extensions); 230 v8::ExtensionConfiguration* extensions);
341 static bool InstallExtension(const char* name); 231 static bool InstallExtension(const char* name);
342 static bool InstallExtension(v8::RegisteredExtension* current); 232 static bool InstallExtension(v8::RegisteredExtension* current);
343 static void InstallSpecialObjects(Handle<Context> global_context); 233 static void InstallSpecialObjects(Handle<Context> global_context);
234 bool InstallJSBuiltins(Handle<JSBuiltinsObject> builtins);
344 bool ConfigureApiObject(Handle<JSObject> object, 235 bool ConfigureApiObject(Handle<JSObject> object,
345 Handle<ObjectTemplateInfo> object_template); 236 Handle<ObjectTemplateInfo> object_template);
346 bool ConfigureGlobalObjects(v8::Handle<v8::ObjectTemplate> global_template); 237 bool ConfigureGlobalObjects(v8::Handle<v8::ObjectTemplate> global_template);
347 void TransferMapsToDeserializedGlobals( 238 void TransferMapsToDeserializedGlobals(
348 Handle<GlobalObject> inner_global_outside_snapshot, 239 Handle<GlobalObject> inner_global_outside_snapshot,
349 Handle<GlobalObject> inner_global_from_snapshot); 240 Handle<GlobalObject> inner_global_from_snapshot);
350 241
351 // Migrates all properties from the 'from' object to the 'to' 242 // Migrates all properties from the 'from' object to the 'to'
352 // object and overrides the prototype in 'to' with the one from 243 // object and overrides the prototype in 'to' with the one from
353 // 'from'. 244 // 'from'.
(...skipping 24 matching lines...) Expand all
378 Handle<Context> result_; 269 Handle<Context> result_;
379 Handle<JSFunction> empty_function_; 270 Handle<JSFunction> empty_function_;
380 BootstrapperActive active_; 271 BootstrapperActive active_;
381 friend class Bootstrapper; 272 friend class Bootstrapper;
382 }; 273 };
383 274
384 275
385 void Bootstrapper::Iterate(ObjectVisitor* v) { 276 void Bootstrapper::Iterate(ObjectVisitor* v) {
386 extensions_cache.Iterate(v); 277 extensions_cache.Iterate(v);
387 v->Synchronize("Extensions"); 278 v->Synchronize("Extensions");
388 PendingFixups::Iterate(v);
389 v->Synchronize("PendingFixups");
390 }
391
392
393 // While setting up the environment, we collect code positions that
394 // need to be patched before we can run any code in the environment.
395 void Bootstrapper::AddFixup(Code* code, MacroAssembler* masm) {
396 PendingFixups::Add(code, masm);
397 } 279 }
398 280
399 281
400 Handle<Context> Bootstrapper::CreateEnvironment( 282 Handle<Context> Bootstrapper::CreateEnvironment(
401 Handle<Object> global_object, 283 Handle<Object> global_object,
402 v8::Handle<v8::ObjectTemplate> global_template, 284 v8::Handle<v8::ObjectTemplate> global_template,
403 v8::ExtensionConfiguration* extensions) { 285 v8::ExtensionConfiguration* extensions) {
404 HandleScope scope; 286 HandleScope scope;
405 Handle<Context> env; 287 Handle<Context> env;
406 Genesis genesis(global_object, global_template, extensions); 288 Genesis genesis(global_object, global_template, extensions);
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 SetProperty(result, Factory::callee_symbol(), 740 SetProperty(result, Factory::callee_symbol(),
859 Factory::undefined_value(), 741 Factory::undefined_value(),
860 DONT_ENUM); 742 DONT_ENUM);
861 SetProperty(result, Factory::length_symbol(), 743 SetProperty(result, Factory::length_symbol(),
862 Factory::undefined_value(), 744 Factory::undefined_value(),
863 DONT_ENUM); 745 DONT_ENUM);
864 746
865 #ifdef DEBUG 747 #ifdef DEBUG
866 LookupResult lookup; 748 LookupResult lookup;
867 result->LocalLookup(Heap::callee_symbol(), &lookup); 749 result->LocalLookup(Heap::callee_symbol(), &lookup);
868 ASSERT(lookup.IsValid() && (lookup.type() == FIELD)); 750 ASSERT(lookup.IsProperty() && (lookup.type() == FIELD));
869 ASSERT(lookup.GetFieldIndex() == Heap::arguments_callee_index); 751 ASSERT(lookup.GetFieldIndex() == Heap::arguments_callee_index);
870 752
871 result->LocalLookup(Heap::length_symbol(), &lookup); 753 result->LocalLookup(Heap::length_symbol(), &lookup);
872 ASSERT(lookup.IsValid() && (lookup.type() == FIELD)); 754 ASSERT(lookup.IsProperty() && (lookup.type() == FIELD));
873 ASSERT(lookup.GetFieldIndex() == Heap::arguments_length_index); 755 ASSERT(lookup.GetFieldIndex() == Heap::arguments_length_index);
874 756
875 ASSERT(result->map()->inobject_properties() > Heap::arguments_callee_index); 757 ASSERT(result->map()->inobject_properties() > Heap::arguments_callee_index);
876 ASSERT(result->map()->inobject_properties() > Heap::arguments_length_index); 758 ASSERT(result->map()->inobject_properties() > Heap::arguments_length_index);
877 759
878 // Check the state of the object. 760 // Check the state of the object.
879 ASSERT(result->HasFastProperties()); 761 ASSERT(result->HasFastProperties());
880 ASSERT(result->HasFastElements()); 762 ASSERT(result->HasFastElements());
881 #endif 763 #endif
882 } 764 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 if (cache == NULL || !cache->Lookup(name, &boilerplate)) { 852 if (cache == NULL || !cache->Lookup(name, &boilerplate)) {
971 ASSERT(source->IsAsciiRepresentation()); 853 ASSERT(source->IsAsciiRepresentation());
972 Handle<String> script_name = Factory::NewStringFromUtf8(name); 854 Handle<String> script_name = Factory::NewStringFromUtf8(name);
973 boilerplate = Compiler::Compile( 855 boilerplate = Compiler::Compile(
974 source, 856 source,
975 script_name, 857 script_name,
976 0, 858 0,
977 0, 859 0,
978 extension, 860 extension,
979 NULL, 861 NULL,
862 Handle<String>::null(),
980 use_runtime_context ? NATIVES_CODE : NOT_NATIVES_CODE); 863 use_runtime_context ? NATIVES_CODE : NOT_NATIVES_CODE);
981 if (boilerplate.is_null()) return false; 864 if (boilerplate.is_null()) return false;
982 if (cache != NULL) cache->Add(name, boilerplate); 865 if (cache != NULL) cache->Add(name, boilerplate);
983 } 866 }
984 867
985 // Setup the function context. Conceptually, we should clone the 868 // Setup the function context. Conceptually, we should clone the
986 // function before overwriting the context but since we're in a 869 // function before overwriting the context but since we're in a
987 // single-threaded environment it is not strictly necessary. 870 // single-threaded environment it is not strictly necessary.
988 ASSERT(top_context->IsGlobalContext()); 871 ASSERT(top_context->IsGlobalContext());
989 Handle<Context> context = 872 Handle<Context> context =
990 Handle<Context>(use_runtime_context 873 Handle<Context>(use_runtime_context
991 ? Handle<Context>(top_context->runtime_context()) 874 ? Handle<Context>(top_context->runtime_context())
992 : top_context); 875 : top_context);
993 Handle<JSFunction> fun = 876 Handle<JSFunction> fun =
994 Factory::NewFunctionFromBoilerplate(boilerplate, context); 877 Factory::NewFunctionFromBoilerplate(boilerplate, context);
995 878
996 // Call function using either the runtime object or the global 879 // Call function using either the runtime object or the global
997 // object as the receiver. Provide no parameters. 880 // object as the receiver. Provide no parameters.
998 Handle<Object> receiver = 881 Handle<Object> receiver =
999 Handle<Object>(use_runtime_context 882 Handle<Object>(use_runtime_context
1000 ? top_context->builtins() 883 ? top_context->builtins()
1001 : top_context->global()); 884 : top_context->global());
1002 bool has_pending_exception; 885 bool has_pending_exception;
1003 Handle<Object> result = 886 Handle<Object> result =
1004 Execution::Call(fun, receiver, 0, NULL, &has_pending_exception); 887 Execution::Call(fun, receiver, 0, NULL, &has_pending_exception);
1005 if (has_pending_exception) return false; 888 if (has_pending_exception) return false;
1006 return PendingFixups::Process( 889 return true;
1007 Handle<JSBuiltinsObject>(top_context->builtins()));
1008 } 890 }
1009 891
1010 892
1011 #define INSTALL_NATIVE(Type, name, var) \ 893 #define INSTALL_NATIVE(Type, name, var) \
1012 Handle<String> var##_name = Factory::LookupAsciiSymbol(name); \ 894 Handle<String> var##_name = Factory::LookupAsciiSymbol(name); \
1013 global_context()->set_##var(Type::cast(global_context()-> \ 895 global_context()->set_##var(Type::cast(global_context()-> \
1014 builtins()-> \ 896 builtins()-> \
1015 GetProperty(*var##_name))); 897 GetProperty(*var##_name)));
1016 898
1017 void Genesis::InstallNativeFunctions() { 899 void Genesis::InstallNativeFunctions() {
1018 HandleScope scope; 900 HandleScope scope;
1019 INSTALL_NATIVE(JSFunction, "CreateDate", create_date_fun); 901 INSTALL_NATIVE(JSFunction, "CreateDate", create_date_fun);
1020 INSTALL_NATIVE(JSFunction, "ToNumber", to_number_fun); 902 INSTALL_NATIVE(JSFunction, "ToNumber", to_number_fun);
1021 INSTALL_NATIVE(JSFunction, "ToString", to_string_fun); 903 INSTALL_NATIVE(JSFunction, "ToString", to_string_fun);
1022 INSTALL_NATIVE(JSFunction, "ToDetailString", to_detail_string_fun); 904 INSTALL_NATIVE(JSFunction, "ToDetailString", to_detail_string_fun);
1023 INSTALL_NATIVE(JSFunction, "ToObject", to_object_fun); 905 INSTALL_NATIVE(JSFunction, "ToObject", to_object_fun);
1024 INSTALL_NATIVE(JSFunction, "ToInteger", to_integer_fun); 906 INSTALL_NATIVE(JSFunction, "ToInteger", to_integer_fun);
1025 INSTALL_NATIVE(JSFunction, "ToUint32", to_uint32_fun); 907 INSTALL_NATIVE(JSFunction, "ToUint32", to_uint32_fun);
1026 INSTALL_NATIVE(JSFunction, "ToInt32", to_int32_fun); 908 INSTALL_NATIVE(JSFunction, "ToInt32", to_int32_fun);
1027 INSTALL_NATIVE(JSFunction, "ToBoolean", to_boolean_fun);
1028 INSTALL_NATIVE(JSFunction, "GlobalEval", global_eval_fun); 909 INSTALL_NATIVE(JSFunction, "GlobalEval", global_eval_fun);
1029 INSTALL_NATIVE(JSFunction, "Instantiate", instantiate_fun); 910 INSTALL_NATIVE(JSFunction, "Instantiate", instantiate_fun);
1030 INSTALL_NATIVE(JSFunction, "ConfigureTemplateInstance", 911 INSTALL_NATIVE(JSFunction, "ConfigureTemplateInstance",
1031 configure_instance_fun); 912 configure_instance_fun);
1032 INSTALL_NATIVE(JSFunction, "MakeMessage", make_message_fun); 913 INSTALL_NATIVE(JSFunction, "MakeMessage", make_message_fun);
1033 INSTALL_NATIVE(JSFunction, "GetStackTraceLine", get_stack_trace_line_fun); 914 INSTALL_NATIVE(JSFunction, "GetStackTraceLine", get_stack_trace_line_fun);
1034 INSTALL_NATIVE(JSObject, "functionCache", function_cache); 915 INSTALL_NATIVE(JSObject, "functionCache", function_cache);
1035 } 916 }
1036 917
1037 #undef INSTALL_NATIVE 918 #undef INSTALL_NATIVE
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); 1085 script->set_type(Smi::FromInt(Script::TYPE_NATIVE));
1205 Heap::public_set_empty_script(*script); 1086 Heap::public_set_empty_script(*script);
1206 } 1087 }
1207 1088
1208 // Install natives. 1089 // Install natives.
1209 for (int i = Natives::GetDebuggerCount(); 1090 for (int i = Natives::GetDebuggerCount();
1210 i < Natives::GetBuiltinsCount(); 1091 i < Natives::GetBuiltinsCount();
1211 i++) { 1092 i++) {
1212 Vector<const char> name = Natives::GetScriptName(i); 1093 Vector<const char> name = Natives::GetScriptName(i);
1213 if (!CompileBuiltin(i)) return false; 1094 if (!CompileBuiltin(i)) return false;
1095 // TODO(ager): We really only need to install the JS builtin
1096 // functions on the builtins object after compiling and running
1097 // runtime.js.
1098 if (!InstallJSBuiltins(builtins)) return false;
1214 } 1099 }
1215 1100
1216 InstallNativeFunctions(); 1101 InstallNativeFunctions();
1217 1102
1218 // Install Function.prototype.call and apply. 1103 // Install Function.prototype.call and apply.
1219 { Handle<String> key = Factory::function_class_symbol(); 1104 { Handle<String> key = Factory::function_class_symbol();
1220 Handle<JSFunction> function = 1105 Handle<JSFunction> function =
1221 Handle<JSFunction>::cast(GetProperty(Top::global(), key)); 1106 Handle<JSFunction>::cast(GetProperty(Top::global(), key));
1222 Handle<JSObject> proto = 1107 Handle<JSObject> proto =
1223 Handle<JSObject>(JSObject::cast(function->instance_prototype())); 1108 Handle<JSObject>(JSObject::cast(function->instance_prototype()));
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1404 #ifdef DEBUG 1289 #ifdef DEBUG
1405 Handle<Map> to_map(inner_global_from_snapshot->map()); 1290 Handle<Map> to_map(inner_global_from_snapshot->map());
1406 ASSERT_EQ(to_map->instance_size(), from_map->instance_size()); 1291 ASSERT_EQ(to_map->instance_size(), from_map->instance_size());
1407 ASSERT_EQ(0, to_map->inobject_properties()); 1292 ASSERT_EQ(0, to_map->inobject_properties());
1408 ASSERT_EQ(0, from_map->inobject_properties()); 1293 ASSERT_EQ(0, from_map->inobject_properties());
1409 #endif 1294 #endif
1410 inner_global_from_snapshot->set_map(*from_map); 1295 inner_global_from_snapshot->set_map(*from_map);
1411 } 1296 }
1412 1297
1413 1298
1299 bool Genesis::InstallJSBuiltins(Handle<JSBuiltinsObject> builtins) {
1300 HandleScope scope;
1301 for (int i = 0; i < Builtins::NumberOfJavaScriptBuiltins(); i++) {
1302 Builtins::JavaScript id = static_cast<Builtins::JavaScript>(i);
1303 Handle<String> name = Factory::LookupAsciiSymbol(Builtins::GetName(id));
1304 Handle<JSFunction> function
1305 = Handle<JSFunction>(JSFunction::cast(builtins->GetProperty(*name)));
1306 builtins->set_javascript_builtin(id, *function);
1307 Handle<SharedFunctionInfo> shared
1308 = Handle<SharedFunctionInfo>(function->shared());
1309 if (!EnsureCompiled(shared, CLEAR_EXCEPTION)) return false;
1310 }
1311 return true;
1312 }
1313
1314
1414 bool Genesis::ConfigureGlobalObjects( 1315 bool Genesis::ConfigureGlobalObjects(
1415 v8::Handle<v8::ObjectTemplate> global_proxy_template) { 1316 v8::Handle<v8::ObjectTemplate> global_proxy_template) {
1416 Handle<JSObject> global_proxy( 1317 Handle<JSObject> global_proxy(
1417 JSObject::cast(global_context()->global_proxy())); 1318 JSObject::cast(global_context()->global_proxy()));
1418 Handle<JSObject> js_global(JSObject::cast(global_context()->global())); 1319 Handle<JSObject> js_global(JSObject::cast(global_context()->global()));
1419 1320
1420 if (!global_proxy_template.IsEmpty()) { 1321 if (!global_proxy_template.IsEmpty()) {
1421 // Configure the global proxy object. 1322 // Configure the global proxy object.
1422 Handle<ObjectTemplateInfo> proxy_data = 1323 Handle<ObjectTemplateInfo> proxy_data =
1423 v8::Utils::OpenHandle(*global_proxy_template); 1324 v8::Utils::OpenHandle(*global_proxy_template);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1478 Handle<String> key = Handle<String>(descs->GetKey(i)); 1379 Handle<String> key = Handle<String>(descs->GetKey(i));
1479 Handle<JSFunction> fun = 1380 Handle<JSFunction> fun =
1480 Handle<JSFunction>(descs->GetConstantFunction(i)); 1381 Handle<JSFunction>(descs->GetConstantFunction(i));
1481 SetProperty(to, key, fun, details.attributes()); 1382 SetProperty(to, key, fun, details.attributes());
1482 break; 1383 break;
1483 } 1384 }
1484 case CALLBACKS: { 1385 case CALLBACKS: {
1485 LookupResult result; 1386 LookupResult result;
1486 to->LocalLookup(descs->GetKey(i), &result); 1387 to->LocalLookup(descs->GetKey(i), &result);
1487 // If the property is already there we skip it 1388 // If the property is already there we skip it
1488 if (result.IsValid()) continue; 1389 if (result.IsProperty()) continue;
1489 HandleScope inner; 1390 HandleScope inner;
1490 ASSERT(!to->HasFastProperties()); 1391 ASSERT(!to->HasFastProperties());
1491 // Add to dictionary. 1392 // Add to dictionary.
1492 Handle<String> key = Handle<String>(descs->GetKey(i)); 1393 Handle<String> key = Handle<String>(descs->GetKey(i));
1493 Handle<Object> callbacks(descs->GetCallbacksObject(i)); 1394 Handle<Object> callbacks(descs->GetCallbacksObject(i));
1494 PropertyDetails d = 1395 PropertyDetails d =
1495 PropertyDetails(details.attributes(), CALLBACKS, details.index()); 1396 PropertyDetails(details.attributes(), CALLBACKS, details.index());
1496 SetNormalizedProperty(to, key, callbacks, d); 1397 SetNormalizedProperty(to, key, callbacks, d);
1497 break; 1398 break;
1498 } 1399 }
(...skipping 14 matching lines...) Expand all
1513 Handle<StringDictionary> properties = 1414 Handle<StringDictionary> properties =
1514 Handle<StringDictionary>(from->property_dictionary()); 1415 Handle<StringDictionary>(from->property_dictionary());
1515 int capacity = properties->Capacity(); 1416 int capacity = properties->Capacity();
1516 for (int i = 0; i < capacity; i++) { 1417 for (int i = 0; i < capacity; i++) {
1517 Object* raw_key(properties->KeyAt(i)); 1418 Object* raw_key(properties->KeyAt(i));
1518 if (properties->IsKey(raw_key)) { 1419 if (properties->IsKey(raw_key)) {
1519 ASSERT(raw_key->IsString()); 1420 ASSERT(raw_key->IsString());
1520 // If the property is already there we skip it. 1421 // If the property is already there we skip it.
1521 LookupResult result; 1422 LookupResult result;
1522 to->LocalLookup(String::cast(raw_key), &result); 1423 to->LocalLookup(String::cast(raw_key), &result);
1523 if (result.IsValid()) continue; 1424 if (result.IsProperty()) continue;
1524 // Set the property. 1425 // Set the property.
1525 Handle<String> key = Handle<String>(String::cast(raw_key)); 1426 Handle<String> key = Handle<String>(String::cast(raw_key));
1526 Handle<Object> value = Handle<Object>(properties->ValueAt(i)); 1427 Handle<Object> value = Handle<Object>(properties->ValueAt(i));
1527 if (value->IsJSGlobalPropertyCell()) { 1428 if (value->IsJSGlobalPropertyCell()) {
1528 value = Handle<Object>(JSGlobalPropertyCell::cast(*value)->value()); 1429 value = Handle<Object>(JSGlobalPropertyCell::cast(*value)->value());
1529 } 1430 }
1530 PropertyDetails details = properties->DetailsAt(i); 1431 PropertyDetails details = properties->DetailsAt(i);
1531 SetProperty(to, key, value, details.attributes()); 1432 SetProperty(to, key, value, details.attributes());
1532 } 1433 }
1533 } 1434 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1597 new_array->set(len+1, *value); 1498 new_array->set(len+1, *value);
1598 new_array->set(len+2, *optimized); 1499 new_array->set(len+2, *optimized);
1599 global_context()->set_special_function_table(*new_array); 1500 global_context()->set_special_function_table(*new_array);
1600 } 1501 }
1601 } 1502 }
1602 1503
1603 1504
1604 void Genesis::BuildSpecialFunctionTable() { 1505 void Genesis::BuildSpecialFunctionTable() {
1605 HandleScope scope; 1506 HandleScope scope;
1606 Handle<JSObject> global = Handle<JSObject>(global_context()->global()); 1507 Handle<JSObject> global = Handle<JSObject>(global_context()->global());
1607 // Add special versions for Array.prototype.pop and push. 1508 // Add special versions for some Array.prototype functions.
1608 Handle<JSFunction> function = 1509 Handle<JSFunction> function =
1609 Handle<JSFunction>( 1510 Handle<JSFunction>(
1610 JSFunction::cast(global->GetProperty(Heap::Array_symbol()))); 1511 JSFunction::cast(global->GetProperty(Heap::Array_symbol())));
1611 Handle<JSObject> visible_prototype = 1512 Handle<JSObject> visible_prototype =
1612 Handle<JSObject>(JSObject::cast(function->prototype())); 1513 Handle<JSObject>(JSObject::cast(function->prototype()));
1613 // Remember to put push and pop on the hidden prototype if it's there. 1514 // Remember to put those specializations on the hidden prototype if present.
1614 Handle<JSObject> push_and_pop_prototype; 1515 Handle<JSObject> special_prototype;
1615 Handle<Object> superproto(visible_prototype->GetPrototype()); 1516 Handle<Object> superproto(visible_prototype->GetPrototype());
1616 if (superproto->IsJSObject() && 1517 if (superproto->IsJSObject() &&
1617 JSObject::cast(*superproto)->map()->is_hidden_prototype()) { 1518 JSObject::cast(*superproto)->map()->is_hidden_prototype()) {
1618 push_and_pop_prototype = Handle<JSObject>::cast(superproto); 1519 special_prototype = Handle<JSObject>::cast(superproto);
1619 } else { 1520 } else {
1620 push_and_pop_prototype = visible_prototype; 1521 special_prototype = visible_prototype;
1621 } 1522 }
1622 AddSpecialFunction(push_and_pop_prototype, "pop", 1523 AddSpecialFunction(special_prototype, "pop",
1623 Handle<Code>(Builtins::builtin(Builtins::ArrayPop))); 1524 Handle<Code>(Builtins::builtin(Builtins::ArrayPop)));
1624 AddSpecialFunction(push_and_pop_prototype, "push", 1525 AddSpecialFunction(special_prototype, "push",
1625 Handle<Code>(Builtins::builtin(Builtins::ArrayPush))); 1526 Handle<Code>(Builtins::builtin(Builtins::ArrayPush)));
1527 AddSpecialFunction(special_prototype, "shift",
1528 Handle<Code>(Builtins::builtin(Builtins::ArrayShift)));
1529 AddSpecialFunction(special_prototype, "unshift",
1530 Handle<Code>(Builtins::builtin(Builtins::ArrayUnshift)));
1531 AddSpecialFunction(special_prototype, "slice",
1532 Handle<Code>(Builtins::builtin(Builtins::ArraySlice)));
1533 AddSpecialFunction(special_prototype, "splice",
1534 Handle<Code>(Builtins::builtin(Builtins::ArraySplice)));
1626 } 1535 }
1627 1536
1628 1537
1629 Genesis::Genesis(Handle<Object> global_object, 1538 Genesis::Genesis(Handle<Object> global_object,
1630 v8::Handle<v8::ObjectTemplate> global_template, 1539 v8::Handle<v8::ObjectTemplate> global_template,
1631 v8::ExtensionConfiguration* extensions) { 1540 v8::ExtensionConfiguration* extensions) {
1632 result_ = Handle<Context>::null(); 1541 result_ = Handle<Context>::null();
1633 // If V8 isn't running and cannot be initialized, just return. 1542 // If V8 isn't running and cannot be initialized, just return.
1634 if (!V8::IsRunning() && !V8::Initialize(NULL)) return; 1543 if (!V8::IsRunning() && !V8::Initialize(NULL)) return;
1635 1544
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1724 } 1633 }
1725 1634
1726 1635
1727 // Restore statics that are thread local. 1636 // Restore statics that are thread local.
1728 char* BootstrapperActive::RestoreState(char* from) { 1637 char* BootstrapperActive::RestoreState(char* from) {
1729 nesting_ = *reinterpret_cast<int*>(from); 1638 nesting_ = *reinterpret_cast<int*>(from);
1730 return from + sizeof(nesting_); 1639 return from + sizeof(nesting_);
1731 } 1640 }
1732 1641
1733 } } // namespace v8::internal 1642 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/bootstrapper.h ('k') | src/builtins.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698