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

Side by Side Diff: src/bootstrapper.cc

Issue 6720014: Isolates: Cleanup usage of FACTORY in code stubs and bootstrapper. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Minor edits. Created 9 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 | Annotate | Revision Log
« no previous file with comments | « src/bootstrapper.h ('k') | src/debug.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 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 delete delete_these_arrays_on_tear_down_; 134 delete delete_these_arrays_on_tear_down_;
135 delete_these_arrays_on_tear_down_ = NULL; 135 delete_these_arrays_on_tear_down_ = NULL;
136 } 136 }
137 137
138 extensions_cache_.Initialize(false); // Yes, symmetrical 138 extensions_cache_.Initialize(false); // Yes, symmetrical
139 } 139 }
140 140
141 141
142 class Genesis BASE_EMBEDDED { 142 class Genesis BASE_EMBEDDED {
143 public: 143 public:
144 Genesis(Handle<Object> global_object, 144 Genesis(Isolate* isolate,
145 Handle<Object> global_object,
145 v8::Handle<v8::ObjectTemplate> global_template, 146 v8::Handle<v8::ObjectTemplate> global_template,
146 v8::ExtensionConfiguration* extensions); 147 v8::ExtensionConfiguration* extensions);
147 ~Genesis() { } 148 ~Genesis() { }
148 149
149 Handle<Context> result() { return result_; } 150 Handle<Context> result() { return result_; }
150 151
151 Genesis* previous() { return previous_; } 152 Genesis* previous() { return previous_; }
152 153
154 Isolate* isolate() const { return isolate_; }
155 Factory* factory() const { return isolate_->factory(); }
156 Heap* heap() const { return isolate_->heap(); }
153 private: 157 private:
Mads Ager (chromium) 2011/04/06 07:34:15 Could you leave a blank line before the private se
154 Handle<Context> global_context_; 158 Handle<Context> global_context_;
159 Isolate* isolate_;
155 160
156 // There may be more than one active genesis object: When GC is 161 // There may be more than one active genesis object: When GC is
157 // triggered during environment creation there may be weak handle 162 // triggered during environment creation there may be weak handle
158 // processing callbacks which may create new environments. 163 // processing callbacks which may create new environments.
159 Genesis* previous_; 164 Genesis* previous_;
160 165
161 Handle<Context> global_context() { return global_context_; } 166 Handle<Context> global_context() { return global_context_; }
162 167
163 // Creates some basic objects. Used for creating a context from scratch. 168 // Creates some basic objects. Used for creating a context from scratch.
164 void CreateRoots(); 169 void CreateRoots();
165 // Creates the empty function. Used for creating a context from scratch. 170 // Creates the empty function. Used for creating a context from scratch.
166 Handle<JSFunction> CreateEmptyFunction(); 171 Handle<JSFunction> CreateEmptyFunction(Isolate* isolate);
167 // Creates the ThrowTypeError function. ECMA 5th Ed. 13.2.3 172 // Creates the ThrowTypeError function. ECMA 5th Ed. 13.2.3
168 Handle<JSFunction> CreateThrowTypeErrorFunction(Builtins::Name builtin); 173 Handle<JSFunction> CreateThrowTypeErrorFunction(Builtins::Name builtin);
169 174
170 void CreateStrictModeFunctionMaps(Handle<JSFunction> empty); 175 void CreateStrictModeFunctionMaps(Handle<JSFunction> empty);
171 // Creates the global objects using the global and the template passed in 176 // Creates the global objects using the global and the template passed in
172 // through the API. We call this regardless of whether we are building a 177 // through the API. We call this regardless of whether we are building a
173 // context from scratch or using a deserialized one from the partial snapshot 178 // context from scratch or using a deserialized one from the partial snapshot
174 // but in the latter case we don't use the objects it produces directly, as 179 // but in the latter case we don't use the objects it produces directly, as
175 // we have to used the deserialized ones that are linked together with the 180 // we have to used the deserialized ones that are linked together with the
176 // rest of the context snapshot. 181 // rest of the context snapshot.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 PrototypePropertyMode prototype_mode, 237 PrototypePropertyMode prototype_mode,
233 Handle<JSFunction> empty_function, 238 Handle<JSFunction> empty_function,
234 Handle<FixedArray> arguments_callbacks, 239 Handle<FixedArray> arguments_callbacks,
235 Handle<FixedArray> caller_callbacks); 240 Handle<FixedArray> caller_callbacks);
236 241
237 Handle<DescriptorArray> ComputeStrictFunctionInstanceDescriptor( 242 Handle<DescriptorArray> ComputeStrictFunctionInstanceDescriptor(
238 PrototypePropertyMode propertyMode, 243 PrototypePropertyMode propertyMode,
239 Handle<FixedArray> arguments, 244 Handle<FixedArray> arguments,
240 Handle<FixedArray> caller); 245 Handle<FixedArray> caller);
241 246
242 static bool CompileBuiltin(int index); 247 static bool CompileBuiltin(Isolate* isolate, int index);
243 static bool CompileNative(Vector<const char> name, Handle<String> source); 248 static bool CompileNative(Vector<const char> name, Handle<String> source);
244 static bool CompileScriptCached(Vector<const char> name, 249 static bool CompileScriptCached(Vector<const char> name,
245 Handle<String> source, 250 Handle<String> source,
246 SourceCodeCache* cache, 251 SourceCodeCache* cache,
247 v8::Extension* extension, 252 v8::Extension* extension,
248 Handle<Context> top_context, 253 Handle<Context> top_context,
249 bool use_runtime_context); 254 bool use_runtime_context);
250 255
251 Handle<Context> result_; 256 Handle<Context> result_;
252 257
253 // Function instance maps. Function literal maps are created initially with 258 // Function instance maps. Function literal maps are created initially with
254 // a read only prototype for the processing of JS builtins. Later the function 259 // a read only prototype for the processing of JS builtins. Later the function
255 // instance maps are replaced in order to make prototype writable. 260 // instance maps are replaced in order to make prototype writable.
256 // These are the final, writable prototype, maps. 261 // These are the final, writable prototype, maps.
257 Handle<Map> function_instance_map_writable_prototype_; 262 Handle<Map> function_instance_map_writable_prototype_;
258 Handle<Map> strict_mode_function_instance_map_writable_prototype_; 263 Handle<Map> strict_mode_function_instance_map_writable_prototype_;
259 264
260 BootstrapperActive active_; 265 BootstrapperActive active_;
261 friend class Bootstrapper; 266 friend class Bootstrapper;
262 }; 267 };
263 268
264 269
265 void Bootstrapper::Iterate(ObjectVisitor* v) { 270 void Bootstrapper::Iterate(ObjectVisitor* v) {
266 extensions_cache_.Iterate(v); 271 extensions_cache_.Iterate(v);
267 v->Synchronize("Extensions"); 272 v->Synchronize("Extensions");
268 } 273 }
269 274
270 275
271 Handle<Context> Bootstrapper::CreateEnvironment( 276 Handle<Context> Bootstrapper::CreateEnvironment(
277 Isolate* isolate,
272 Handle<Object> global_object, 278 Handle<Object> global_object,
273 v8::Handle<v8::ObjectTemplate> global_template, 279 v8::Handle<v8::ObjectTemplate> global_template,
274 v8::ExtensionConfiguration* extensions) { 280 v8::ExtensionConfiguration* extensions) {
275 HandleScope scope; 281 HandleScope scope;
276 Handle<Context> env; 282 Handle<Context> env;
277 Genesis genesis(global_object, global_template, extensions); 283 Genesis genesis(isolate, global_object, global_template, extensions);
278 env = genesis.result(); 284 env = genesis.result();
279 if (!env.is_null()) { 285 if (!env.is_null()) {
280 if (InstallExtensions(env, extensions)) { 286 if (InstallExtensions(env, extensions)) {
281 return env; 287 return env;
282 } 288 }
283 } 289 }
284 return Handle<Context>(); 290 return Handle<Context>();
285 } 291 }
286 292
287 293
288 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) { 294 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) {
289 // object.__proto__ = proto; 295 // object.__proto__ = proto;
296 Factory* factory = object->GetIsolate()->factory();
290 Handle<Map> old_to_map = Handle<Map>(object->map()); 297 Handle<Map> old_to_map = Handle<Map>(object->map());
291 Handle<Map> new_to_map = FACTORY->CopyMapDropTransitions(old_to_map); 298 Handle<Map> new_to_map = factory->CopyMapDropTransitions(old_to_map);
292 new_to_map->set_prototype(*proto); 299 new_to_map->set_prototype(*proto);
293 object->set_map(*new_to_map); 300 object->set_map(*new_to_map);
294 } 301 }
295 302
296 303
297 void Bootstrapper::DetachGlobal(Handle<Context> env) { 304 void Bootstrapper::DetachGlobal(Handle<Context> env) {
298 Factory* factory = Isolate::Current()->factory(); 305 Factory* factory = env->GetIsolate()->factory();
299 JSGlobalProxy::cast(env->global_proxy())->set_context(*factory->null_value()); 306 JSGlobalProxy::cast(env->global_proxy())->set_context(*factory->null_value());
300 SetObjectPrototype(Handle<JSObject>(env->global_proxy()), 307 SetObjectPrototype(Handle<JSObject>(env->global_proxy()),
301 factory->null_value()); 308 factory->null_value());
302 env->set_global_proxy(env->global()); 309 env->set_global_proxy(env->global());
303 env->global()->set_global_receiver(env->global()); 310 env->global()->set_global_receiver(env->global());
304 } 311 }
305 312
306 313
307 void Bootstrapper::ReattachGlobal(Handle<Context> env, 314 void Bootstrapper::ReattachGlobal(Handle<Context> env,
308 Handle<Object> global_object) { 315 Handle<Object> global_object) {
309 ASSERT(global_object->IsJSGlobalProxy()); 316 ASSERT(global_object->IsJSGlobalProxy());
310 Handle<JSGlobalProxy> global = Handle<JSGlobalProxy>::cast(global_object); 317 Handle<JSGlobalProxy> global = Handle<JSGlobalProxy>::cast(global_object);
311 env->global()->set_global_receiver(*global); 318 env->global()->set_global_receiver(*global);
312 env->set_global_proxy(*global); 319 env->set_global_proxy(*global);
313 SetObjectPrototype(global, Handle<JSObject>(env->global())); 320 SetObjectPrototype(global, Handle<JSObject>(env->global()));
314 global->set_context(*env); 321 global->set_context(*env);
315 } 322 }
316 323
317 324
318 static Handle<JSFunction> InstallFunction(Handle<JSObject> target, 325 static Handle<JSFunction> InstallFunction(Handle<JSObject> target,
319 const char* name, 326 const char* name,
320 InstanceType type, 327 InstanceType type,
321 int instance_size, 328 int instance_size,
322 Handle<JSObject> prototype, 329 Handle<JSObject> prototype,
323 Builtins::Name call, 330 Builtins::Name call,
324 bool is_ecma_native) { 331 bool is_ecma_native) {
325 Isolate* isolate = Isolate::Current(); 332 Isolate* isolate = target->GetIsolate();
326 Factory* factory = isolate->factory(); 333 Factory* factory = isolate->factory();
327 Handle<String> symbol = factory->LookupAsciiSymbol(name); 334 Handle<String> symbol = factory->LookupAsciiSymbol(name);
328 Handle<Code> call_code = Handle<Code>(isolate->builtins()->builtin(call)); 335 Handle<Code> call_code = Handle<Code>(isolate->builtins()->builtin(call));
329 Handle<JSFunction> function = prototype.is_null() ? 336 Handle<JSFunction> function = prototype.is_null() ?
330 factory->NewFunctionWithoutPrototype(symbol, call_code) : 337 factory->NewFunctionWithoutPrototype(symbol, call_code) :
331 factory->NewFunctionWithPrototype(symbol, 338 factory->NewFunctionWithPrototype(symbol,
332 type, 339 type,
333 instance_size, 340 instance_size,
334 prototype, 341 prototype,
335 call_code, 342 call_code,
336 is_ecma_native); 343 is_ecma_native);
337 SetLocalPropertyNoThrow(target, symbol, function, DONT_ENUM); 344 SetLocalPropertyNoThrow(target, symbol, function, DONT_ENUM);
338 if (is_ecma_native) { 345 if (is_ecma_native) {
339 function->shared()->set_instance_class_name(*symbol); 346 function->shared()->set_instance_class_name(*symbol);
340 } 347 }
341 return function; 348 return function;
342 } 349 }
343 350
344 351
345 Handle<DescriptorArray> Genesis::ComputeFunctionInstanceDescriptor( 352 Handle<DescriptorArray> Genesis::ComputeFunctionInstanceDescriptor(
346 PrototypePropertyMode prototypeMode) { 353 PrototypePropertyMode prototypeMode) {
347 Factory* factory = Isolate::Current()->factory();
348 Handle<DescriptorArray> descriptors = 354 Handle<DescriptorArray> descriptors =
349 factory->NewDescriptorArray(prototypeMode == DONT_ADD_PROTOTYPE ? 4 : 5); 355 factory()->NewDescriptorArray(prototypeMode == DONT_ADD_PROTOTYPE ? 4 : 5) ;
350 PropertyAttributes attributes = 356 PropertyAttributes attributes =
351 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); 357 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
352 358
353 { // Add length. 359 { // Add length.
354 Handle<Proxy> proxy = factory->NewProxy(&Accessors::FunctionLength); 360 Handle<Proxy> proxy = factory()->NewProxy(&Accessors::FunctionLength);
355 CallbacksDescriptor d(*factory->length_symbol(), *proxy, attributes); 361 CallbacksDescriptor d(*factory()->length_symbol(), *proxy, attributes);
356 descriptors->Set(0, &d); 362 descriptors->Set(0, &d);
357 } 363 }
358 { // Add name. 364 { // Add name.
359 Handle<Proxy> proxy = factory->NewProxy(&Accessors::FunctionName); 365 Handle<Proxy> proxy = factory()->NewProxy(&Accessors::FunctionName);
360 CallbacksDescriptor d(*factory->name_symbol(), *proxy, attributes); 366 CallbacksDescriptor d(*factory()->name_symbol(), *proxy, attributes);
361 descriptors->Set(1, &d); 367 descriptors->Set(1, &d);
362 } 368 }
363 { // Add arguments. 369 { // Add arguments.
364 Handle<Proxy> proxy = factory->NewProxy(&Accessors::FunctionArguments); 370 Handle<Proxy> proxy = factory()->NewProxy(&Accessors::FunctionArguments);
365 CallbacksDescriptor d(*factory->arguments_symbol(), *proxy, attributes); 371 CallbacksDescriptor d(*factory()->arguments_symbol(), *proxy, attributes);
366 descriptors->Set(2, &d); 372 descriptors->Set(2, &d);
367 } 373 }
368 { // Add caller. 374 { // Add caller.
369 Handle<Proxy> proxy = factory->NewProxy(&Accessors::FunctionCaller); 375 Handle<Proxy> proxy = factory()->NewProxy(&Accessors::FunctionCaller);
370 CallbacksDescriptor d(*factory->caller_symbol(), *proxy, attributes); 376 CallbacksDescriptor d(*factory()->caller_symbol(), *proxy, attributes);
371 descriptors->Set(3, &d); 377 descriptors->Set(3, &d);
372 } 378 }
373 if (prototypeMode != DONT_ADD_PROTOTYPE) { 379 if (prototypeMode != DONT_ADD_PROTOTYPE) {
374 // Add prototype. 380 // Add prototype.
375 if (prototypeMode == ADD_WRITEABLE_PROTOTYPE) { 381 if (prototypeMode == ADD_WRITEABLE_PROTOTYPE) {
376 attributes = static_cast<PropertyAttributes>(attributes & ~READ_ONLY); 382 attributes = static_cast<PropertyAttributes>(attributes & ~READ_ONLY);
377 } 383 }
378 Handle<Proxy> proxy = factory->NewProxy(&Accessors::FunctionPrototype); 384 Handle<Proxy> proxy = factory()->NewProxy(&Accessors::FunctionPrototype);
379 CallbacksDescriptor d(*factory->prototype_symbol(), *proxy, attributes); 385 CallbacksDescriptor d(*factory()->prototype_symbol(), *proxy, attributes);
380 descriptors->Set(4, &d); 386 descriptors->Set(4, &d);
381 } 387 }
382 descriptors->Sort(); 388 descriptors->Sort();
383 return descriptors; 389 return descriptors;
384 } 390 }
385 391
386 392
387 Handle<Map> Genesis::CreateFunctionMap(PrototypePropertyMode prototype_mode) { 393 Handle<Map> Genesis::CreateFunctionMap(PrototypePropertyMode prototype_mode) {
388 Handle<Map> map = FACTORY->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); 394 Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize);
389 Handle<DescriptorArray> descriptors = 395 Handle<DescriptorArray> descriptors =
390 ComputeFunctionInstanceDescriptor(prototype_mode); 396 ComputeFunctionInstanceDescriptor(prototype_mode);
391 map->set_instance_descriptors(*descriptors); 397 map->set_instance_descriptors(*descriptors);
392 map->set_function_with_prototype(prototype_mode != DONT_ADD_PROTOTYPE); 398 map->set_function_with_prototype(prototype_mode != DONT_ADD_PROTOTYPE);
393 return map; 399 return map;
394 } 400 }
395 401
396 402
397 Handle<JSFunction> Genesis::CreateEmptyFunction() { 403 Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) {
398 // Allocate the map for function instances. Maps are allocated first and their 404 // Allocate the map for function instances. Maps are allocated first and their
399 // prototypes patched later, once empty function is created. 405 // prototypes patched later, once empty function is created.
400 406
401 // Please note that the prototype property for function instances must be 407 // Please note that the prototype property for function instances must be
402 // writable. 408 // writable.
403 Handle<Map> function_instance_map = 409 Handle<Map> function_instance_map =
404 CreateFunctionMap(ADD_WRITEABLE_PROTOTYPE); 410 CreateFunctionMap(ADD_WRITEABLE_PROTOTYPE);
405 global_context()->set_function_instance_map(*function_instance_map); 411 global_context()->set_function_instance_map(*function_instance_map);
406 412
407 // Functions with this map will not have a 'prototype' property, and 413 // Functions with this map will not have a 'prototype' property, and
408 // can not be used as constructors. 414 // can not be used as constructors.
409 Handle<Map> function_without_prototype_map = 415 Handle<Map> function_without_prototype_map =
410 CreateFunctionMap(DONT_ADD_PROTOTYPE); 416 CreateFunctionMap(DONT_ADD_PROTOTYPE);
411 global_context()->set_function_without_prototype_map( 417 global_context()->set_function_without_prototype_map(
412 *function_without_prototype_map); 418 *function_without_prototype_map);
413 419
414 // Allocate the function map. This map is temporary, used only for processing 420 // Allocate the function map. This map is temporary, used only for processing
415 // of builtins. 421 // of builtins.
416 // Later the map is replaced with writable prototype map, allocated below. 422 // Later the map is replaced with writable prototype map, allocated below.
417 Handle<Map> function_map = CreateFunctionMap(ADD_READONLY_PROTOTYPE); 423 Handle<Map> function_map = CreateFunctionMap(ADD_READONLY_PROTOTYPE);
418 global_context()->set_function_map(*function_map); 424 global_context()->set_function_map(*function_map);
419 425
420 // The final map for functions. Writeable prototype. 426 // The final map for functions. Writeable prototype.
421 // This map is installed in MakeFunctionInstancePrototypeWritable. 427 // This map is installed in MakeFunctionInstancePrototypeWritable.
422 function_instance_map_writable_prototype_ = 428 function_instance_map_writable_prototype_ =
423 CreateFunctionMap(ADD_WRITEABLE_PROTOTYPE); 429 CreateFunctionMap(ADD_WRITEABLE_PROTOTYPE);
424 430
425 Isolate* isolate = Isolate::Current();
426 Factory* factory = isolate->factory(); 431 Factory* factory = isolate->factory();
427 Heap* heap = isolate->heap(); 432 Heap* heap = isolate->heap();
428 433
429 Handle<String> object_name = Handle<String>(heap->Object_symbol()); 434 Handle<String> object_name = Handle<String>(heap->Object_symbol());
430 435
431 { // --- O b j e c t --- 436 { // --- O b j e c t ---
432 Handle<JSFunction> object_fun = 437 Handle<JSFunction> object_fun =
433 factory->NewFunction(object_name, factory->null_value()); 438 factory->NewFunction(object_name, factory->null_value());
434 Handle<Map> object_function_map = 439 Handle<Map> object_function_map =
435 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 440 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 empty_fm->set_prototype(global_context()->object_function()->prototype()); 489 empty_fm->set_prototype(global_context()->object_function()->prototype());
485 empty_function->set_map(*empty_fm); 490 empty_function->set_map(*empty_fm);
486 return empty_function; 491 return empty_function;
487 } 492 }
488 493
489 494
490 Handle<DescriptorArray> Genesis::ComputeStrictFunctionInstanceDescriptor( 495 Handle<DescriptorArray> Genesis::ComputeStrictFunctionInstanceDescriptor(
491 PrototypePropertyMode prototypeMode, 496 PrototypePropertyMode prototypeMode,
492 Handle<FixedArray> arguments, 497 Handle<FixedArray> arguments,
493 Handle<FixedArray> caller) { 498 Handle<FixedArray> caller) {
494 Factory* factory = Isolate::Current()->factory();
495 Handle<DescriptorArray> descriptors = 499 Handle<DescriptorArray> descriptors =
496 factory->NewDescriptorArray(prototypeMode == DONT_ADD_PROTOTYPE ? 4 : 5); 500 factory()->NewDescriptorArray(prototypeMode == DONT_ADD_PROTOTYPE ? 4 : 5) ;
497 PropertyAttributes attributes = static_cast<PropertyAttributes>( 501 PropertyAttributes attributes = static_cast<PropertyAttributes>(
498 DONT_ENUM | DONT_DELETE | READ_ONLY); 502 DONT_ENUM | DONT_DELETE | READ_ONLY);
499 503
500 { // length 504 { // length
501 Handle<Proxy> proxy = factory->NewProxy(&Accessors::FunctionLength); 505 Handle<Proxy> proxy = factory()->NewProxy(&Accessors::FunctionLength);
502 CallbacksDescriptor d(*factory->length_symbol(), *proxy, attributes); 506 CallbacksDescriptor d(*factory()->length_symbol(), *proxy, attributes);
503 descriptors->Set(0, &d); 507 descriptors->Set(0, &d);
504 } 508 }
505 { // name 509 { // name
506 Handle<Proxy> proxy = factory->NewProxy(&Accessors::FunctionName); 510 Handle<Proxy> proxy = factory()->NewProxy(&Accessors::FunctionName);
507 CallbacksDescriptor d(*factory->name_symbol(), *proxy, attributes); 511 CallbacksDescriptor d(*factory()->name_symbol(), *proxy, attributes);
508 descriptors->Set(1, &d); 512 descriptors->Set(1, &d);
509 } 513 }
510 { // arguments 514 { // arguments
511 CallbacksDescriptor d(*factory->arguments_symbol(), *arguments, attributes); 515 CallbacksDescriptor d(*factory()->arguments_symbol(),
516 *arguments,
517 attributes);
512 descriptors->Set(2, &d); 518 descriptors->Set(2, &d);
513 } 519 }
514 { // caller 520 { // caller
515 CallbacksDescriptor d(*factory->caller_symbol(), *caller, attributes); 521 CallbacksDescriptor d(*factory()->caller_symbol(), *caller, attributes);
516 descriptors->Set(3, &d); 522 descriptors->Set(3, &d);
517 } 523 }
518 524
519 // prototype 525 // prototype
520 if (prototypeMode != DONT_ADD_PROTOTYPE) { 526 if (prototypeMode != DONT_ADD_PROTOTYPE) {
521 if (prototypeMode == ADD_WRITEABLE_PROTOTYPE) { 527 if (prototypeMode == ADD_WRITEABLE_PROTOTYPE) {
522 attributes = static_cast<PropertyAttributes>(attributes & ~READ_ONLY); 528 attributes = static_cast<PropertyAttributes>(attributes & ~READ_ONLY);
523 } 529 }
524 Handle<Proxy> proxy = factory->NewProxy(&Accessors::FunctionPrototype); 530 Handle<Proxy> proxy = factory()->NewProxy(&Accessors::FunctionPrototype);
525 CallbacksDescriptor d(*factory->prototype_symbol(), *proxy, attributes); 531 CallbacksDescriptor d(*factory()->prototype_symbol(), *proxy, attributes);
526 descriptors->Set(4, &d); 532 descriptors->Set(4, &d);
527 } 533 }
528 534
529 descriptors->Sort(); 535 descriptors->Sort();
530 return descriptors; 536 return descriptors;
531 } 537 }
532 538
533 539
534 // ECMAScript 5th Edition, 13.2.3 540 // ECMAScript 5th Edition, 13.2.3
535 Handle<JSFunction> Genesis::CreateThrowTypeErrorFunction( 541 Handle<JSFunction> Genesis::CreateThrowTypeErrorFunction(
536 Builtins::Name builtin) { 542 Builtins::Name builtin) {
537 Isolate* isolate = Isolate::Current(); 543 Handle<String> name = factory()->LookupAsciiSymbol("ThrowTypeError");
538 Factory* factory = isolate->factory();
539
540 Handle<String> name = factory->LookupAsciiSymbol("ThrowTypeError");
541 Handle<JSFunction> throw_type_error = 544 Handle<JSFunction> throw_type_error =
542 factory->NewFunctionWithoutPrototype(name, kStrictMode); 545 factory()->NewFunctionWithoutPrototype(name, kStrictMode);
543 Handle<Code> code = Handle<Code>( 546 Handle<Code> code = Handle<Code>(
544 isolate->builtins()->builtin(builtin)); 547 isolate()->builtins()->builtin(builtin));
545 548
546 throw_type_error->set_map(global_context()->strict_mode_function_map()); 549 throw_type_error->set_map(global_context()->strict_mode_function_map());
547 throw_type_error->set_code(*code); 550 throw_type_error->set_code(*code);
548 throw_type_error->shared()->set_code(*code); 551 throw_type_error->shared()->set_code(*code);
549 throw_type_error->shared()->DontAdaptArguments(); 552 throw_type_error->shared()->DontAdaptArguments();
550 553
551 PreventExtensions(throw_type_error); 554 PreventExtensions(throw_type_error);
552 555
553 return throw_type_error; 556 return throw_type_error;
554 } 557 }
555 558
556 559
557 Handle<Map> Genesis::CreateStrictModeFunctionMap( 560 Handle<Map> Genesis::CreateStrictModeFunctionMap(
558 PrototypePropertyMode prototype_mode, 561 PrototypePropertyMode prototype_mode,
559 Handle<JSFunction> empty_function, 562 Handle<JSFunction> empty_function,
560 Handle<FixedArray> arguments_callbacks, 563 Handle<FixedArray> arguments_callbacks,
561 Handle<FixedArray> caller_callbacks) { 564 Handle<FixedArray> caller_callbacks) {
562 Handle<Map> map = FACTORY->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); 565 Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize);
563 Handle<DescriptorArray> descriptors = 566 Handle<DescriptorArray> descriptors =
564 ComputeStrictFunctionInstanceDescriptor(prototype_mode, 567 ComputeStrictFunctionInstanceDescriptor(prototype_mode,
565 arguments_callbacks, 568 arguments_callbacks,
566 caller_callbacks); 569 caller_callbacks);
567 map->set_instance_descriptors(*descriptors); 570 map->set_instance_descriptors(*descriptors);
568 map->set_function_with_prototype(prototype_mode != DONT_ADD_PROTOTYPE); 571 map->set_function_with_prototype(prototype_mode != DONT_ADD_PROTOTYPE);
569 map->set_prototype(*empty_function); 572 map->set_prototype(*empty_function);
570 return map; 573 return map;
571 } 574 }
572 575
573 576
574 void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) { 577 void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) {
575 // Create the callbacks arrays for ThrowTypeError functions. 578 // Create the callbacks arrays for ThrowTypeError functions.
576 // The get/set callacks are filled in after the maps are created below. 579 // The get/set callacks are filled in after the maps are created below.
577 Factory* factory = Isolate::Current()->factory(); 580 Factory* factory = empty->GetIsolate()->factory();
578 Handle<FixedArray> arguments = factory->NewFixedArray(2, TENURED); 581 Handle<FixedArray> arguments = factory->NewFixedArray(2, TENURED);
579 Handle<FixedArray> caller = factory->NewFixedArray(2, TENURED); 582 Handle<FixedArray> caller = factory->NewFixedArray(2, TENURED);
580 583
581 // Allocate map for the strict mode function instances. 584 // Allocate map for the strict mode function instances.
582 Handle<Map> strict_mode_function_instance_map = 585 Handle<Map> strict_mode_function_instance_map =
583 CreateStrictModeFunctionMap( 586 CreateStrictModeFunctionMap(
584 ADD_WRITEABLE_PROTOTYPE, empty, arguments, caller); 587 ADD_WRITEABLE_PROTOTYPE, empty, arguments, caller);
585 global_context()->set_strict_mode_function_instance_map( 588 global_context()->set_strict_mode_function_instance_map(
586 *strict_mode_function_instance_map); 589 *strict_mode_function_instance_map);
587 590
(...skipping 28 matching lines...) Expand all
616 // Complete the callback fixed arrays. 619 // Complete the callback fixed arrays.
617 arguments->set(0, *arguments_throw); 620 arguments->set(0, *arguments_throw);
618 arguments->set(1, *arguments_throw); 621 arguments->set(1, *arguments_throw);
619 caller->set(0, *caller_throw); 622 caller->set(0, *caller_throw);
620 caller->set(1, *caller_throw); 623 caller->set(1, *caller_throw);
621 } 624 }
622 625
623 626
624 static void AddToWeakGlobalContextList(Context* context) { 627 static void AddToWeakGlobalContextList(Context* context) {
625 ASSERT(context->IsGlobalContext()); 628 ASSERT(context->IsGlobalContext());
626 Heap* heap = Isolate::Current()->heap(); 629 Heap* heap = context->GetIsolate()->heap();
627 #ifdef DEBUG 630 #ifdef DEBUG
628 { // NOLINT 631 { // NOLINT
629 ASSERT(context->get(Context::NEXT_CONTEXT_LINK)->IsUndefined()); 632 ASSERT(context->get(Context::NEXT_CONTEXT_LINK)->IsUndefined());
630 // Check that context is not in the list yet. 633 // Check that context is not in the list yet.
631 for (Object* current = heap->global_contexts_list(); 634 for (Object* current = heap->global_contexts_list();
632 !current->IsUndefined(); 635 !current->IsUndefined();
633 current = Context::cast(current)->get(Context::NEXT_CONTEXT_LINK)) { 636 current = Context::cast(current)->get(Context::NEXT_CONTEXT_LINK)) {
634 ASSERT(current != context); 637 ASSERT(current != context);
635 } 638 }
636 } 639 }
637 #endif 640 #endif
638 context->set(Context::NEXT_CONTEXT_LINK, heap->global_contexts_list()); 641 context->set(Context::NEXT_CONTEXT_LINK, heap->global_contexts_list());
639 heap->set_global_contexts_list(context); 642 heap->set_global_contexts_list(context);
640 } 643 }
641 644
642 645
643 void Genesis::CreateRoots() { 646 void Genesis::CreateRoots() {
644 Isolate* isolate = Isolate::Current();
645 // Allocate the global context FixedArray first and then patch the 647 // Allocate the global context FixedArray first and then patch the
646 // closure and extension object later (we need the empty function 648 // closure and extension object later (we need the empty function
647 // and the global object, but in order to create those, we need the 649 // and the global object, but in order to create those, we need the
648 // global context). 650 // global context).
649 global_context_ = Handle<Context>::cast(isolate->global_handles()->Create( 651 global_context_ = Handle<Context>::cast(isolate()->global_handles()->Create(
650 *isolate->factory()->NewGlobalContext())); 652 *factory()->NewGlobalContext()));
651 AddToWeakGlobalContextList(*global_context_); 653 AddToWeakGlobalContextList(*global_context_);
652 isolate->set_context(*global_context()); 654 isolate()->set_context(*global_context());
653 655
654 // Allocate the message listeners object. 656 // Allocate the message listeners object.
655 { 657 {
656 v8::NeanderArray listeners; 658 v8::NeanderArray listeners;
657 global_context()->set_message_listeners(*listeners.value()); 659 global_context()->set_message_listeners(*listeners.value());
658 } 660 }
659 } 661 }
660 662
661 663
662 Handle<JSGlobalProxy> Genesis::CreateNewGlobals( 664 Handle<JSGlobalProxy> Genesis::CreateNewGlobals(
(...skipping 22 matching lines...) Expand all
685 Handle<FunctionTemplateInfo> global_constructor = 687 Handle<FunctionTemplateInfo> global_constructor =
686 Handle<FunctionTemplateInfo>( 688 Handle<FunctionTemplateInfo>(
687 FunctionTemplateInfo::cast(data->constructor())); 689 FunctionTemplateInfo::cast(data->constructor()));
688 Handle<Object> proto_template(global_constructor->prototype_template()); 690 Handle<Object> proto_template(global_constructor->prototype_template());
689 if (!proto_template->IsUndefined()) { 691 if (!proto_template->IsUndefined()) {
690 js_global_template = 692 js_global_template =
691 Handle<ObjectTemplateInfo>::cast(proto_template); 693 Handle<ObjectTemplateInfo>::cast(proto_template);
692 } 694 }
693 } 695 }
694 696
695 Isolate* isolate = Isolate::Current();
696 Factory* factory = isolate->factory();
697 Heap* heap = isolate->heap();
698
699 if (js_global_template.is_null()) { 697 if (js_global_template.is_null()) {
700 Handle<String> name = Handle<String>(heap->empty_symbol()); 698 Handle<String> name = Handle<String>(heap()->empty_symbol());
701 Handle<Code> code = Handle<Code>(isolate->builtins()->builtin( 699 Handle<Code> code = Handle<Code>(isolate()->builtins()->builtin(
702 Builtins::kIllegal)); 700 Builtins::kIllegal));
703 js_global_function = 701 js_global_function =
704 factory->NewFunction(name, JS_GLOBAL_OBJECT_TYPE, 702 factory()->NewFunction(name, JS_GLOBAL_OBJECT_TYPE,
705 JSGlobalObject::kSize, code, true); 703 JSGlobalObject::kSize, code, true);
Mads Ager (chromium) 2011/04/06 07:34:15 Indentation is off.
706 // Change the constructor property of the prototype of the 704 // Change the constructor property of the prototype of the
707 // hidden global function to refer to the Object function. 705 // hidden global function to refer to the Object function.
708 Handle<JSObject> prototype = 706 Handle<JSObject> prototype =
709 Handle<JSObject>( 707 Handle<JSObject>(
710 JSObject::cast(js_global_function->instance_prototype())); 708 JSObject::cast(js_global_function->instance_prototype()));
711 SetLocalPropertyNoThrow( 709 SetLocalPropertyNoThrow(
712 prototype, 710 prototype,
713 factory->constructor_symbol(), 711 factory()->constructor_symbol(),
714 isolate->object_function(), 712 isolate()->object_function(),
715 NONE); 713 NONE);
716 } else { 714 } else {
717 Handle<FunctionTemplateInfo> js_global_constructor( 715 Handle<FunctionTemplateInfo> js_global_constructor(
718 FunctionTemplateInfo::cast(js_global_template->constructor())); 716 FunctionTemplateInfo::cast(js_global_template->constructor()));
719 js_global_function = 717 js_global_function =
720 factory->CreateApiFunction(js_global_constructor, 718 factory()->CreateApiFunction(js_global_constructor,
721 factory->InnerGlobalObject); 719 factory()->InnerGlobalObject);
722 } 720 }
723 721
724 js_global_function->initial_map()->set_is_hidden_prototype(); 722 js_global_function->initial_map()->set_is_hidden_prototype();
725 Handle<GlobalObject> inner_global = 723 Handle<GlobalObject> inner_global =
726 factory->NewGlobalObject(js_global_function); 724 factory()->NewGlobalObject(js_global_function);
727 if (inner_global_out != NULL) { 725 if (inner_global_out != NULL) {
728 *inner_global_out = inner_global; 726 *inner_global_out = inner_global;
729 } 727 }
730 728
731 // Step 2: create or re-initialize the global proxy object. 729 // Step 2: create or re-initialize the global proxy object.
732 Handle<JSFunction> global_proxy_function; 730 Handle<JSFunction> global_proxy_function;
733 if (global_template.IsEmpty()) { 731 if (global_template.IsEmpty()) {
734 Handle<String> name = Handle<String>(heap->empty_symbol()); 732 Handle<String> name = Handle<String>(heap()->empty_symbol());
735 Handle<Code> code = Handle<Code>(isolate->builtins()->builtin( 733 Handle<Code> code = Handle<Code>(isolate()->builtins()->builtin(
736 Builtins::kIllegal)); 734 Builtins::kIllegal));
737 global_proxy_function = 735 global_proxy_function =
738 factory->NewFunction(name, JS_GLOBAL_PROXY_TYPE, 736 factory()->NewFunction(name, JS_GLOBAL_PROXY_TYPE,
739 JSGlobalProxy::kSize, code, true); 737 JSGlobalProxy::kSize, code, true);
740 } else { 738 } else {
741 Handle<ObjectTemplateInfo> data = 739 Handle<ObjectTemplateInfo> data =
742 v8::Utils::OpenHandle(*global_template); 740 v8::Utils::OpenHandle(*global_template);
743 Handle<FunctionTemplateInfo> global_constructor( 741 Handle<FunctionTemplateInfo> global_constructor(
744 FunctionTemplateInfo::cast(data->constructor())); 742 FunctionTemplateInfo::cast(data->constructor()));
745 global_proxy_function = 743 global_proxy_function =
746 factory->CreateApiFunction(global_constructor, 744 factory()->CreateApiFunction(global_constructor,
747 factory->OuterGlobalObject); 745 factory()->OuterGlobalObject);
748 } 746 }
749 747
750 Handle<String> global_name = factory->LookupAsciiSymbol("global"); 748 Handle<String> global_name = factory()->LookupAsciiSymbol("global");
751 global_proxy_function->shared()->set_instance_class_name(*global_name); 749 global_proxy_function->shared()->set_instance_class_name(*global_name);
752 global_proxy_function->initial_map()->set_is_access_check_needed(true); 750 global_proxy_function->initial_map()->set_is_access_check_needed(true);
753 751
754 // Set global_proxy.__proto__ to js_global after ConfigureGlobalObjects 752 // Set global_proxy.__proto__ to js_global after ConfigureGlobalObjects
755 // Return the global proxy. 753 // Return the global proxy.
756 754
757 if (global_object.location() != NULL) { 755 if (global_object.location() != NULL) {
758 ASSERT(global_object->IsJSGlobalProxy()); 756 ASSERT(global_object->IsJSGlobalProxy());
759 return ReinitializeJSGlobalProxy( 757 return ReinitializeJSGlobalProxy(
760 global_proxy_function, 758 global_proxy_function,
761 Handle<JSGlobalProxy>::cast(global_object)); 759 Handle<JSGlobalProxy>::cast(global_object));
762 } else { 760 } else {
763 return Handle<JSGlobalProxy>::cast( 761 return Handle<JSGlobalProxy>::cast(
764 factory->NewJSObject(global_proxy_function, TENURED)); 762 factory()->NewJSObject(global_proxy_function, TENURED));
765 } 763 }
766 } 764 }
767 765
768 766
769 void Genesis::HookUpGlobalProxy(Handle<GlobalObject> inner_global, 767 void Genesis::HookUpGlobalProxy(Handle<GlobalObject> inner_global,
770 Handle<JSGlobalProxy> global_proxy) { 768 Handle<JSGlobalProxy> global_proxy) {
771 // Set the global context for the global object. 769 // Set the global context for the global object.
772 inner_global->set_global_context(*global_context()); 770 inner_global->set_global_context(*global_context());
773 inner_global->set_global_receiver(*global_proxy); 771 inner_global->set_global_receiver(*global_proxy);
774 global_proxy->set_context(*global_context()); 772 global_proxy->set_context(*global_context());
775 global_context()->set_global_proxy(*global_proxy); 773 global_context()->set_global_proxy(*global_proxy);
776 } 774 }
777 775
778 776
779 void Genesis::HookUpInnerGlobal(Handle<GlobalObject> inner_global) { 777 void Genesis::HookUpInnerGlobal(Handle<GlobalObject> inner_global) {
780 Handle<GlobalObject> inner_global_from_snapshot( 778 Handle<GlobalObject> inner_global_from_snapshot(
781 GlobalObject::cast(global_context_->extension())); 779 GlobalObject::cast(global_context_->extension()));
782 Handle<JSBuiltinsObject> builtins_global(global_context_->builtins()); 780 Handle<JSBuiltinsObject> builtins_global(global_context_->builtins());
783 global_context_->set_extension(*inner_global); 781 global_context_->set_extension(*inner_global);
784 global_context_->set_global(*inner_global); 782 global_context_->set_global(*inner_global);
785 global_context_->set_security_token(*inner_global); 783 global_context_->set_security_token(*inner_global);
786 static const PropertyAttributes attributes = 784 static const PropertyAttributes attributes =
787 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); 785 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE);
788 ForceSetProperty(builtins_global, 786 ForceSetProperty(builtins_global,
789 FACTORY->LookupAsciiSymbol("global"), 787 factory()->LookupAsciiSymbol("global"),
790 inner_global, 788 inner_global,
791 attributes); 789 attributes);
792 // Setup the reference from the global object to the builtins object. 790 // Setup the reference from the global object to the builtins object.
793 JSGlobalObject::cast(*inner_global)->set_builtins(*builtins_global); 791 JSGlobalObject::cast(*inner_global)->set_builtins(*builtins_global);
794 TransferNamedProperties(inner_global_from_snapshot, inner_global); 792 TransferNamedProperties(inner_global_from_snapshot, inner_global);
795 TransferIndexedProperties(inner_global_from_snapshot, inner_global); 793 TransferIndexedProperties(inner_global_from_snapshot, inner_global);
796 } 794 }
797 795
798 796
799 // This is only called if we are not using snapshots. The equivalent 797 // This is only called if we are not using snapshots. The equivalent
800 // work in the snapshot case is done in HookUpInnerGlobal. 798 // work in the snapshot case is done in HookUpInnerGlobal.
801 void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global, 799 void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global,
802 Handle<JSFunction> empty_function) { 800 Handle<JSFunction> empty_function) {
803 // --- G l o b a l C o n t e x t --- 801 // --- G l o b a l C o n t e x t ---
804 // Use the empty function as closure (no scope info). 802 // Use the empty function as closure (no scope info).
805 global_context()->set_closure(*empty_function); 803 global_context()->set_closure(*empty_function);
806 global_context()->set_fcontext(*global_context()); 804 global_context()->set_fcontext(*global_context());
807 global_context()->set_previous(NULL); 805 global_context()->set_previous(NULL);
808 // Set extension and global object. 806 // Set extension and global object.
809 global_context()->set_extension(*inner_global); 807 global_context()->set_extension(*inner_global);
810 global_context()->set_global(*inner_global); 808 global_context()->set_global(*inner_global);
811 // Security setup: Set the security token of the global object to 809 // Security setup: Set the security token of the global object to
812 // its the inner global. This makes the security check between two 810 // its the inner global. This makes the security check between two
813 // different contexts fail by default even in case of global 811 // different contexts fail by default even in case of global
814 // object reinitialization. 812 // object reinitialization.
815 global_context()->set_security_token(*inner_global); 813 global_context()->set_security_token(*inner_global);
816 814
817 Isolate* isolate = Isolate::Current(); 815 Isolate* isolate = inner_global->GetIsolate();
818 Factory* factory = isolate->factory(); 816 Factory* factory = isolate->factory();
819 Heap* heap = isolate->heap(); 817 Heap* heap = isolate->heap();
820 818
821 Handle<String> object_name = Handle<String>(heap->Object_symbol()); 819 Handle<String> object_name = Handle<String>(heap->Object_symbol());
822 SetLocalPropertyNoThrow(inner_global, object_name, 820 SetLocalPropertyNoThrow(inner_global, object_name,
823 isolate->object_function(), DONT_ENUM); 821 isolate->object_function(), DONT_ENUM);
824 822
825 Handle<JSObject> global = Handle<JSObject>(global_context()->global()); 823 Handle<JSObject> global = Handle<JSObject>(global_context()->global());
826 824
827 // Install global Function object 825 // Install global Function object
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 } 1155 }
1158 1156
1159 // Initialize the out of memory slot. 1157 // Initialize the out of memory slot.
1160 global_context()->set_out_of_memory(heap->false_value()); 1158 global_context()->set_out_of_memory(heap->false_value());
1161 1159
1162 // Initialize the data slot. 1160 // Initialize the data slot.
1163 global_context()->set_data(heap->undefined_value()); 1161 global_context()->set_data(heap->undefined_value());
1164 } 1162 }
1165 1163
1166 1164
1167 bool Genesis::CompileBuiltin(int index) { 1165 bool Genesis::CompileBuiltin(Isolate* isolate, int index) {
1168 Vector<const char> name = Natives::GetScriptName(index); 1166 Vector<const char> name = Natives::GetScriptName(index);
1169 Handle<String> source_code = 1167 Handle<String> source_code =
1170 Isolate::Current()->bootstrapper()->NativesSourceLookup(index); 1168 isolate->bootstrapper()->NativesSourceLookup(index);
1171 return CompileNative(name, source_code); 1169 return CompileNative(name, source_code);
1172 } 1170 }
1173 1171
1174 1172
1175 bool Genesis::CompileNative(Vector<const char> name, Handle<String> source) { 1173 bool Genesis::CompileNative(Vector<const char> name, Handle<String> source) {
1176 HandleScope scope; 1174 HandleScope scope;
1177 Isolate* isolate = Isolate::Current(); 1175 Isolate* isolate = source->GetIsolate();
1178 #ifdef ENABLE_DEBUGGER_SUPPORT 1176 #ifdef ENABLE_DEBUGGER_SUPPORT
1179 isolate->debugger()->set_compiling_natives(true); 1177 isolate->debugger()->set_compiling_natives(true);
1180 #endif 1178 #endif
1181 bool result = CompileScriptCached(name, 1179 bool result = CompileScriptCached(name,
1182 source, 1180 source,
1183 NULL, 1181 NULL,
1184 NULL, 1182 NULL,
1185 Handle<Context>(isolate->context()), 1183 Handle<Context>(isolate->context()),
1186 true); 1184 true);
1187 ASSERT(isolate->has_pending_exception() != result); 1185 ASSERT(isolate->has_pending_exception() != result);
1188 if (!result) isolate->clear_pending_exception(); 1186 if (!result) isolate->clear_pending_exception();
1189 #ifdef ENABLE_DEBUGGER_SUPPORT 1187 #ifdef ENABLE_DEBUGGER_SUPPORT
1190 isolate->debugger()->set_compiling_natives(false); 1188 isolate->debugger()->set_compiling_natives(false);
1191 #endif 1189 #endif
1192 return result; 1190 return result;
1193 } 1191 }
1194 1192
1195 1193
1196 bool Genesis::CompileScriptCached(Vector<const char> name, 1194 bool Genesis::CompileScriptCached(Vector<const char> name,
1197 Handle<String> source, 1195 Handle<String> source,
1198 SourceCodeCache* cache, 1196 SourceCodeCache* cache,
1199 v8::Extension* extension, 1197 v8::Extension* extension,
1200 Handle<Context> top_context, 1198 Handle<Context> top_context,
1201 bool use_runtime_context) { 1199 bool use_runtime_context) {
1202 Factory* factory = Isolate::Current()->factory(); 1200 Factory* factory = source->GetIsolate()->factory();
1203 HandleScope scope; 1201 HandleScope scope;
1204 Handle<SharedFunctionInfo> function_info; 1202 Handle<SharedFunctionInfo> function_info;
1205 1203
1206 // If we can't find the function in the cache, we compile a new 1204 // If we can't find the function in the cache, we compile a new
1207 // function and insert it into the cache. 1205 // function and insert it into the cache.
1208 if (cache == NULL || !cache->Lookup(name, &function_info)) { 1206 if (cache == NULL || !cache->Lookup(name, &function_info)) {
1209 ASSERT(source->IsAsciiRepresentation()); 1207 ASSERT(source->IsAsciiRepresentation());
1210 Handle<String> script_name = factory->NewStringFromUtf8(name); 1208 Handle<String> script_name = factory->NewStringFromUtf8(name);
1211 function_info = Compiler::Compile( 1209 function_info = Compiler::Compile(
1212 source, 1210 source,
(...skipping 27 matching lines...) Expand all
1240 : top_context->global()); 1238 : top_context->global());
1241 bool has_pending_exception; 1239 bool has_pending_exception;
1242 Handle<Object> result = 1240 Handle<Object> result =
1243 Execution::Call(fun, receiver, 0, NULL, &has_pending_exception); 1241 Execution::Call(fun, receiver, 0, NULL, &has_pending_exception);
1244 if (has_pending_exception) return false; 1242 if (has_pending_exception) return false;
1245 return true; 1243 return true;
1246 } 1244 }
1247 1245
1248 1246
1249 #define INSTALL_NATIVE(Type, name, var) \ 1247 #define INSTALL_NATIVE(Type, name, var) \
1250 Handle<String> var##_name = factory->LookupAsciiSymbol(name); \ 1248 Handle<String> var##_name = factory()->LookupAsciiSymbol(name); \
1251 Object* var##_native = \ 1249 Object* var##_native = \
1252 global_context()->builtins()->GetPropertyNoExceptionThrown(*var##_name); \ 1250 global_context()->builtins()->GetPropertyNoExceptionThrown(*var##_name); \
1253 global_context()->set_##var(Type::cast(var##_native)); 1251 global_context()->set_##var(Type::cast(var##_native));
1254 1252
1255 1253
1256 void Genesis::InstallNativeFunctions() { 1254 void Genesis::InstallNativeFunctions() {
1257 Factory* factory = Isolate::Current()->factory();
1258 HandleScope scope; 1255 HandleScope scope;
1259 INSTALL_NATIVE(JSFunction, "CreateDate", create_date_fun); 1256 INSTALL_NATIVE(JSFunction, "CreateDate", create_date_fun);
1260 INSTALL_NATIVE(JSFunction, "ToNumber", to_number_fun); 1257 INSTALL_NATIVE(JSFunction, "ToNumber", to_number_fun);
1261 INSTALL_NATIVE(JSFunction, "ToString", to_string_fun); 1258 INSTALL_NATIVE(JSFunction, "ToString", to_string_fun);
1262 INSTALL_NATIVE(JSFunction, "ToDetailString", to_detail_string_fun); 1259 INSTALL_NATIVE(JSFunction, "ToDetailString", to_detail_string_fun);
1263 INSTALL_NATIVE(JSFunction, "ToObject", to_object_fun); 1260 INSTALL_NATIVE(JSFunction, "ToObject", to_object_fun);
1264 INSTALL_NATIVE(JSFunction, "ToInteger", to_integer_fun); 1261 INSTALL_NATIVE(JSFunction, "ToInteger", to_integer_fun);
1265 INSTALL_NATIVE(JSFunction, "ToUint32", to_uint32_fun); 1262 INSTALL_NATIVE(JSFunction, "ToUint32", to_uint32_fun);
1266 INSTALL_NATIVE(JSFunction, "ToInt32", to_int32_fun); 1263 INSTALL_NATIVE(JSFunction, "ToInt32", to_int32_fun);
1267 INSTALL_NATIVE(JSFunction, "GlobalEval", global_eval_fun); 1264 INSTALL_NATIVE(JSFunction, "GlobalEval", global_eval_fun);
1268 INSTALL_NATIVE(JSFunction, "Instantiate", instantiate_fun); 1265 INSTALL_NATIVE(JSFunction, "Instantiate", instantiate_fun);
1269 INSTALL_NATIVE(JSFunction, "ConfigureTemplateInstance", 1266 INSTALL_NATIVE(JSFunction, "ConfigureTemplateInstance",
1270 configure_instance_fun); 1267 configure_instance_fun);
1271 INSTALL_NATIVE(JSFunction, "GetStackTraceLine", get_stack_trace_line_fun); 1268 INSTALL_NATIVE(JSFunction, "GetStackTraceLine", get_stack_trace_line_fun);
1272 INSTALL_NATIVE(JSObject, "functionCache", function_cache); 1269 INSTALL_NATIVE(JSObject, "functionCache", function_cache);
1273 } 1270 }
1274 1271
1275 #undef INSTALL_NATIVE 1272 #undef INSTALL_NATIVE
1276 1273
1277 1274
1278 bool Genesis::InstallNatives() { 1275 bool Genesis::InstallNatives() {
1279 HandleScope scope; 1276 HandleScope scope;
1280 Isolate* isolate = Isolate::Current();
1281 Factory* factory = isolate->factory();
1282 Heap* heap = isolate->heap();
1283 1277
1284 // Create a function for the builtins object. Allocate space for the 1278 // Create a function for the builtins object. Allocate space for the
1285 // JavaScript builtins, a reference to the builtins object 1279 // JavaScript builtins, a reference to the builtins object
1286 // (itself) and a reference to the global_context directly in the object. 1280 // (itself) and a reference to the global_context directly in the object.
1287 Handle<Code> code = Handle<Code>( 1281 Handle<Code> code = Handle<Code>(
1288 isolate->builtins()->builtin(Builtins::kIllegal)); 1282 isolate()->builtins()->builtin(Builtins::kIllegal));
1289 Handle<JSFunction> builtins_fun = 1283 Handle<JSFunction> builtins_fun =
1290 factory->NewFunction(factory->empty_symbol(), JS_BUILTINS_OBJECT_TYPE, 1284 factory()->NewFunction(factory()->empty_symbol(),
1291 JSBuiltinsObject::kSize, code, true); 1285 JS_BUILTINS_OBJECT_TYPE,
1286 JSBuiltinsObject::kSize, code, true);
1292 1287
1293 Handle<String> name = factory->LookupAsciiSymbol("builtins"); 1288 Handle<String> name = factory()->LookupAsciiSymbol("builtins");
1294 builtins_fun->shared()->set_instance_class_name(*name); 1289 builtins_fun->shared()->set_instance_class_name(*name);
1295 1290
1296 // Allocate the builtins object. 1291 // Allocate the builtins object.
1297 Handle<JSBuiltinsObject> builtins = 1292 Handle<JSBuiltinsObject> builtins =
1298 Handle<JSBuiltinsObject>::cast(factory->NewGlobalObject(builtins_fun)); 1293 Handle<JSBuiltinsObject>::cast(factory()->NewGlobalObject(builtins_fun));
1299 builtins->set_builtins(*builtins); 1294 builtins->set_builtins(*builtins);
1300 builtins->set_global_context(*global_context()); 1295 builtins->set_global_context(*global_context());
1301 builtins->set_global_receiver(*builtins); 1296 builtins->set_global_receiver(*builtins);
1302 1297
1303 // Setup the 'global' properties of the builtins object. The 1298 // Setup the 'global' properties of the builtins object. The
1304 // 'global' property that refers to the global object is the only 1299 // 'global' property that refers to the global object is the only
1305 // way to get from code running in the builtins context to the 1300 // way to get from code running in the builtins context to the
1306 // global object. 1301 // global object.
1307 static const PropertyAttributes attributes = 1302 static const PropertyAttributes attributes =
1308 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); 1303 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE);
1309 Handle<String> global_symbol = factory->LookupAsciiSymbol("global"); 1304 Handle<String> global_symbol = factory()->LookupAsciiSymbol("global");
1310 Handle<Object> global_obj(global_context()->global()); 1305 Handle<Object> global_obj(global_context()->global());
1311 SetLocalPropertyNoThrow(builtins, global_symbol, global_obj, attributes); 1306 SetLocalPropertyNoThrow(builtins, global_symbol, global_obj, attributes);
1312 1307
1313 // Setup the reference from the global object to the builtins object. 1308 // Setup the reference from the global object to the builtins object.
1314 JSGlobalObject::cast(global_context()->global())->set_builtins(*builtins); 1309 JSGlobalObject::cast(global_context()->global())->set_builtins(*builtins);
1315 1310
1316 // Create a bridge function that has context in the global context. 1311 // Create a bridge function that has context in the global context.
1317 Handle<JSFunction> bridge = 1312 Handle<JSFunction> bridge =
1318 factory->NewFunction(factory->empty_symbol(), factory->undefined_value()); 1313 factory()->NewFunction(factory()->empty_symbol(), factory()->undefined_val ue());
Mads Ager (chromium) 2011/04/06 07:34:15 Line too long.
1319 ASSERT(bridge->context() == *isolate->global_context()); 1314 ASSERT(bridge->context() == *isolate()->global_context());
1320 1315
1321 // Allocate the builtins context. 1316 // Allocate the builtins context.
1322 Handle<Context> context = 1317 Handle<Context> context =
1323 factory->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, bridge); 1318 factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, bridge);
1324 context->set_global(*builtins); // override builtins global object 1319 context->set_global(*builtins); // override builtins global object
1325 1320
1326 global_context()->set_runtime_context(*context); 1321 global_context()->set_runtime_context(*context);
1327 1322
1328 { // -- S c r i p t 1323 { // -- S c r i p t
1329 // Builtin functions for Script. 1324 // Builtin functions for Script.
1330 Handle<JSFunction> script_fun = 1325 Handle<JSFunction> script_fun =
1331 InstallFunction(builtins, "Script", JS_VALUE_TYPE, JSValue::kSize, 1326 InstallFunction(builtins, "Script", JS_VALUE_TYPE, JSValue::kSize,
1332 isolate->initial_object_prototype(), 1327 isolate()->initial_object_prototype(),
1333 Builtins::kIllegal, false); 1328 Builtins::kIllegal, false);
1334 Handle<JSObject> prototype = 1329 Handle<JSObject> prototype =
1335 factory->NewJSObject(isolate->object_function(), TENURED); 1330 factory()->NewJSObject(isolate()->object_function(), TENURED);
1336 SetPrototype(script_fun, prototype); 1331 SetPrototype(script_fun, prototype);
1337 global_context()->set_script_function(*script_fun); 1332 global_context()->set_script_function(*script_fun);
1338 1333
1339 // Add 'source' and 'data' property to scripts. 1334 // Add 'source' and 'data' property to scripts.
1340 PropertyAttributes common_attributes = 1335 PropertyAttributes common_attributes =
1341 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); 1336 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
1342 Handle<Proxy> proxy_source = factory->NewProxy(&Accessors::ScriptSource); 1337 Handle<Proxy> proxy_source = factory()->NewProxy(&Accessors::ScriptSource);
1343 Handle<DescriptorArray> script_descriptors = 1338 Handle<DescriptorArray> script_descriptors =
1344 factory->CopyAppendProxyDescriptor( 1339 factory()->CopyAppendProxyDescriptor(
1345 factory->empty_descriptor_array(), 1340 factory()->empty_descriptor_array(),
1346 factory->LookupAsciiSymbol("source"), 1341 factory()->LookupAsciiSymbol("source"),
1347 proxy_source, 1342 proxy_source,
1348 common_attributes); 1343 common_attributes);
1349 Handle<Proxy> proxy_name = factory->NewProxy(&Accessors::ScriptName); 1344 Handle<Proxy> proxy_name = factory()->NewProxy(&Accessors::ScriptName);
1350 script_descriptors = 1345 script_descriptors =
1351 factory->CopyAppendProxyDescriptor( 1346 factory()->CopyAppendProxyDescriptor(
1352 script_descriptors, 1347 script_descriptors,
1353 factory->LookupAsciiSymbol("name"), 1348 factory()->LookupAsciiSymbol("name"),
1354 proxy_name, 1349 proxy_name,
1355 common_attributes); 1350 common_attributes);
1356 Handle<Proxy> proxy_id = factory->NewProxy(&Accessors::ScriptId); 1351 Handle<Proxy> proxy_id = factory()->NewProxy(&Accessors::ScriptId);
1357 script_descriptors = 1352 script_descriptors =
1358 factory->CopyAppendProxyDescriptor( 1353 factory()->CopyAppendProxyDescriptor(
1359 script_descriptors, 1354 script_descriptors,
1360 factory->LookupAsciiSymbol("id"), 1355 factory()->LookupAsciiSymbol("id"),
1361 proxy_id, 1356 proxy_id,
1362 common_attributes); 1357 common_attributes);
1363 Handle<Proxy> proxy_line_offset = 1358 Handle<Proxy> proxy_line_offset =
1364 factory->NewProxy(&Accessors::ScriptLineOffset); 1359 factory()->NewProxy(&Accessors::ScriptLineOffset);
1365 script_descriptors = 1360 script_descriptors =
1366 factory->CopyAppendProxyDescriptor( 1361 factory()->CopyAppendProxyDescriptor(
1367 script_descriptors, 1362 script_descriptors,
1368 factory->LookupAsciiSymbol("line_offset"), 1363 factory()->LookupAsciiSymbol("line_offset"),
1369 proxy_line_offset, 1364 proxy_line_offset,
1370 common_attributes); 1365 common_attributes);
1371 Handle<Proxy> proxy_column_offset = 1366 Handle<Proxy> proxy_column_offset =
1372 factory->NewProxy(&Accessors::ScriptColumnOffset); 1367 factory()->NewProxy(&Accessors::ScriptColumnOffset);
1373 script_descriptors = 1368 script_descriptors =
1374 factory->CopyAppendProxyDescriptor( 1369 factory()->CopyAppendProxyDescriptor(
1375 script_descriptors, 1370 script_descriptors,
1376 factory->LookupAsciiSymbol("column_offset"), 1371 factory()->LookupAsciiSymbol("column_offset"),
1377 proxy_column_offset, 1372 proxy_column_offset,
1378 common_attributes); 1373 common_attributes);
1379 Handle<Proxy> proxy_data = factory->NewProxy(&Accessors::ScriptData); 1374 Handle<Proxy> proxy_data = factory()->NewProxy(&Accessors::ScriptData);
1380 script_descriptors = 1375 script_descriptors =
1381 factory->CopyAppendProxyDescriptor( 1376 factory()->CopyAppendProxyDescriptor(
1382 script_descriptors, 1377 script_descriptors,
1383 factory->LookupAsciiSymbol("data"), 1378 factory()->LookupAsciiSymbol("data"),
1384 proxy_data, 1379 proxy_data,
1385 common_attributes); 1380 common_attributes);
1386 Handle<Proxy> proxy_type = factory->NewProxy(&Accessors::ScriptType); 1381 Handle<Proxy> proxy_type = factory()->NewProxy(&Accessors::ScriptType);
1387 script_descriptors = 1382 script_descriptors =
1388 factory->CopyAppendProxyDescriptor( 1383 factory()->CopyAppendProxyDescriptor(
1389 script_descriptors, 1384 script_descriptors,
1390 factory->LookupAsciiSymbol("type"), 1385 factory()->LookupAsciiSymbol("type"),
1391 proxy_type, 1386 proxy_type,
1392 common_attributes); 1387 common_attributes);
1393 Handle<Proxy> proxy_compilation_type = 1388 Handle<Proxy> proxy_compilation_type =
1394 factory->NewProxy(&Accessors::ScriptCompilationType); 1389 factory()->NewProxy(&Accessors::ScriptCompilationType);
1395 script_descriptors = 1390 script_descriptors =
1396 factory->CopyAppendProxyDescriptor( 1391 factory()->CopyAppendProxyDescriptor(
1397 script_descriptors, 1392 script_descriptors,
1398 factory->LookupAsciiSymbol("compilation_type"), 1393 factory()->LookupAsciiSymbol("compilation_type"),
1399 proxy_compilation_type, 1394 proxy_compilation_type,
1400 common_attributes); 1395 common_attributes);
1401 Handle<Proxy> proxy_line_ends = 1396 Handle<Proxy> proxy_line_ends =
1402 factory->NewProxy(&Accessors::ScriptLineEnds); 1397 factory()->NewProxy(&Accessors::ScriptLineEnds);
1403 script_descriptors = 1398 script_descriptors =
1404 factory->CopyAppendProxyDescriptor( 1399 factory()->CopyAppendProxyDescriptor(
1405 script_descriptors, 1400 script_descriptors,
1406 factory->LookupAsciiSymbol("line_ends"), 1401 factory()->LookupAsciiSymbol("line_ends"),
1407 proxy_line_ends, 1402 proxy_line_ends,
1408 common_attributes); 1403 common_attributes);
1409 Handle<Proxy> proxy_context_data = 1404 Handle<Proxy> proxy_context_data =
1410 factory->NewProxy(&Accessors::ScriptContextData); 1405 factory()->NewProxy(&Accessors::ScriptContextData);
1411 script_descriptors = 1406 script_descriptors =
1412 factory->CopyAppendProxyDescriptor( 1407 factory()->CopyAppendProxyDescriptor(
1413 script_descriptors, 1408 script_descriptors,
1414 factory->LookupAsciiSymbol("context_data"), 1409 factory()->LookupAsciiSymbol("context_data"),
1415 proxy_context_data, 1410 proxy_context_data,
1416 common_attributes); 1411 common_attributes);
1417 Handle<Proxy> proxy_eval_from_script = 1412 Handle<Proxy> proxy_eval_from_script =
1418 factory->NewProxy(&Accessors::ScriptEvalFromScript); 1413 factory()->NewProxy(&Accessors::ScriptEvalFromScript);
1419 script_descriptors = 1414 script_descriptors =
1420 factory->CopyAppendProxyDescriptor( 1415 factory()->CopyAppendProxyDescriptor(
1421 script_descriptors, 1416 script_descriptors,
1422 factory->LookupAsciiSymbol("eval_from_script"), 1417 factory()->LookupAsciiSymbol("eval_from_script"),
1423 proxy_eval_from_script, 1418 proxy_eval_from_script,
1424 common_attributes); 1419 common_attributes);
1425 Handle<Proxy> proxy_eval_from_script_position = 1420 Handle<Proxy> proxy_eval_from_script_position =
1426 factory->NewProxy(&Accessors::ScriptEvalFromScriptPosition); 1421 factory()->NewProxy(&Accessors::ScriptEvalFromScriptPosition);
1427 script_descriptors = 1422 script_descriptors =
1428 factory->CopyAppendProxyDescriptor( 1423 factory()->CopyAppendProxyDescriptor(
1429 script_descriptors, 1424 script_descriptors,
1430 factory->LookupAsciiSymbol("eval_from_script_position"), 1425 factory()->LookupAsciiSymbol("eval_from_script_position"),
1431 proxy_eval_from_script_position, 1426 proxy_eval_from_script_position,
1432 common_attributes); 1427 common_attributes);
1433 Handle<Proxy> proxy_eval_from_function_name = 1428 Handle<Proxy> proxy_eval_from_function_name =
1434 factory->NewProxy(&Accessors::ScriptEvalFromFunctionName); 1429 factory()->NewProxy(&Accessors::ScriptEvalFromFunctionName);
1435 script_descriptors = 1430 script_descriptors =
1436 factory->CopyAppendProxyDescriptor( 1431 factory()->CopyAppendProxyDescriptor(
1437 script_descriptors, 1432 script_descriptors,
1438 factory->LookupAsciiSymbol("eval_from_function_name"), 1433 factory()->LookupAsciiSymbol("eval_from_function_name"),
1439 proxy_eval_from_function_name, 1434 proxy_eval_from_function_name,
1440 common_attributes); 1435 common_attributes);
1441 1436
1442 Handle<Map> script_map = Handle<Map>(script_fun->initial_map()); 1437 Handle<Map> script_map = Handle<Map>(script_fun->initial_map());
1443 script_map->set_instance_descriptors(*script_descriptors); 1438 script_map->set_instance_descriptors(*script_descriptors);
1444 1439
1445 // Allocate the empty script. 1440 // Allocate the empty script.
1446 Handle<Script> script = factory->NewScript(factory->empty_string()); 1441 Handle<Script> script = factory()->NewScript(factory()->empty_string());
1447 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); 1442 script->set_type(Smi::FromInt(Script::TYPE_NATIVE));
1448 heap->public_set_empty_script(*script); 1443 heap()->public_set_empty_script(*script);
1449 } 1444 }
1450 { 1445 {
1451 // Builtin function for OpaqueReference -- a JSValue-based object, 1446 // Builtin function for OpaqueReference -- a JSValue-based object,
1452 // that keeps its field isolated from JavaScript code. It may store 1447 // that keeps its field isolate()d from JavaScript code. It may store
Mads Ager (chromium) 2011/04/06 07:34:15 Whoops. :)
1453 // objects, that JavaScript code may not access. 1448 // objects, that JavaScript code may not access.
1454 Handle<JSFunction> opaque_reference_fun = 1449 Handle<JSFunction> opaque_reference_fun =
1455 InstallFunction(builtins, "OpaqueReference", JS_VALUE_TYPE, 1450 InstallFunction(builtins, "OpaqueReference", JS_VALUE_TYPE,
1456 JSValue::kSize, 1451 JSValue::kSize,
1457 isolate->initial_object_prototype(), 1452 isolate()->initial_object_prototype(),
1458 Builtins::kIllegal, false); 1453 Builtins::kIllegal, false);
1459 Handle<JSObject> prototype = 1454 Handle<JSObject> prototype =
1460 factory->NewJSObject(isolate->object_function(), TENURED); 1455 factory()->NewJSObject(isolate()->object_function(), TENURED);
1461 SetPrototype(opaque_reference_fun, prototype); 1456 SetPrototype(opaque_reference_fun, prototype);
1462 global_context()->set_opaque_reference_function(*opaque_reference_fun); 1457 global_context()->set_opaque_reference_function(*opaque_reference_fun);
1463 } 1458 }
1464 1459
1465 { // --- I n t e r n a l A r r a y --- 1460 { // --- I n t e r n a l A r r a y ---
1466 // An array constructor on the builtins object that works like 1461 // An array constructor on the builtins object that works like
1467 // the public Array constructor, except that its prototype 1462 // the public Array constructor, except that its prototype
1468 // doesn't inherit from Object.prototype. 1463 // doesn't inherit from Object.prototype.
1469 // To be used only for internal work by builtins. Instances 1464 // To be used only for internal work by builtins. Instances
1470 // must not be leaked to user code. 1465 // must not be leaked to user code.
1471 // Only works correctly when called as a constructor. The normal 1466 // Only works correctly when called as a constructor. The normal
1472 // Array code uses Array.prototype as prototype when called as 1467 // Array code uses Array.prototype as prototype when called as
1473 // a function. 1468 // a function.
1474 Handle<JSFunction> array_function = 1469 Handle<JSFunction> array_function =
1475 InstallFunction(builtins, 1470 InstallFunction(builtins,
1476 "InternalArray", 1471 "InternalArray",
1477 JS_ARRAY_TYPE, 1472 JS_ARRAY_TYPE,
1478 JSArray::kSize, 1473 JSArray::kSize,
1479 isolate->initial_object_prototype(), 1474 isolate()->initial_object_prototype(),
1480 Builtins::kArrayCode, 1475 Builtins::kArrayCode,
1481 true); 1476 true);
1482 Handle<JSObject> prototype = 1477 Handle<JSObject> prototype =
1483 factory->NewJSObject(isolate->object_function(), TENURED); 1478 factory()->NewJSObject(isolate()->object_function(), TENURED);
1484 SetPrototype(array_function, prototype); 1479 SetPrototype(array_function, prototype);
1485 1480
1486 array_function->shared()->set_construct_stub( 1481 array_function->shared()->set_construct_stub(
1487 isolate->builtins()->builtin(Builtins::kArrayConstructCode)); 1482 isolate()->builtins()->builtin(Builtins::kArrayConstructCode));
1488 array_function->shared()->DontAdaptArguments(); 1483 array_function->shared()->DontAdaptArguments();
1489 1484
1490 // Make "length" magic on instances. 1485 // Make "length" magic on instances.
1491 Handle<DescriptorArray> array_descriptors = 1486 Handle<DescriptorArray> array_descriptors =
1492 factory->CopyAppendProxyDescriptor( 1487 factory()->CopyAppendProxyDescriptor(
1493 factory->empty_descriptor_array(), 1488 factory()->empty_descriptor_array(),
1494 factory->length_symbol(), 1489 factory()->length_symbol(),
1495 factory->NewProxy(&Accessors::ArrayLength), 1490 factory()->NewProxy(&Accessors::ArrayLength),
1496 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE)); 1491 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE));
1497 1492
1498 array_function->initial_map()->set_instance_descriptors( 1493 array_function->initial_map()->set_instance_descriptors(
1499 *array_descriptors); 1494 *array_descriptors);
1500 } 1495 }
1501 1496
1502 if (FLAG_disable_native_files) { 1497 if (FLAG_disable_native_files) {
1503 PrintF("Warning: Running without installed natives!\n"); 1498 PrintF("Warning: Running without installed natives!\n");
1504 return true; 1499 return true;
1505 } 1500 }
1506 1501
1507 // Install natives. 1502 // Install natives.
1508 for (int i = Natives::GetDebuggerCount(); 1503 for (int i = Natives::GetDebuggerCount();
1509 i < Natives::GetBuiltinsCount(); 1504 i < Natives::GetBuiltinsCount();
1510 i++) { 1505 i++) {
1511 Vector<const char> name = Natives::GetScriptName(i); 1506 Vector<const char> name = Natives::GetScriptName(i);
1512 if (!CompileBuiltin(i)) return false; 1507 if (!CompileBuiltin(isolate(), i)) return false;
1513 // TODO(ager): We really only need to install the JS builtin 1508 // TODO(ager): We really only need to install the JS builtin
1514 // functions on the builtins object after compiling and running 1509 // functions on the builtins object after compiling and running
1515 // runtime.js. 1510 // runtime.js.
1516 if (!InstallJSBuiltins(builtins)) return false; 1511 if (!InstallJSBuiltins(builtins)) return false;
1517 } 1512 }
1518 1513
1519 InstallNativeFunctions(); 1514 InstallNativeFunctions();
1520 1515
1521 // Store the map for the string prototype after the natives has been compiled 1516 // Store the map for the string prototype after the natives has been compiled
1522 // and the String function has been setup. 1517 // and the String function has been setup.
1523 Handle<JSFunction> string_function(global_context()->string_function()); 1518 Handle<JSFunction> string_function(global_context()->string_function());
1524 ASSERT(JSObject::cast( 1519 ASSERT(JSObject::cast(
1525 string_function->initial_map()->prototype())->HasFastProperties()); 1520 string_function->initial_map()->prototype())->HasFastProperties());
1526 global_context()->set_string_function_prototype_map( 1521 global_context()->set_string_function_prototype_map(
1527 HeapObject::cast(string_function->initial_map()->prototype())->map()); 1522 HeapObject::cast(string_function->initial_map()->prototype())->map());
1528 1523
1529 InstallBuiltinFunctionIds(); 1524 InstallBuiltinFunctionIds();
1530 1525
1531 // Install Function.prototype.call and apply. 1526 // Install Function.prototype.call and apply.
1532 { Handle<String> key = factory->function_class_symbol(); 1527 { Handle<String> key = factory()->function_class_symbol();
1533 Handle<JSFunction> function = 1528 Handle<JSFunction> function =
1534 Handle<JSFunction>::cast(GetProperty(isolate->global(), key)); 1529 Handle<JSFunction>::cast(GetProperty(isolate()->global(), key));
1535 Handle<JSObject> proto = 1530 Handle<JSObject> proto =
1536 Handle<JSObject>(JSObject::cast(function->instance_prototype())); 1531 Handle<JSObject>(JSObject::cast(function->instance_prototype()));
1537 1532
1538 // Install the call and the apply functions. 1533 // Install the call and the apply functions.
1539 Handle<JSFunction> call = 1534 Handle<JSFunction> call =
1540 InstallFunction(proto, "call", JS_OBJECT_TYPE, JSObject::kHeaderSize, 1535 InstallFunction(proto, "call", JS_OBJECT_TYPE, JSObject::kHeaderSize,
1541 Handle<JSObject>::null(), 1536 Handle<JSObject>::null(),
1542 Builtins::kFunctionCall, 1537 Builtins::kFunctionCall,
1543 false); 1538 false);
1544 Handle<JSFunction> apply = 1539 Handle<JSFunction> apply =
(...skipping 21 matching lines...) Expand all
1566 { 1561 {
1567 // RegExpResult initial map. 1562 // RegExpResult initial map.
1568 1563
1569 // Find global.Array.prototype to inherit from. 1564 // Find global.Array.prototype to inherit from.
1570 Handle<JSFunction> array_constructor(global_context()->array_function()); 1565 Handle<JSFunction> array_constructor(global_context()->array_function());
1571 Handle<JSObject> array_prototype( 1566 Handle<JSObject> array_prototype(
1572 JSObject::cast(array_constructor->instance_prototype())); 1567 JSObject::cast(array_constructor->instance_prototype()));
1573 1568
1574 // Add initial map. 1569 // Add initial map.
1575 Handle<Map> initial_map = 1570 Handle<Map> initial_map =
1576 factory->NewMap(JS_ARRAY_TYPE, JSRegExpResult::kSize); 1571 factory()->NewMap(JS_ARRAY_TYPE, JSRegExpResult::kSize);
1577 initial_map->set_constructor(*array_constructor); 1572 initial_map->set_constructor(*array_constructor);
1578 1573
1579 // Set prototype on map. 1574 // Set prototype on map.
1580 initial_map->set_non_instance_prototype(false); 1575 initial_map->set_non_instance_prototype(false);
1581 initial_map->set_prototype(*array_prototype); 1576 initial_map->set_prototype(*array_prototype);
1582 1577
1583 // Update map with length accessor from Array and add "index" and "input". 1578 // Update map with length accessor from Array and add "index" and "input".
1584 Handle<Map> array_map(global_context()->js_array_map()); 1579 Handle<Map> array_map(global_context()->js_array_map());
1585 Handle<DescriptorArray> array_descriptors( 1580 Handle<DescriptorArray> array_descriptors(
1586 array_map->instance_descriptors()); 1581 array_map->instance_descriptors());
1587 ASSERT_EQ(1, array_descriptors->number_of_descriptors()); 1582 ASSERT_EQ(1, array_descriptors->number_of_descriptors());
1588 1583
1589 Handle<DescriptorArray> reresult_descriptors = 1584 Handle<DescriptorArray> reresult_descriptors =
1590 factory->NewDescriptorArray(3); 1585 factory()->NewDescriptorArray(3);
1591 1586
1592 reresult_descriptors->CopyFrom(0, *array_descriptors, 0); 1587 reresult_descriptors->CopyFrom(0, *array_descriptors, 0);
1593 1588
1594 int enum_index = 0; 1589 int enum_index = 0;
1595 { 1590 {
1596 FieldDescriptor index_field(heap->index_symbol(), 1591 FieldDescriptor index_field(heap()->index_symbol(),
1597 JSRegExpResult::kIndexIndex, 1592 JSRegExpResult::kIndexIndex,
1598 NONE, 1593 NONE,
1599 enum_index++); 1594 enum_index++);
1600 reresult_descriptors->Set(1, &index_field); 1595 reresult_descriptors->Set(1, &index_field);
1601 } 1596 }
1602 1597
1603 { 1598 {
1604 FieldDescriptor input_field(heap->input_symbol(), 1599 FieldDescriptor input_field(heap()->input_symbol(),
1605 JSRegExpResult::kInputIndex, 1600 JSRegExpResult::kInputIndex,
1606 NONE, 1601 NONE,
1607 enum_index++); 1602 enum_index++);
1608 reresult_descriptors->Set(2, &input_field); 1603 reresult_descriptors->Set(2, &input_field);
1609 } 1604 }
1610 reresult_descriptors->Sort(); 1605 reresult_descriptors->Sort();
1611 1606
1612 initial_map->set_inobject_properties(2); 1607 initial_map->set_inobject_properties(2);
1613 initial_map->set_pre_allocated_property_fields(2); 1608 initial_map->set_pre_allocated_property_fields(2);
1614 initial_map->set_unused_property_fields(0); 1609 initial_map->set_unused_property_fields(0);
1615 initial_map->set_instance_descriptors(*reresult_descriptors); 1610 initial_map->set_instance_descriptors(*reresult_descriptors);
1616 1611
1617 global_context()->set_regexp_result_map(*initial_map); 1612 global_context()->set_regexp_result_map(*initial_map);
1618 } 1613 }
1619 1614
1620 1615
1621 #ifdef DEBUG 1616 #ifdef DEBUG
1622 builtins->Verify(); 1617 builtins->Verify();
1623 #endif 1618 #endif
1624 1619
1625 return true; 1620 return true;
1626 } 1621 }
1627 1622
1628 1623
1629 static Handle<JSObject> ResolveBuiltinIdHolder( 1624 static Handle<JSObject> ResolveBuiltinIdHolder(
1630 Handle<Context> global_context, 1625 Handle<Context> global_context,
1631 const char* holder_expr) { 1626 const char* holder_expr) {
1632 Factory* factory = Isolate::Current()->factory(); 1627 Factory* factory = global_context->GetIsolate()->factory();
1633 Handle<GlobalObject> global(global_context->global()); 1628 Handle<GlobalObject> global(global_context->global());
1634 const char* period_pos = strchr(holder_expr, '.'); 1629 const char* period_pos = strchr(holder_expr, '.');
1635 if (period_pos == NULL) { 1630 if (period_pos == NULL) {
1636 return Handle<JSObject>::cast( 1631 return Handle<JSObject>::cast(
1637 GetProperty(global, factory->LookupAsciiSymbol(holder_expr))); 1632 GetProperty(global, factory->LookupAsciiSymbol(holder_expr)));
1638 } 1633 }
1639 ASSERT_EQ(".prototype", period_pos); 1634 ASSERT_EQ(".prototype", period_pos);
1640 Vector<const char> property(holder_expr, 1635 Vector<const char> property(holder_expr,
1641 static_cast<int>(period_pos - holder_expr)); 1636 static_cast<int>(period_pos - holder_expr));
1642 Handle<JSFunction> function = Handle<JSFunction>::cast( 1637 Handle<JSFunction> function = Handle<JSFunction>::cast(
1643 GetProperty(global, factory->LookupSymbol(property))); 1638 GetProperty(global, factory->LookupSymbol(property)));
1644 return Handle<JSObject>(JSObject::cast(function->prototype())); 1639 return Handle<JSObject>(JSObject::cast(function->prototype()));
1645 } 1640 }
1646 1641
1647 1642
1648 static void InstallBuiltinFunctionId(Handle<JSObject> holder, 1643 static void InstallBuiltinFunctionId(Handle<JSObject> holder,
1649 const char* function_name, 1644 const char* function_name,
1650 BuiltinFunctionId id) { 1645 BuiltinFunctionId id) {
1651 Handle<String> name = FACTORY->LookupAsciiSymbol(function_name); 1646 Factory* factory = holder->GetIsolate()->factory();
1647 Handle<String> name = factory->LookupAsciiSymbol(function_name);
1652 Object* function_object = holder->GetProperty(*name)->ToObjectUnchecked(); 1648 Object* function_object = holder->GetProperty(*name)->ToObjectUnchecked();
1653 Handle<JSFunction> function(JSFunction::cast(function_object)); 1649 Handle<JSFunction> function(JSFunction::cast(function_object));
1654 function->shared()->set_function_data(Smi::FromInt(id)); 1650 function->shared()->set_function_data(Smi::FromInt(id));
1655 } 1651 }
1656 1652
1657 1653
1658 void Genesis::InstallBuiltinFunctionIds() { 1654 void Genesis::InstallBuiltinFunctionIds() {
1659 HandleScope scope; 1655 HandleScope scope;
1660 #define INSTALL_BUILTIN_ID(holder_expr, fun_name, name) \ 1656 #define INSTALL_BUILTIN_ID(holder_expr, fun_name, name) \
1661 { \ 1657 { \
1662 Handle<JSObject> holder = ResolveBuiltinIdHolder( \ 1658 Handle<JSObject> holder = ResolveBuiltinIdHolder( \
1663 global_context(), #holder_expr); \ 1659 global_context(), #holder_expr); \
1664 BuiltinFunctionId id = k##name; \ 1660 BuiltinFunctionId id = k##name; \
1665 InstallBuiltinFunctionId(holder, #fun_name, id); \ 1661 InstallBuiltinFunctionId(holder, #fun_name, id); \
1666 } 1662 }
1667 FUNCTIONS_WITH_ID_LIST(INSTALL_BUILTIN_ID) 1663 FUNCTIONS_WITH_ID_LIST(INSTALL_BUILTIN_ID)
1668 #undef INSTALL_BUILTIN_ID 1664 #undef INSTALL_BUILTIN_ID
1669 } 1665 }
1670 1666
1671 1667
1672 // Do not forget to update macros.py with named constant 1668 // Do not forget to update macros.py with named constant
1673 // of cache id. 1669 // of cache id.
1674 #define JSFUNCTION_RESULT_CACHE_LIST(F) \ 1670 #define JSFUNCTION_RESULT_CACHE_LIST(F) \
1675 F(16, global_context()->regexp_function()) 1671 F(16, global_context()->regexp_function())
1676 1672
1677 1673
1678 static FixedArray* CreateCache(int size, JSFunction* factory) { 1674 static FixedArray* CreateCache(int size, JSFunction* factory_function) {
1675 Factory* factory = factory_function->GetIsolate()->factory();
1679 // Caches are supposed to live for a long time, allocate in old space. 1676 // Caches are supposed to live for a long time, allocate in old space.
1680 int array_size = JSFunctionResultCache::kEntriesIndex + 2 * size; 1677 int array_size = JSFunctionResultCache::kEntriesIndex + 2 * size;
1681 // Cannot use cast as object is not fully initialized yet. 1678 // Cannot use cast as object is not fully initialized yet.
1682 JSFunctionResultCache* cache = reinterpret_cast<JSFunctionResultCache*>( 1679 JSFunctionResultCache* cache = reinterpret_cast<JSFunctionResultCache*>(
1683 *FACTORY->NewFixedArrayWithHoles(array_size, TENURED)); 1680 *factory->NewFixedArrayWithHoles(array_size, TENURED));
1684 cache->set(JSFunctionResultCache::kFactoryIndex, factory); 1681 cache->set(JSFunctionResultCache::kFactoryIndex, factory_function);
1685 cache->MakeZeroSize(); 1682 cache->MakeZeroSize();
1686 return cache; 1683 return cache;
1687 } 1684 }
1688 1685
1689 1686
1690 void Genesis::InstallJSFunctionResultCaches() { 1687 void Genesis::InstallJSFunctionResultCaches() {
1691 const int kNumberOfCaches = 0 + 1688 const int kNumberOfCaches = 0 +
1692 #define F(size, func) + 1 1689 #define F(size, func) + 1
1693 JSFUNCTION_RESULT_CACHE_LIST(F) 1690 JSFUNCTION_RESULT_CACHE_LIST(F)
1694 #undef F 1691 #undef F
(...skipping 18 matching lines...) Expand all
1713 1710
1714 void Genesis::InitializeNormalizedMapCaches() { 1711 void Genesis::InitializeNormalizedMapCaches() {
1715 Handle<FixedArray> array( 1712 Handle<FixedArray> array(
1716 FACTORY->NewFixedArray(NormalizedMapCache::kEntries, TENURED)); 1713 FACTORY->NewFixedArray(NormalizedMapCache::kEntries, TENURED));
1717 global_context()->set_normalized_map_cache(NormalizedMapCache::cast(*array)); 1714 global_context()->set_normalized_map_cache(NormalizedMapCache::cast(*array));
1718 } 1715 }
1719 1716
1720 1717
1721 bool Bootstrapper::InstallExtensions(Handle<Context> global_context, 1718 bool Bootstrapper::InstallExtensions(Handle<Context> global_context,
1722 v8::ExtensionConfiguration* extensions) { 1719 v8::ExtensionConfiguration* extensions) {
1723 Isolate* isolate = Isolate::Current(); 1720 Isolate* isolate = global_context->GetIsolate();
1724 BootstrapperActive active; 1721 BootstrapperActive active;
1725 SaveContext saved_context(isolate); 1722 SaveContext saved_context(isolate);
1726 isolate->set_context(*global_context); 1723 isolate->set_context(*global_context);
1727 if (!Genesis::InstallExtensions(global_context, extensions)) return false; 1724 if (!Genesis::InstallExtensions(global_context, extensions)) return false;
1728 Genesis::InstallSpecialObjects(global_context); 1725 Genesis::InstallSpecialObjects(global_context);
1729 return true; 1726 return true;
1730 } 1727 }
1731 1728
1732 1729
1733 void Genesis::InstallSpecialObjects(Handle<Context> global_context) { 1730 void Genesis::InstallSpecialObjects(Handle<Context> global_context) {
1734 Factory* factory = Isolate::Current()->factory(); 1731 Factory* factory = global_context->GetIsolate()->factory();
1735 HandleScope scope; 1732 HandleScope scope;
1736 Handle<JSGlobalObject> js_global( 1733 Handle<JSGlobalObject> js_global(
1737 JSGlobalObject::cast(global_context->global())); 1734 JSGlobalObject::cast(global_context->global()));
1738 // Expose the natives in global if a name for it is specified. 1735 // Expose the natives in global if a name for it is specified.
1739 if (FLAG_expose_natives_as != NULL && strlen(FLAG_expose_natives_as) != 0) { 1736 if (FLAG_expose_natives_as != NULL && strlen(FLAG_expose_natives_as) != 0) {
1740 Handle<String> natives_string = 1737 Handle<String> natives_string =
1741 factory->LookupAsciiSymbol(FLAG_expose_natives_as); 1738 factory->LookupAsciiSymbol(FLAG_expose_natives_as);
1742 SetLocalPropertyNoThrow(js_global, natives_string, 1739 SetLocalPropertyNoThrow(js_global, natives_string,
1743 Handle<JSObject>(js_global->builtins()), DONT_ENUM); 1740 Handle<JSObject>(js_global->builtins()), DONT_ENUM);
1744 } 1741 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 if (!result) { 1857 if (!result) {
1861 isolate->clear_pending_exception(); 1858 isolate->clear_pending_exception();
1862 } 1859 }
1863 current->set_state(v8::INSTALLED); 1860 current->set_state(v8::INSTALLED);
1864 return result; 1861 return result;
1865 } 1862 }
1866 1863
1867 1864
1868 bool Genesis::InstallJSBuiltins(Handle<JSBuiltinsObject> builtins) { 1865 bool Genesis::InstallJSBuiltins(Handle<JSBuiltinsObject> builtins) {
1869 HandleScope scope; 1866 HandleScope scope;
1867 Factory* factory = builtins->GetIsolate()->factory();
1870 for (int i = 0; i < Builtins::NumberOfJavaScriptBuiltins(); i++) { 1868 for (int i = 0; i < Builtins::NumberOfJavaScriptBuiltins(); i++) {
1871 Builtins::JavaScript id = static_cast<Builtins::JavaScript>(i); 1869 Builtins::JavaScript id = static_cast<Builtins::JavaScript>(i);
1872 Handle<String> name = FACTORY->LookupAsciiSymbol(Builtins::GetName(id)); 1870 Handle<String> name = factory->LookupAsciiSymbol(Builtins::GetName(id));
1873 Object* function_object = builtins->GetPropertyNoExceptionThrown(*name); 1871 Object* function_object = builtins->GetPropertyNoExceptionThrown(*name);
1874 Handle<JSFunction> function 1872 Handle<JSFunction> function
1875 = Handle<JSFunction>(JSFunction::cast(function_object)); 1873 = Handle<JSFunction>(JSFunction::cast(function_object));
1876 builtins->set_javascript_builtin(id, *function); 1874 builtins->set_javascript_builtin(id, *function);
1877 Handle<SharedFunctionInfo> shared 1875 Handle<SharedFunctionInfo> shared
1878 = Handle<SharedFunctionInfo>(function->shared()); 1876 = Handle<SharedFunctionInfo>(function->shared());
1879 if (!EnsureCompiled(shared, CLEAR_EXCEPTION)) return false; 1877 if (!EnsureCompiled(shared, CLEAR_EXCEPTION)) return false;
1880 // Set the code object on the function object. 1878 // Set the code object on the function object.
1881 function->ReplaceCode(function->shared()->code()); 1879 function->ReplaceCode(function->shared()->code());
1882 builtins->set_javascript_builtin_code(id, shared->code()); 1880 builtins->set_javascript_builtin_code(id, shared->code());
(...skipping 28 matching lines...) Expand all
1911 return true; 1909 return true;
1912 } 1910 }
1913 1911
1914 1912
1915 bool Genesis::ConfigureApiObject(Handle<JSObject> object, 1913 bool Genesis::ConfigureApiObject(Handle<JSObject> object,
1916 Handle<ObjectTemplateInfo> object_template) { 1914 Handle<ObjectTemplateInfo> object_template) {
1917 ASSERT(!object_template.is_null()); 1915 ASSERT(!object_template.is_null());
1918 ASSERT(object->IsInstanceOf( 1916 ASSERT(object->IsInstanceOf(
1919 FunctionTemplateInfo::cast(object_template->constructor()))); 1917 FunctionTemplateInfo::cast(object_template->constructor())));
1920 1918
1921 Isolate* isolate = Isolate::Current();
1922 bool pending_exception = false; 1919 bool pending_exception = false;
1923 Handle<JSObject> obj = 1920 Handle<JSObject> obj =
1924 Execution::InstantiateObject(object_template, &pending_exception); 1921 Execution::InstantiateObject(object_template, &pending_exception);
1925 if (pending_exception) { 1922 if (pending_exception) {
1926 ASSERT(isolate->has_pending_exception()); 1923 ASSERT(isolate()->has_pending_exception());
1927 isolate->clear_pending_exception(); 1924 isolate()->clear_pending_exception();
1928 return false; 1925 return false;
1929 } 1926 }
1930 TransferObject(obj, object); 1927 TransferObject(obj, object);
1931 return true; 1928 return true;
1932 } 1929 }
1933 1930
1934 1931
1935 void Genesis::TransferNamedProperties(Handle<JSObject> from, 1932 void Genesis::TransferNamedProperties(Handle<JSObject> from,
1936 Handle<JSObject> to) { 1933 Handle<JSObject> to) {
1937 if (from->HasFastProperties()) { 1934 if (from->HasFastProperties()) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2016 // Cloning the elements array is sufficient. 2013 // Cloning the elements array is sufficient.
2017 Handle<FixedArray> from_elements = 2014 Handle<FixedArray> from_elements =
2018 Handle<FixedArray>(FixedArray::cast(from->elements())); 2015 Handle<FixedArray>(FixedArray::cast(from->elements()));
2019 Handle<FixedArray> to_elements = FACTORY->CopyFixedArray(from_elements); 2016 Handle<FixedArray> to_elements = FACTORY->CopyFixedArray(from_elements);
2020 to->set_elements(*to_elements); 2017 to->set_elements(*to_elements);
2021 } 2018 }
2022 2019
2023 2020
2024 void Genesis::TransferObject(Handle<JSObject> from, Handle<JSObject> to) { 2021 void Genesis::TransferObject(Handle<JSObject> from, Handle<JSObject> to) {
2025 HandleScope outer; 2022 HandleScope outer;
2023 Factory* factory = from->GetIsolate()->factory();
2026 2024
2027 ASSERT(!from->IsJSArray()); 2025 ASSERT(!from->IsJSArray());
2028 ASSERT(!to->IsJSArray()); 2026 ASSERT(!to->IsJSArray());
2029 2027
2030 TransferNamedProperties(from, to); 2028 TransferNamedProperties(from, to);
2031 TransferIndexedProperties(from, to); 2029 TransferIndexedProperties(from, to);
2032 2030
2033 // Transfer the prototype (new map is needed). 2031 // Transfer the prototype (new map is needed).
2034 Handle<Map> old_to_map = Handle<Map>(to->map()); 2032 Handle<Map> old_to_map = Handle<Map>(to->map());
2035 Handle<Map> new_to_map = FACTORY->CopyMapDropTransitions(old_to_map); 2033 Handle<Map> new_to_map = factory->CopyMapDropTransitions(old_to_map);
2036 new_to_map->set_prototype(from->map()->prototype()); 2034 new_to_map->set_prototype(from->map()->prototype());
2037 to->set_map(*new_to_map); 2035 to->set_map(*new_to_map);
2038 } 2036 }
2039 2037
2040 2038
2041 void Genesis::MakeFunctionInstancePrototypeWritable() { 2039 void Genesis::MakeFunctionInstancePrototypeWritable() {
2042 // The maps with writable prototype are created in CreateEmptyFunction 2040 // The maps with writable prototype are created in CreateEmptyFunction
2043 // and CreateStrictModeFunctionMaps respectively. Initially the maps are 2041 // and CreateStrictModeFunctionMaps respectively. Initially the maps are
2044 // created with read-only prototype for JS builtins processing. 2042 // created with read-only prototype for JS builtins processing.
2045 ASSERT(!function_instance_map_writable_prototype_.is_null()); 2043 ASSERT(!function_instance_map_writable_prototype_.is_null());
2046 ASSERT(!strict_mode_function_instance_map_writable_prototype_.is_null()); 2044 ASSERT(!strict_mode_function_instance_map_writable_prototype_.is_null());
2047 2045
2048 // Replace function instance maps to make prototype writable. 2046 // Replace function instance maps to make prototype writable.
2049 global_context()->set_function_map( 2047 global_context()->set_function_map(
2050 *function_instance_map_writable_prototype_); 2048 *function_instance_map_writable_prototype_);
2051 global_context()->set_strict_mode_function_map( 2049 global_context()->set_strict_mode_function_map(
2052 *strict_mode_function_instance_map_writable_prototype_); 2050 *strict_mode_function_instance_map_writable_prototype_);
2053 } 2051 }
2054 2052
2055 2053
2056 Genesis::Genesis(Handle<Object> global_object, 2054 Genesis::Genesis(Isolate* isolate,
2055 Handle<Object> global_object,
2057 v8::Handle<v8::ObjectTemplate> global_template, 2056 v8::Handle<v8::ObjectTemplate> global_template,
2058 v8::ExtensionConfiguration* extensions) { 2057 v8::ExtensionConfiguration* extensions) {
2059 Isolate* isolate = Isolate::Current();
2060 result_ = Handle<Context>::null(); 2058 result_ = Handle<Context>::null();
2061 // If V8 isn't running and cannot be initialized, just return. 2059 // If V8 isn't running and cannot be initialized, just return.
2062 if (!V8::IsRunning() && !V8::Initialize(NULL)) return; 2060 if (!V8::IsRunning() && !V8::Initialize(NULL)) return;
2063 2061
2064 // Before creating the roots we must save the context and restore it 2062 // Before creating the roots we must save the context and restore it
2065 // on all function exits. 2063 // on all function exits.
2066 HandleScope scope; 2064 HandleScope scope;
2067 SaveContext saved_context(isolate); 2065 SaveContext saved_context(isolate);
2068 2066
2069 Handle<Context> new_context = Snapshot::NewContextFromSnapshot(); 2067 Handle<Context> new_context = Snapshot::NewContextFromSnapshot();
2070 if (!new_context.is_null()) { 2068 if (!new_context.is_null()) {
2071 global_context_ = 2069 global_context_ =
2072 Handle<Context>::cast(isolate->global_handles()->Create(*new_context)); 2070 Handle<Context>::cast(isolate->global_handles()->Create(*new_context));
2073 AddToWeakGlobalContextList(*global_context_); 2071 AddToWeakGlobalContextList(*global_context_);
2074 isolate->set_context(*global_context_); 2072 isolate->set_context(*global_context_);
2075 isolate->counters()->contexts_created_by_snapshot()->Increment(); 2073 isolate->counters()->contexts_created_by_snapshot()->Increment();
2076 Handle<GlobalObject> inner_global; 2074 Handle<GlobalObject> inner_global;
2077 Handle<JSGlobalProxy> global_proxy = 2075 Handle<JSGlobalProxy> global_proxy =
2078 CreateNewGlobals(global_template, 2076 CreateNewGlobals(global_template,
2079 global_object, 2077 global_object,
2080 &inner_global); 2078 &inner_global);
2081 2079
2082 HookUpGlobalProxy(inner_global, global_proxy); 2080 HookUpGlobalProxy(inner_global, global_proxy);
2083 HookUpInnerGlobal(inner_global); 2081 HookUpInnerGlobal(inner_global);
2084 2082
2085 if (!ConfigureGlobalObjects(global_template)) return; 2083 if (!ConfigureGlobalObjects(global_template)) return;
2086 } else { 2084 } else {
2087 // We get here if there was no context snapshot. 2085 // We get here if there was no context snapshot.
2088 CreateRoots(); 2086 CreateRoots();
2089 Handle<JSFunction> empty_function = CreateEmptyFunction(); 2087 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate);
2090 CreateStrictModeFunctionMaps(empty_function); 2088 CreateStrictModeFunctionMaps(empty_function);
2091 Handle<GlobalObject> inner_global; 2089 Handle<GlobalObject> inner_global;
2092 Handle<JSGlobalProxy> global_proxy = 2090 Handle<JSGlobalProxy> global_proxy =
2093 CreateNewGlobals(global_template, global_object, &inner_global); 2091 CreateNewGlobals(global_template, global_object, &inner_global);
2094 HookUpGlobalProxy(inner_global, global_proxy); 2092 HookUpGlobalProxy(inner_global, global_proxy);
2095 InitializeGlobal(inner_global, empty_function); 2093 InitializeGlobal(inner_global, empty_function);
2096 InstallJSFunctionResultCaches(); 2094 InstallJSFunctionResultCaches();
2097 InitializeNormalizedMapCaches(); 2095 InitializeNormalizedMapCaches();
2098 if (!InstallNatives()) return; 2096 if (!InstallNatives()) return;
2099 2097
(...skipping 29 matching lines...) Expand all
2129 return from + sizeof(NestingCounterType); 2127 return from + sizeof(NestingCounterType);
2130 } 2128 }
2131 2129
2132 2130
2133 // Called when the top-level V8 mutex is destroyed. 2131 // Called when the top-level V8 mutex is destroyed.
2134 void Bootstrapper::FreeThreadResources() { 2132 void Bootstrapper::FreeThreadResources() {
2135 ASSERT(!IsActive()); 2133 ASSERT(!IsActive());
2136 } 2134 }
2137 2135
2138 } } // namespace v8::internal 2136 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/bootstrapper.h ('k') | src/debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698