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

Side by Side Diff: src/runtime.cc

Issue 10832342: Rename "global context" to "native context", (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 // An index key does not require space in the property backing store. 296 // An index key does not require space in the property backing store.
297 number_of_properties--; 297 number_of_properties--;
298 } else { 298 } else {
299 // Bail out as a non-symbol non-index key makes caching impossible. 299 // Bail out as a non-symbol non-index key makes caching impossible.
300 // ASSERT to make sure that the if condition after the loop is false. 300 // ASSERT to make sure that the if condition after the loop is false.
301 ASSERT(number_of_symbol_keys != number_of_properties); 301 ASSERT(number_of_symbol_keys != number_of_properties);
302 break; 302 break;
303 } 303 }
304 } 304 }
305 // If we only have symbols and array indices among keys then we can 305 // If we only have symbols and array indices among keys then we can
306 // use the map cache in the global context. 306 // use the map cache in the native context.
307 const int kMaxKeys = 10; 307 const int kMaxKeys = 10;
308 if ((number_of_symbol_keys == number_of_properties) && 308 if ((number_of_symbol_keys == number_of_properties) &&
309 (number_of_symbol_keys < kMaxKeys)) { 309 (number_of_symbol_keys < kMaxKeys)) {
310 // Create the fixed array with the key. 310 // Create the fixed array with the key.
311 Handle<FixedArray> keys = 311 Handle<FixedArray> keys =
312 isolate->factory()->NewFixedArray(number_of_symbol_keys); 312 isolate->factory()->NewFixedArray(number_of_symbol_keys);
313 if (number_of_symbol_keys > 0) { 313 if (number_of_symbol_keys > 0) {
314 int index = 0; 314 int index = 0;
315 for (int p = 0; p < properties_length; p += 2) { 315 for (int p = 0; p < properties_length; p += 2) {
316 Object* key = constant_properties->get(p); 316 Object* key = constant_properties->get(p);
(...skipping 18 matching lines...) Expand all
335 Handle<FixedArray> literals, 335 Handle<FixedArray> literals,
336 Handle<FixedArray> constant_properties); 336 Handle<FixedArray> constant_properties);
337 337
338 338
339 static Handle<Object> CreateObjectLiteralBoilerplate( 339 static Handle<Object> CreateObjectLiteralBoilerplate(
340 Isolate* isolate, 340 Isolate* isolate,
341 Handle<FixedArray> literals, 341 Handle<FixedArray> literals,
342 Handle<FixedArray> constant_properties, 342 Handle<FixedArray> constant_properties,
343 bool should_have_fast_elements, 343 bool should_have_fast_elements,
344 bool has_function_literal) { 344 bool has_function_literal) {
345 // Get the global context from the literals array. This is the 345 // Get the native context from the literals array. This is the
346 // context in which the function was created and we use the object 346 // context in which the function was created and we use the object
347 // function from this context to create the object literal. We do 347 // function from this context to create the object literal. We do
348 // not use the object function from the current global context 348 // not use the object function from the current native context
349 // because this might be the object function from another context 349 // because this might be the object function from another context
350 // which we should not have access to. 350 // which we should not have access to.
351 Handle<Context> context = 351 Handle<Context> context =
352 Handle<Context>(JSFunction::GlobalContextFromLiterals(*literals)); 352 Handle<Context>(JSFunction::NativeContextFromLiterals(*literals));
353 353
354 // In case we have function literals, we want the object to be in 354 // In case we have function literals, we want the object to be in
355 // slow properties mode for now. We don't go in the map cache because 355 // slow properties mode for now. We don't go in the map cache because
356 // maps with constant functions can't be shared if the functions are 356 // maps with constant functions can't be shared if the functions are
357 // not the same (which is the common case). 357 // not the same (which is the common case).
358 bool is_result_from_cache = false; 358 bool is_result_from_cache = false;
359 Handle<Map> map = has_function_literal 359 Handle<Map> map = has_function_literal
360 ? Handle<Map>(context->object_function()->initial_map()) 360 ? Handle<Map>(context->object_function()->initial_map())
361 : ComputeObjectLiteralMap(context, 361 : ComputeObjectLiteralMap(context,
362 constant_properties, 362 constant_properties,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 457
458 static const int kSmiLiteralMinimumLength = 1024; 458 static const int kSmiLiteralMinimumLength = 1024;
459 459
460 460
461 Handle<Object> Runtime::CreateArrayLiteralBoilerplate( 461 Handle<Object> Runtime::CreateArrayLiteralBoilerplate(
462 Isolate* isolate, 462 Isolate* isolate,
463 Handle<FixedArray> literals, 463 Handle<FixedArray> literals,
464 Handle<FixedArray> elements) { 464 Handle<FixedArray> elements) {
465 // Create the JSArray. 465 // Create the JSArray.
466 Handle<JSFunction> constructor( 466 Handle<JSFunction> constructor(
467 JSFunction::GlobalContextFromLiterals(*literals)->array_function()); 467 JSFunction::NativeContextFromLiterals(*literals)->array_function());
468 Handle<JSArray> object = 468 Handle<JSArray> object =
469 Handle<JSArray>::cast(isolate->factory()->NewJSObject(constructor)); 469 Handle<JSArray>::cast(isolate->factory()->NewJSObject(constructor));
470 470
471 ElementsKind constant_elements_kind = 471 ElementsKind constant_elements_kind =
472 static_cast<ElementsKind>(Smi::cast(elements->get(0))->value()); 472 static_cast<ElementsKind>(Smi::cast(elements->get(0))->value());
473 Handle<FixedArrayBase> constant_elements_values( 473 Handle<FixedArrayBase> constant_elements_values(
474 FixedArrayBase::cast(elements->get(1))); 474 FixedArrayBase::cast(elements->get(1)));
475 475
476 ASSERT(IsFastElementsKind(constant_elements_kind)); 476 ASSERT(IsFastElementsKind(constant_elements_kind));
477 Context* global_context = isolate->context()->global_context(); 477 Context* native_context = isolate->context()->native_context();
478 Object* maybe_maps_array = global_context->js_array_maps(); 478 Object* maybe_maps_array = native_context->js_array_maps();
479 ASSERT(!maybe_maps_array->IsUndefined()); 479 ASSERT(!maybe_maps_array->IsUndefined());
480 Object* maybe_map = FixedArray::cast(maybe_maps_array)->get( 480 Object* maybe_map = FixedArray::cast(maybe_maps_array)->get(
481 constant_elements_kind); 481 constant_elements_kind);
482 ASSERT(maybe_map->IsMap()); 482 ASSERT(maybe_map->IsMap());
483 object->set_map(Map::cast(maybe_map)); 483 object->set_map(Map::cast(maybe_map));
484 484
485 Handle<FixedArrayBase> copied_elements_values; 485 Handle<FixedArrayBase> copied_elements_values;
486 if (IsFastDoubleElementsKind(constant_elements_kind)) { 486 if (IsFastDoubleElementsKind(constant_elements_kind)) {
487 ASSERT(FLAG_smi_only_arrays); 487 ASSERT(FLAG_smi_only_arrays);
488 copied_elements_values = isolate->factory()->CopyFixedDoubleArray( 488 copied_elements_values = isolate->factory()->CopyFixedDoubleArray(
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after
1439 1439
1440 ASSERT(!isolate->has_pending_exception()); 1440 ASSERT(!isolate->has_pending_exception());
1441 return isolate->heap()->undefined_value(); 1441 return isolate->heap()->undefined_value();
1442 } 1442 }
1443 1443
1444 1444
1445 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeclareContextSlot) { 1445 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeclareContextSlot) {
1446 HandleScope scope(isolate); 1446 HandleScope scope(isolate);
1447 ASSERT(args.length() == 4); 1447 ASSERT(args.length() == 4);
1448 1448
1449 // Declarations are always made in a function or global context. In the 1449 // Declarations are always made in a function or native context. In the
1450 // case of eval code, the context passed is the context of the caller, 1450 // case of eval code, the context passed is the context of the caller,
1451 // which may be some nested context and not the declaration context. 1451 // which may be some nested context and not the declaration context.
1452 RUNTIME_ASSERT(args[0]->IsContext()); 1452 RUNTIME_ASSERT(args[0]->IsContext());
1453 Handle<Context> context(Context::cast(args[0])->declaration_context()); 1453 Handle<Context> context(Context::cast(args[0])->declaration_context());
1454 1454
1455 Handle<String> name(String::cast(args[1])); 1455 Handle<String> name(String::cast(args[1]));
1456 PropertyAttributes mode = static_cast<PropertyAttributes>(args.smi_at(2)); 1456 PropertyAttributes mode = static_cast<PropertyAttributes>(args.smi_at(2));
1457 RUNTIME_ASSERT(mode == READ_ONLY || mode == NONE); 1457 RUNTIME_ASSERT(mode == READ_ONLY || mode == NONE);
1458 Handle<Object> initial_value(args[3], isolate); 1458 Handle<Object> initial_value(args[3], isolate);
1459 1459
(...skipping 18 matching lines...) Expand all
1478 // Initialize it if necessary. 1478 // Initialize it if necessary.
1479 if (*initial_value != NULL) { 1479 if (*initial_value != NULL) {
1480 if (index >= 0) { 1480 if (index >= 0) {
1481 ASSERT(holder.is_identical_to(context)); 1481 ASSERT(holder.is_identical_to(context));
1482 if (((attributes & READ_ONLY) == 0) || 1482 if (((attributes & READ_ONLY) == 0) ||
1483 context->get(index)->IsTheHole()) { 1483 context->get(index)->IsTheHole()) {
1484 context->set(index, *initial_value); 1484 context->set(index, *initial_value);
1485 } 1485 }
1486 } else { 1486 } else {
1487 // Slow case: The property is in the context extension object of a 1487 // Slow case: The property is in the context extension object of a
1488 // function context or the global object of a global context. 1488 // function context or the global object of a native context.
1489 Handle<JSObject> object = Handle<JSObject>::cast(holder); 1489 Handle<JSObject> object = Handle<JSObject>::cast(holder);
1490 RETURN_IF_EMPTY_HANDLE( 1490 RETURN_IF_EMPTY_HANDLE(
1491 isolate, 1491 isolate,
1492 JSReceiver::SetProperty(object, name, initial_value, mode, 1492 JSReceiver::SetProperty(object, name, initial_value, mode,
1493 kNonStrictMode)); 1493 kNonStrictMode));
1494 } 1494 }
1495 } 1495 }
1496 1496
1497 } else { 1497 } else {
1498 // The property is not in the function context. It needs to be 1498 // The property is not in the function context. It needs to be
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 } 1679 }
1680 1680
1681 1681
1682 RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeConstContextSlot) { 1682 RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeConstContextSlot) {
1683 HandleScope scope(isolate); 1683 HandleScope scope(isolate);
1684 ASSERT(args.length() == 3); 1684 ASSERT(args.length() == 3);
1685 1685
1686 Handle<Object> value(args[0], isolate); 1686 Handle<Object> value(args[0], isolate);
1687 ASSERT(!value->IsTheHole()); 1687 ASSERT(!value->IsTheHole());
1688 1688
1689 // Initializations are always done in a function or global context. 1689 // Initializations are always done in a function or native context.
1690 RUNTIME_ASSERT(args[1]->IsContext()); 1690 RUNTIME_ASSERT(args[1]->IsContext());
1691 Handle<Context> context(Context::cast(args[1])->declaration_context()); 1691 Handle<Context> context(Context::cast(args[1])->declaration_context());
1692 1692
1693 Handle<String> name(String::cast(args[2])); 1693 Handle<String> name(String::cast(args[2]));
1694 1694
1695 int index; 1695 int index;
1696 PropertyAttributes attributes; 1696 PropertyAttributes attributes;
1697 ContextLookupFlags flags = FOLLOW_CHAINS; 1697 ContextLookupFlags flags = FOLLOW_CHAINS;
1698 BindingFlags binding_flags; 1698 BindingFlags binding_flags;
1699 Handle<Object> holder = 1699 Handle<Object> holder =
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 } 1828 }
1829 FixedArray* elements = FixedArray::cast(new_object); 1829 FixedArray* elements = FixedArray::cast(new_object);
1830 { MaybeObject* maybe_new_object = isolate->heap()->AllocateRaw( 1830 { MaybeObject* maybe_new_object = isolate->heap()->AllocateRaw(
1831 JSRegExpResult::kSize, NEW_SPACE, OLD_POINTER_SPACE); 1831 JSRegExpResult::kSize, NEW_SPACE, OLD_POINTER_SPACE);
1832 if (!maybe_new_object->ToObject(&new_object)) return maybe_new_object; 1832 if (!maybe_new_object->ToObject(&new_object)) return maybe_new_object;
1833 } 1833 }
1834 { 1834 {
1835 AssertNoAllocation no_gc; 1835 AssertNoAllocation no_gc;
1836 HandleScope scope(isolate); 1836 HandleScope scope(isolate);
1837 reinterpret_cast<HeapObject*>(new_object)-> 1837 reinterpret_cast<HeapObject*>(new_object)->
1838 set_map(isolate->global_context()->regexp_result_map()); 1838 set_map(isolate->native_context()->regexp_result_map());
1839 } 1839 }
1840 JSArray* array = JSArray::cast(new_object); 1840 JSArray* array = JSArray::cast(new_object);
1841 array->set_properties(isolate->heap()->empty_fixed_array()); 1841 array->set_properties(isolate->heap()->empty_fixed_array());
1842 array->set_elements(elements); 1842 array->set_elements(elements);
1843 array->set_length(Smi::FromInt(elements_count)); 1843 array->set_length(Smi::FromInt(elements_count));
1844 // Write in-object properties after the length of the array. 1844 // Write in-object properties after the length of the array.
1845 array->InObjectPropertyAtPut(JSRegExpResult::kIndexIndex, args[1]); 1845 array->InObjectPropertyAtPut(JSRegExpResult::kIndexIndex, args[1]);
1846 array->InObjectPropertyAtPut(JSRegExpResult::kInputIndex, args[2]); 1846 array->InObjectPropertyAtPut(JSRegExpResult::kInputIndex, args[2]);
1847 return array; 1847 return array;
1848 } 1848 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1980 } 1980 }
1981 JSFunction* function = JSFunction::cast(callable); 1981 JSFunction* function = JSFunction::cast(callable);
1982 1982
1983 SharedFunctionInfo* shared = function->shared(); 1983 SharedFunctionInfo* shared = function->shared();
1984 if (shared->native() || !shared->is_classic_mode()) { 1984 if (shared->native() || !shared->is_classic_mode()) {
1985 return isolate->heap()->undefined_value(); 1985 return isolate->heap()->undefined_value();
1986 } 1986 }
1987 // Returns undefined for strict or native functions, or 1987 // Returns undefined for strict or native functions, or
1988 // the associated global receiver for "normal" functions. 1988 // the associated global receiver for "normal" functions.
1989 1989
1990 Context* global_context = 1990 Context* native_context =
1991 function->context()->global()->global_context(); 1991 function->context()->global()->native_context();
1992 return global_context->global()->global_receiver(); 1992 return native_context->global()->global_receiver();
1993 } 1993 }
1994 1994
1995 1995
1996 RUNTIME_FUNCTION(MaybeObject*, Runtime_MaterializeRegExpLiteral) { 1996 RUNTIME_FUNCTION(MaybeObject*, Runtime_MaterializeRegExpLiteral) {
1997 HandleScope scope(isolate); 1997 HandleScope scope(isolate);
1998 ASSERT(args.length() == 4); 1998 ASSERT(args.length() == 4);
1999 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); 1999 CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0);
2000 int index = args.smi_at(1); 2000 int index = args.smi_at(1);
2001 Handle<String> pattern = args.at<String>(2); 2001 Handle<String> pattern = args.at<String>(2);
2002 Handle<String> flags = args.at<String>(3); 2002 Handle<String> flags = args.at<String>(3);
2003 2003
2004 // Get the RegExp function from the context in the literals array. 2004 // Get the RegExp function from the context in the literals array.
2005 // This is the RegExp function from the context in which the 2005 // This is the RegExp function from the context in which the
2006 // function was created. We do not use the RegExp function from the 2006 // function was created. We do not use the RegExp function from the
2007 // current global context because this might be the RegExp function 2007 // current native context because this might be the RegExp function
2008 // from another context which we should not have access to. 2008 // from another context which we should not have access to.
2009 Handle<JSFunction> constructor = 2009 Handle<JSFunction> constructor =
2010 Handle<JSFunction>( 2010 Handle<JSFunction>(
2011 JSFunction::GlobalContextFromLiterals(*literals)->regexp_function()); 2011 JSFunction::NativeContextFromLiterals(*literals)->regexp_function());
2012 // Compute the regular expression literal. 2012 // Compute the regular expression literal.
2013 bool has_pending_exception; 2013 bool has_pending_exception;
2014 Handle<Object> regexp = 2014 Handle<Object> regexp =
2015 RegExpImpl::CreateRegExpLiteral(constructor, pattern, flags, 2015 RegExpImpl::CreateRegExpLiteral(constructor, pattern, flags,
2016 &has_pending_exception); 2016 &has_pending_exception);
2017 if (has_pending_exception) { 2017 if (has_pending_exception) {
2018 ASSERT(isolate->has_pending_exception()); 2018 ASSERT(isolate->has_pending_exception());
2019 return Failure::Exception(); 2019 return Failure::Exception();
2020 } 2020 }
2021 literals->set(index, *regexp); 2021 literals->set(index, *regexp);
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
2255 // Set the code of the target function. 2255 // Set the code of the target function.
2256 target->ReplaceCode(source_shared->code()); 2256 target->ReplaceCode(source_shared->code());
2257 2257
2258 // Make sure we get a fresh copy of the literal vector to avoid cross 2258 // Make sure we get a fresh copy of the literal vector to avoid cross
2259 // context contamination. 2259 // context contamination.
2260 Handle<Context> context(source->context()); 2260 Handle<Context> context(source->context());
2261 int number_of_literals = source->NumberOfLiterals(); 2261 int number_of_literals = source->NumberOfLiterals();
2262 Handle<FixedArray> literals = 2262 Handle<FixedArray> literals =
2263 isolate->factory()->NewFixedArray(number_of_literals, TENURED); 2263 isolate->factory()->NewFixedArray(number_of_literals, TENURED);
2264 if (number_of_literals > 0) { 2264 if (number_of_literals > 0) {
2265 literals->set(JSFunction::kLiteralGlobalContextIndex, 2265 literals->set(JSFunction::kLiteralNativeContextIndex,
2266 context->global_context()); 2266 context->native_context());
2267 } 2267 }
2268 target->set_context(*context); 2268 target->set_context(*context);
2269 target->set_literals(*literals); 2269 target->set_literals(*literals);
2270 target->set_next_function_link(isolate->heap()->undefined_value()); 2270 target->set_next_function_link(isolate->heap()->undefined_value());
2271 2271
2272 if (isolate->logger()->is_logging() || CpuProfiler::is_profiling(isolate)) { 2272 if (isolate->logger()->is_logging() || CpuProfiler::is_profiling(isolate)) {
2273 isolate->logger()->LogExistingFunction( 2273 isolate->logger()->LogExistingFunction(
2274 source_shared, Handle<Code>(source_shared->code())); 2274 source_shared, Handle<Code>(source_shared->code()));
2275 } 2275 }
2276 2276
(...skipping 6128 matching lines...) Expand 10 before | Expand all | Expand 10 after
8405 } else { 8405 } else {
8406 return maybe_js_object; 8406 return maybe_js_object;
8407 } 8407 }
8408 } 8408 }
8409 } 8409 }
8410 8410
8411 JSFunction* function; 8411 JSFunction* function;
8412 if (args[1]->IsSmi()) { 8412 if (args[1]->IsSmi()) {
8413 // A smi sentinel indicates a context nested inside global code rather 8413 // A smi sentinel indicates a context nested inside global code rather
8414 // than some function. There is a canonical empty function that can be 8414 // than some function. There is a canonical empty function that can be
8415 // gotten from the global context. 8415 // gotten from the native context.
8416 function = isolate->context()->global_context()->closure(); 8416 function = isolate->context()->native_context()->closure();
8417 } else { 8417 } else {
8418 function = JSFunction::cast(args[1]); 8418 function = JSFunction::cast(args[1]);
8419 } 8419 }
8420 8420
8421 Context* context; 8421 Context* context;
8422 MaybeObject* maybe_context = 8422 MaybeObject* maybe_context =
8423 isolate->heap()->AllocateWithContext(function, 8423 isolate->heap()->AllocateWithContext(function,
8424 isolate->context(), 8424 isolate->context(),
8425 extension_object); 8425 extension_object);
8426 if (!maybe_context->To(&context)) return maybe_context; 8426 if (!maybe_context->To(&context)) return maybe_context;
8427 isolate->set_context(context); 8427 isolate->set_context(context);
8428 return context; 8428 return context;
8429 } 8429 }
8430 8430
8431 8431
8432 RUNTIME_FUNCTION(MaybeObject*, Runtime_PushCatchContext) { 8432 RUNTIME_FUNCTION(MaybeObject*, Runtime_PushCatchContext) {
8433 NoHandleAllocation ha; 8433 NoHandleAllocation ha;
8434 ASSERT(args.length() == 3); 8434 ASSERT(args.length() == 3);
8435 String* name = String::cast(args[0]); 8435 String* name = String::cast(args[0]);
8436 Object* thrown_object = args[1]; 8436 Object* thrown_object = args[1];
8437 JSFunction* function; 8437 JSFunction* function;
8438 if (args[2]->IsSmi()) { 8438 if (args[2]->IsSmi()) {
8439 // A smi sentinel indicates a context nested inside global code rather 8439 // A smi sentinel indicates a context nested inside global code rather
8440 // than some function. There is a canonical empty function that can be 8440 // than some function. There is a canonical empty function that can be
8441 // gotten from the global context. 8441 // gotten from the native context.
8442 function = isolate->context()->global_context()->closure(); 8442 function = isolate->context()->native_context()->closure();
8443 } else { 8443 } else {
8444 function = JSFunction::cast(args[2]); 8444 function = JSFunction::cast(args[2]);
8445 } 8445 }
8446 Context* context; 8446 Context* context;
8447 MaybeObject* maybe_context = 8447 MaybeObject* maybe_context =
8448 isolate->heap()->AllocateCatchContext(function, 8448 isolate->heap()->AllocateCatchContext(function,
8449 isolate->context(), 8449 isolate->context(),
8450 name, 8450 name,
8451 thrown_object); 8451 thrown_object);
8452 if (!maybe_context->To(&context)) return maybe_context; 8452 if (!maybe_context->To(&context)) return maybe_context;
8453 isolate->set_context(context); 8453 isolate->set_context(context);
8454 return context; 8454 return context;
8455 } 8455 }
8456 8456
8457 8457
8458 RUNTIME_FUNCTION(MaybeObject*, Runtime_PushBlockContext) { 8458 RUNTIME_FUNCTION(MaybeObject*, Runtime_PushBlockContext) {
8459 NoHandleAllocation ha; 8459 NoHandleAllocation ha;
8460 ASSERT(args.length() == 2); 8460 ASSERT(args.length() == 2);
8461 ScopeInfo* scope_info = ScopeInfo::cast(args[0]); 8461 ScopeInfo* scope_info = ScopeInfo::cast(args[0]);
8462 JSFunction* function; 8462 JSFunction* function;
8463 if (args[1]->IsSmi()) { 8463 if (args[1]->IsSmi()) {
8464 // A smi sentinel indicates a context nested inside global code rather 8464 // A smi sentinel indicates a context nested inside global code rather
8465 // than some function. There is a canonical empty function that can be 8465 // than some function. There is a canonical empty function that can be
8466 // gotten from the global context. 8466 // gotten from the native context.
8467 function = isolate->context()->global_context()->closure(); 8467 function = isolate->context()->native_context()->closure();
8468 } else { 8468 } else {
8469 function = JSFunction::cast(args[1]); 8469 function = JSFunction::cast(args[1]);
8470 } 8470 }
8471 Context* context; 8471 Context* context;
8472 MaybeObject* maybe_context = 8472 MaybeObject* maybe_context =
8473 isolate->heap()->AllocateBlockContext(function, 8473 isolate->heap()->AllocateBlockContext(function,
8474 isolate->context(), 8474 isolate->context(),
8475 scope_info); 8475 scope_info);
8476 if (!maybe_context->To(&context)) return maybe_context; 8476 if (!maybe_context->To(&context)) return maybe_context;
8477 isolate->set_context(context); 8477 isolate->set_context(context);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
8576 return x->IsTheHole() ? heap->undefined_value() : x; 8576 return x->IsTheHole() ? heap->undefined_value() : x;
8577 } 8577 }
8578 8578
8579 8579
8580 static Object* ComputeReceiverForNonGlobal(Isolate* isolate, 8580 static Object* ComputeReceiverForNonGlobal(Isolate* isolate,
8581 JSObject* holder) { 8581 JSObject* holder) {
8582 ASSERT(!holder->IsGlobalObject()); 8582 ASSERT(!holder->IsGlobalObject());
8583 Context* top = isolate->context(); 8583 Context* top = isolate->context();
8584 // Get the context extension function. 8584 // Get the context extension function.
8585 JSFunction* context_extension_function = 8585 JSFunction* context_extension_function =
8586 top->global_context()->context_extension_function(); 8586 top->native_context()->context_extension_function();
8587 // If the holder isn't a context extension object, we just return it 8587 // If the holder isn't a context extension object, we just return it
8588 // as the receiver. This allows arguments objects to be used as 8588 // as the receiver. This allows arguments objects to be used as
8589 // receivers, but only if they are put in the context scope chain 8589 // receivers, but only if they are put in the context scope chain
8590 // explicitly via a with-statement. 8590 // explicitly via a with-statement.
8591 Object* constructor = holder->map()->constructor(); 8591 Object* constructor = holder->map()->constructor();
8592 if (constructor != context_extension_function) return holder; 8592 if (constructor != context_extension_function) return holder;
8593 // Fall back to using the global object as the implicit receiver if 8593 // Fall back to using the global object as the implicit receiver if
8594 // the property turns out to be a local variable allocated in a 8594 // the property turns out to be a local variable allocated in a
8595 // context extension object - introduced via eval. Implicit global 8595 // context extension object - introduced via eval. Implicit global
8596 // receivers are indicated with the hole value. 8596 // receivers are indicated with the hole value.
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
9038 return callback(v8::Utils::ToLocal(context)); 9038 return callback(v8::Utils::ToLocal(context));
9039 } 9039 }
9040 } 9040 }
9041 9041
9042 9042
9043 RUNTIME_FUNCTION(MaybeObject*, Runtime_CompileString) { 9043 RUNTIME_FUNCTION(MaybeObject*, Runtime_CompileString) {
9044 HandleScope scope(isolate); 9044 HandleScope scope(isolate);
9045 ASSERT_EQ(1, args.length()); 9045 ASSERT_EQ(1, args.length());
9046 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); 9046 CONVERT_ARG_HANDLE_CHECKED(String, source, 0);
9047 9047
9048 // Extract global context. 9048 // Extract native context.
9049 Handle<Context> context(isolate->context()->global_context()); 9049 Handle<Context> context(isolate->context()->native_context());
9050 9050
9051 // Check if global context allows code generation from 9051 // Check if native context allows code generation from
9052 // strings. Throw an exception if it doesn't. 9052 // strings. Throw an exception if it doesn't.
9053 if (context->allow_code_gen_from_strings()->IsFalse() && 9053 if (context->allow_code_gen_from_strings()->IsFalse() &&
9054 !CodeGenerationFromStringsAllowed(isolate, context)) { 9054 !CodeGenerationFromStringsAllowed(isolate, context)) {
9055 return isolate->Throw(*isolate->factory()->NewError( 9055 return isolate->Throw(*isolate->factory()->NewError(
9056 "code_gen_from_strings", HandleVector<Object>(NULL, 0))); 9056 "code_gen_from_strings", HandleVector<Object>(NULL, 0)));
9057 } 9057 }
9058 9058
9059 // Compile source string in the global context. 9059 // Compile source string in the native context.
9060 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( 9060 Handle<SharedFunctionInfo> shared = Compiler::CompileEval(
9061 source, context, true, CLASSIC_MODE, RelocInfo::kNoPosition); 9061 source, context, true, CLASSIC_MODE, RelocInfo::kNoPosition);
9062 if (shared.is_null()) return Failure::Exception(); 9062 if (shared.is_null()) return Failure::Exception();
9063 Handle<JSFunction> fun = 9063 Handle<JSFunction> fun =
9064 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, 9064 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared,
9065 context, 9065 context,
9066 NOT_TENURED); 9066 NOT_TENURED);
9067 return *fun; 9067 return *fun;
9068 } 9068 }
9069 9069
9070 9070
9071 static ObjectPair CompileGlobalEval(Isolate* isolate, 9071 static ObjectPair CompileGlobalEval(Isolate* isolate,
9072 Handle<String> source, 9072 Handle<String> source,
9073 Handle<Object> receiver, 9073 Handle<Object> receiver,
9074 LanguageMode language_mode, 9074 LanguageMode language_mode,
9075 int scope_position) { 9075 int scope_position) {
9076 Handle<Context> context = Handle<Context>(isolate->context()); 9076 Handle<Context> context = Handle<Context>(isolate->context());
9077 Handle<Context> global_context = Handle<Context>(context->global_context()); 9077 Handle<Context> native_context = Handle<Context>(context->native_context());
9078 9078
9079 // Check if global context allows code generation from 9079 // Check if native context allows code generation from
9080 // strings. Throw an exception if it doesn't. 9080 // strings. Throw an exception if it doesn't.
9081 if (global_context->allow_code_gen_from_strings()->IsFalse() && 9081 if (native_context->allow_code_gen_from_strings()->IsFalse() &&
9082 !CodeGenerationFromStringsAllowed(isolate, global_context)) { 9082 !CodeGenerationFromStringsAllowed(isolate, native_context)) {
9083 isolate->Throw(*isolate->factory()->NewError( 9083 isolate->Throw(*isolate->factory()->NewError(
9084 "code_gen_from_strings", HandleVector<Object>(NULL, 0))); 9084 "code_gen_from_strings", HandleVector<Object>(NULL, 0)));
9085 return MakePair(Failure::Exception(), NULL); 9085 return MakePair(Failure::Exception(), NULL);
9086 } 9086 }
9087 9087
9088 // Deal with a normal eval call with a string argument. Compile it 9088 // Deal with a normal eval call with a string argument. Compile it
9089 // and return the compiled function bound in the local context. 9089 // and return the compiled function bound in the local context.
9090 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( 9090 Handle<SharedFunctionInfo> shared = Compiler::CompileEval(
9091 source, 9091 source,
9092 Handle<Context>(isolate->context()), 9092 Handle<Context>(isolate->context()),
9093 context->IsGlobalContext(), 9093 context->IsNativeContext(),
9094 language_mode, 9094 language_mode,
9095 scope_position); 9095 scope_position);
9096 if (shared.is_null()) return MakePair(Failure::Exception(), NULL); 9096 if (shared.is_null()) return MakePair(Failure::Exception(), NULL);
9097 Handle<JSFunction> compiled = 9097 Handle<JSFunction> compiled =
9098 isolate->factory()->NewFunctionFromSharedFunctionInfo( 9098 isolate->factory()->NewFunctionFromSharedFunctionInfo(
9099 shared, context, NOT_TENURED); 9099 shared, context, NOT_TENURED);
9100 return MakePair(*compiled, *receiver); 9100 return MakePair(*compiled, *receiver);
9101 } 9101 }
9102 9102
9103 9103
9104 RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEval) { 9104 RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEval) {
9105 ASSERT(args.length() == 5); 9105 ASSERT(args.length() == 5);
9106 9106
9107 HandleScope scope(isolate); 9107 HandleScope scope(isolate);
9108 Handle<Object> callee = args.at<Object>(0); 9108 Handle<Object> callee = args.at<Object>(0);
9109 9109
9110 // If "eval" didn't refer to the original GlobalEval, it's not a 9110 // If "eval" didn't refer to the original GlobalEval, it's not a
9111 // direct call to eval. 9111 // direct call to eval.
9112 // (And even if it is, but the first argument isn't a string, just let 9112 // (And even if it is, but the first argument isn't a string, just let
9113 // execution default to an indirect call to eval, which will also return 9113 // execution default to an indirect call to eval, which will also return
9114 // the first argument without doing anything). 9114 // the first argument without doing anything).
9115 if (*callee != isolate->global_context()->global_eval_fun() || 9115 if (*callee != isolate->native_context()->global_eval_fun() ||
9116 !args[1]->IsString()) { 9116 !args[1]->IsString()) {
9117 return MakePair(*callee, isolate->heap()->the_hole_value()); 9117 return MakePair(*callee, isolate->heap()->the_hole_value());
9118 } 9118 }
9119 9119
9120 CONVERT_LANGUAGE_MODE_ARG(language_mode, 3); 9120 CONVERT_LANGUAGE_MODE_ARG(language_mode, 3);
9121 ASSERT(args[4]->IsSmi()); 9121 ASSERT(args[4]->IsSmi());
9122 return CompileGlobalEval(isolate, 9122 return CompileGlobalEval(isolate,
9123 args.at<String>(1), 9123 args.at<String>(1),
9124 args.at<Object>(2), 9124 args.at<Object>(2),
9125 language_mode, 9125 language_mode,
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after
10010 10010
10011 ASSERT(args.length() == 2); 10011 ASSERT(args.length() == 2);
10012 10012
10013 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); 10013 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0);
10014 CONVERT_ARG_HANDLE_CHECKED(String, name, 1); 10014 CONVERT_ARG_HANDLE_CHECKED(String, name, 1);
10015 10015
10016 // Make sure to set the current context to the context before the debugger was 10016 // Make sure to set the current context to the context before the debugger was
10017 // entered (if the debugger is entered). The reason for switching context here 10017 // entered (if the debugger is entered). The reason for switching context here
10018 // is that for some property lookups (accessors and interceptors) callbacks 10018 // is that for some property lookups (accessors and interceptors) callbacks
10019 // into the embedding application can occour, and the embedding application 10019 // into the embedding application can occour, and the embedding application
10020 // could have the assumption that its own global context is the current 10020 // could have the assumption that its own native context is the current
10021 // context and not some internal debugger context. 10021 // context and not some internal debugger context.
10022 SaveContext save(isolate); 10022 SaveContext save(isolate);
10023 if (isolate->debug()->InDebugger()) { 10023 if (isolate->debug()->InDebugger()) {
10024 isolate->set_context(*isolate->debug()->debugger_entry()->GetContext()); 10024 isolate->set_context(*isolate->debug()->debugger_entry()->GetContext());
10025 } 10025 }
10026 10026
10027 // Skip the global proxy as it has no properties and always delegates to the 10027 // Skip the global proxy as it has no properties and always delegates to the
10028 // real global object. 10028 // real global object.
10029 if (obj->IsJSGlobalProxy()) { 10029 if (obj->IsJSGlobalProxy()) {
10030 obj = Handle<JSObject>(JSObject::cast(obj->GetPrototype())); 10030 obj = Handle<JSObject>(JSObject::cast(obj->GetPrototype()));
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
10555 // THE FRAME ITERATOR TO WRAP THE RECEIVER. 10555 // THE FRAME ITERATOR TO WRAP THE RECEIVER.
10556 Handle<Object> receiver(it.frame()->receiver(), isolate); 10556 Handle<Object> receiver(it.frame()->receiver(), isolate);
10557 if (!receiver->IsJSObject() && 10557 if (!receiver->IsJSObject() &&
10558 shared->is_classic_mode() && 10558 shared->is_classic_mode() &&
10559 !shared->native()) { 10559 !shared->native()) {
10560 // If the receiver is not a JSObject and the function is not a 10560 // If the receiver is not a JSObject and the function is not a
10561 // builtin or strict-mode we have hit an optimization where a 10561 // builtin or strict-mode we have hit an optimization where a
10562 // value object is not converted into a wrapped JS objects. To 10562 // value object is not converted into a wrapped JS objects. To
10563 // hide this optimization from the debugger, we wrap the receiver 10563 // hide this optimization from the debugger, we wrap the receiver
10564 // by creating correct wrapper object based on the calling frame's 10564 // by creating correct wrapper object based on the calling frame's
10565 // global context. 10565 // native context.
10566 it.Advance(); 10566 it.Advance();
10567 Handle<Context> calling_frames_global_context( 10567 Handle<Context> calling_frames_native_context(
10568 Context::cast(Context::cast(it.frame()->context())->global_context())); 10568 Context::cast(Context::cast(it.frame()->context())->native_context()));
10569 receiver = 10569 receiver =
10570 isolate->factory()->ToObject(receiver, calling_frames_global_context); 10570 isolate->factory()->ToObject(receiver, calling_frames_native_context);
10571 } 10571 }
10572 details->set(kFrameDetailsReceiverIndex, *receiver); 10572 details->set(kFrameDetailsReceiverIndex, *receiver);
10573 10573
10574 ASSERT_EQ(details_size, details_index); 10574 ASSERT_EQ(details_size, details_index);
10575 return *isolate->factory()->NewJSArrayWithElements(details); 10575 return *isolate->factory()->NewJSArrayWithElements(details);
10576 } 10576 }
10577 10577
10578 10578
10579 // Copy all the context locals into an object used to materialize a scope. 10579 // Copy all the context locals into an object used to materialize a scope.
10580 static bool CopyContextLocalsToScopeObject( 10580 static bool CopyContextLocalsToScopeObject(
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
10652 Handle<Context> function_context(frame_context->declaration_context()); 10652 Handle<Context> function_context(frame_context->declaration_context());
10653 if (!CopyContextLocalsToScopeObject( 10653 if (!CopyContextLocalsToScopeObject(
10654 isolate, scope_info, function_context, local_scope)) { 10654 isolate, scope_info, function_context, local_scope)) {
10655 return Handle<JSObject>(); 10655 return Handle<JSObject>();
10656 } 10656 }
10657 10657
10658 // Finally copy any properties from the function context extension. 10658 // Finally copy any properties from the function context extension.
10659 // These will be variables introduced by eval. 10659 // These will be variables introduced by eval.
10660 if (function_context->closure() == *function) { 10660 if (function_context->closure() == *function) {
10661 if (function_context->has_extension() && 10661 if (function_context->has_extension() &&
10662 !function_context->IsGlobalContext()) { 10662 !function_context->IsNativeContext()) {
10663 Handle<JSObject> ext(JSObject::cast(function_context->extension())); 10663 Handle<JSObject> ext(JSObject::cast(function_context->extension()));
10664 bool threw = false; 10664 bool threw = false;
10665 Handle<FixedArray> keys = 10665 Handle<FixedArray> keys =
10666 GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS, &threw); 10666 GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS, &threw);
10667 if (threw) return Handle<JSObject>(); 10667 if (threw) return Handle<JSObject>();
10668 10668
10669 for (int i = 0; i < keys->length(); i++) { 10669 for (int i = 0; i < keys->length(); i++) {
10670 // Names of variables introduced by eval are strings. 10670 // Names of variables introduced by eval are strings.
10671 ASSERT(keys->get(i)->IsString()); 10671 ASSERT(keys->get(i)->IsString());
10672 Handle<String> key(String::cast(keys->get(i))); 10672 Handle<String> key(String::cast(keys->get(i)));
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
10914 } 10914 }
10915 10915
10916 // More scopes? 10916 // More scopes?
10917 bool Done() { return context_.is_null(); } 10917 bool Done() { return context_.is_null(); }
10918 10918
10919 // Move to the next scope. 10919 // Move to the next scope.
10920 void Next() { 10920 void Next() {
10921 ScopeType scope_type = Type(); 10921 ScopeType scope_type = Type();
10922 if (scope_type == ScopeTypeGlobal) { 10922 if (scope_type == ScopeTypeGlobal) {
10923 // The global scope is always the last in the chain. 10923 // The global scope is always the last in the chain.
10924 ASSERT(context_->IsGlobalContext()); 10924 ASSERT(context_->IsNativeContext());
10925 context_ = Handle<Context>(); 10925 context_ = Handle<Context>();
10926 return; 10926 return;
10927 } 10927 }
10928 if (nested_scope_chain_.is_empty()) { 10928 if (nested_scope_chain_.is_empty()) {
10929 context_ = Handle<Context>(context_->previous(), isolate_); 10929 context_ = Handle<Context>(context_->previous(), isolate_);
10930 } else { 10930 } else {
10931 if (nested_scope_chain_.last()->HasContext()) { 10931 if (nested_scope_chain_.last()->HasContext()) {
10932 ASSERT(context_->previous() != NULL); 10932 ASSERT(context_->previous() != NULL);
10933 context_ = Handle<Context>(context_->previous(), isolate_); 10933 context_ = Handle<Context>(context_->previous(), isolate_);
10934 } 10934 }
10935 nested_scope_chain_.RemoveLast(); 10935 nested_scope_chain_.RemoveLast();
10936 } 10936 }
10937 } 10937 }
10938 10938
10939 // Return the type of the current scope. 10939 // Return the type of the current scope.
10940 ScopeType Type() { 10940 ScopeType Type() {
10941 if (!nested_scope_chain_.is_empty()) { 10941 if (!nested_scope_chain_.is_empty()) {
10942 Handle<ScopeInfo> scope_info = nested_scope_chain_.last(); 10942 Handle<ScopeInfo> scope_info = nested_scope_chain_.last();
10943 switch (scope_info->Type()) { 10943 switch (scope_info->Type()) {
10944 case FUNCTION_SCOPE: 10944 case FUNCTION_SCOPE:
10945 ASSERT(context_->IsFunctionContext() || 10945 ASSERT(context_->IsFunctionContext() ||
10946 !scope_info->HasContext()); 10946 !scope_info->HasContext());
10947 return ScopeTypeLocal; 10947 return ScopeTypeLocal;
10948 case MODULE_SCOPE: 10948 case MODULE_SCOPE:
10949 ASSERT(context_->IsModuleContext()); 10949 ASSERT(context_->IsModuleContext());
10950 return ScopeTypeModule; 10950 return ScopeTypeModule;
10951 case GLOBAL_SCOPE: 10951 case GLOBAL_SCOPE:
10952 ASSERT(context_->IsGlobalContext()); 10952 ASSERT(context_->IsNativeContext());
10953 return ScopeTypeGlobal; 10953 return ScopeTypeGlobal;
10954 case WITH_SCOPE: 10954 case WITH_SCOPE:
10955 ASSERT(context_->IsWithContext()); 10955 ASSERT(context_->IsWithContext());
10956 return ScopeTypeWith; 10956 return ScopeTypeWith;
10957 case CATCH_SCOPE: 10957 case CATCH_SCOPE:
10958 ASSERT(context_->IsCatchContext()); 10958 ASSERT(context_->IsCatchContext());
10959 return ScopeTypeCatch; 10959 return ScopeTypeCatch;
10960 case BLOCK_SCOPE: 10960 case BLOCK_SCOPE:
10961 ASSERT(!scope_info->HasContext() || 10961 ASSERT(!scope_info->HasContext() ||
10962 context_->IsBlockContext()); 10962 context_->IsBlockContext());
10963 return ScopeTypeBlock; 10963 return ScopeTypeBlock;
10964 case EVAL_SCOPE: 10964 case EVAL_SCOPE:
10965 UNREACHABLE(); 10965 UNREACHABLE();
10966 } 10966 }
10967 } 10967 }
10968 if (context_->IsGlobalContext()) { 10968 if (context_->IsNativeContext()) {
10969 ASSERT(context_->global()->IsGlobalObject()); 10969 ASSERT(context_->global()->IsGlobalObject());
10970 return ScopeTypeGlobal; 10970 return ScopeTypeGlobal;
10971 } 10971 }
10972 if (context_->IsFunctionContext()) { 10972 if (context_->IsFunctionContext()) {
10973 return ScopeTypeClosure; 10973 return ScopeTypeClosure;
10974 } 10974 }
10975 if (context_->IsCatchContext()) { 10975 if (context_->IsCatchContext()) {
10976 return ScopeTypeCatch; 10976 return ScopeTypeCatch;
10977 } 10977 }
10978 if (context_->IsBlockContext()) { 10978 if (context_->IsBlockContext()) {
(...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after
11847 11847
11848 Handle<String> function_source = 11848 Handle<String> function_source =
11849 isolate->factory()->NewStringFromAscii( 11849 isolate->factory()->NewStringFromAscii(
11850 Vector<const char>(kSourceStr, sizeof(kSourceStr) - 1)); 11850 Vector<const char>(kSourceStr, sizeof(kSourceStr) - 1));
11851 11851
11852 // Currently, the eval code will be executed in non-strict mode, 11852 // Currently, the eval code will be executed in non-strict mode,
11853 // even in the strict code context. 11853 // even in the strict code context.
11854 Handle<SharedFunctionInfo> shared = 11854 Handle<SharedFunctionInfo> shared =
11855 Compiler::CompileEval(function_source, 11855 Compiler::CompileEval(function_source,
11856 context, 11856 context,
11857 context->IsGlobalContext(), 11857 context->IsNativeContext(),
11858 CLASSIC_MODE, 11858 CLASSIC_MODE,
11859 RelocInfo::kNoPosition); 11859 RelocInfo::kNoPosition);
11860 if (shared.is_null()) return Failure::Exception(); 11860 if (shared.is_null()) return Failure::Exception();
11861 Handle<JSFunction> compiled_function = 11861 Handle<JSFunction> compiled_function =
11862 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context); 11862 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context);
11863 11863
11864 // Invoke the result of the compilation to get the evaluation function. 11864 // Invoke the result of the compilation to get the evaluation function.
11865 bool has_pending_exception; 11865 bool has_pending_exception;
11866 Handle<Object> receiver(frame->receiver(), isolate); 11866 Handle<Object> receiver(frame->receiver(), isolate);
11867 Handle<Object> evaluation_function = 11867 Handle<Object> evaluation_function =
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
11918 // Enter the top context from before the debugger was invoked. 11918 // Enter the top context from before the debugger was invoked.
11919 SaveContext save(isolate); 11919 SaveContext save(isolate);
11920 SaveContext* top = &save; 11920 SaveContext* top = &save;
11921 while (top != NULL && *top->context() == *isolate->debug()->debug_context()) { 11921 while (top != NULL && *top->context() == *isolate->debug()->debug_context()) {
11922 top = top->prev(); 11922 top = top->prev();
11923 } 11923 }
11924 if (top != NULL) { 11924 if (top != NULL) {
11925 isolate->set_context(*top->context()); 11925 isolate->set_context(*top->context());
11926 } 11926 }
11927 11927
11928 // Get the global context now set to the top context from before the 11928 // Get the native context now set to the top context from before the
11929 // debugger was invoked. 11929 // debugger was invoked.
11930 Handle<Context> context = isolate->global_context(); 11930 Handle<Context> context = isolate->native_context();
11931 11931
11932 bool is_global = true; 11932 bool is_global = true;
11933 11933
11934 if (additional_context->IsJSObject()) { 11934 if (additional_context->IsJSObject()) {
11935 // Create a new with context with the additional context information between 11935 // Create a new with context with the additional context information between
11936 // the context of the debugged function and the eval code to be executed. 11936 // the context of the debugged function and the eval code to be executed.
11937 context = isolate->factory()->NewWithContext( 11937 context = isolate->factory()->NewWithContext(
11938 Handle<JSFunction>(context->closure()), 11938 Handle<JSFunction>(context->closure()),
11939 context, 11939 context,
11940 Handle<JSObject>::cast(additional_context)); 11940 Handle<JSObject>::cast(additional_context));
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
12085 CONVERT_ARG_CHECKED(JSObject, target, 0); 12085 CONVERT_ARG_CHECKED(JSObject, target, 0);
12086 Object* instance_filter = args[1]; 12086 Object* instance_filter = args[1];
12087 RUNTIME_ASSERT(instance_filter->IsUndefined() || 12087 RUNTIME_ASSERT(instance_filter->IsUndefined() ||
12088 instance_filter->IsJSObject()); 12088 instance_filter->IsJSObject());
12089 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]); 12089 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]);
12090 RUNTIME_ASSERT(max_references >= 0); 12090 RUNTIME_ASSERT(max_references >= 0);
12091 12091
12092 12092
12093 // Get the constructor function for context extension and arguments array. 12093 // Get the constructor function for context extension and arguments array.
12094 JSObject* arguments_boilerplate = 12094 JSObject* arguments_boilerplate =
12095 isolate->context()->global_context()->arguments_boilerplate(); 12095 isolate->context()->native_context()->arguments_boilerplate();
12096 JSFunction* arguments_function = 12096 JSFunction* arguments_function =
12097 JSFunction::cast(arguments_boilerplate->map()->constructor()); 12097 JSFunction::cast(arguments_boilerplate->map()->constructor());
12098 12098
12099 // Get the number of referencing objects. 12099 // Get the number of referencing objects.
12100 int count; 12100 int count;
12101 HeapIterator heap_iterator; 12101 HeapIterator heap_iterator;
12102 count = DebugReferencedBy(&heap_iterator, 12102 count = DebugReferencedBy(&heap_iterator,
12103 target, instance_filter, max_references, 12103 target, instance_filter, max_references,
12104 NULL, 0, arguments_function); 12104 NULL, 0, arguments_function);
12105 12105
12106 // Allocate an array to hold the result. 12106 // Allocate an array to hold the result.
12107 Object* object; 12107 Object* object;
12108 { MaybeObject* maybe_object = isolate->heap()->AllocateFixedArray(count); 12108 { MaybeObject* maybe_object = isolate->heap()->AllocateFixedArray(count);
12109 if (!maybe_object->ToObject(&object)) return maybe_object; 12109 if (!maybe_object->ToObject(&object)) return maybe_object;
12110 } 12110 }
12111 FixedArray* instances = FixedArray::cast(object); 12111 FixedArray* instances = FixedArray::cast(object);
12112 12112
12113 // Fill the referencing objects. 12113 // Fill the referencing objects.
12114 // AllocateFixedArray above does not make the heap non-iterable. 12114 // AllocateFixedArray above does not make the heap non-iterable.
12115 ASSERT(HEAP->IsHeapIterable()); 12115 ASSERT(HEAP->IsHeapIterable());
12116 HeapIterator heap_iterator2; 12116 HeapIterator heap_iterator2;
12117 count = DebugReferencedBy(&heap_iterator2, 12117 count = DebugReferencedBy(&heap_iterator2,
12118 target, instance_filter, max_references, 12118 target, instance_filter, max_references,
12119 instances, count, arguments_function); 12119 instances, count, arguments_function);
12120 12120
12121 // Return result as JS array. 12121 // Return result as JS array.
12122 Object* result; 12122 Object* result;
12123 MaybeObject* maybe_result = isolate->heap()->AllocateJSObject( 12123 MaybeObject* maybe_result = isolate->heap()->AllocateJSObject(
12124 isolate->context()->global_context()->array_function()); 12124 isolate->context()->native_context()->array_function());
12125 if (!maybe_result->ToObject(&result)) return maybe_result; 12125 if (!maybe_result->ToObject(&result)) return maybe_result;
12126 return JSArray::cast(result)->SetContent(instances); 12126 return JSArray::cast(result)->SetContent(instances);
12127 } 12127 }
12128 12128
12129 12129
12130 // Helper function used by Runtime_DebugConstructedBy below. 12130 // Helper function used by Runtime_DebugConstructedBy below.
12131 static int DebugConstructedBy(HeapIterator* iterator, 12131 static int DebugConstructedBy(HeapIterator* iterator,
12132 JSFunction* constructor, 12132 JSFunction* constructor,
12133 int max_references, 12133 int max_references,
12134 FixedArray* instances, 12134 FixedArray* instances,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
12195 HeapIterator heap_iterator2; 12195 HeapIterator heap_iterator2;
12196 count = DebugConstructedBy(&heap_iterator2, 12196 count = DebugConstructedBy(&heap_iterator2,
12197 constructor, 12197 constructor,
12198 max_references, 12198 max_references,
12199 instances, 12199 instances,
12200 count); 12200 count);
12201 12201
12202 // Return result as JS array. 12202 // Return result as JS array.
12203 Object* result; 12203 Object* result;
12204 { MaybeObject* maybe_result = isolate->heap()->AllocateJSObject( 12204 { MaybeObject* maybe_result = isolate->heap()->AllocateJSObject(
12205 isolate->context()->global_context()->array_function()); 12205 isolate->context()->native_context()->array_function());
12206 if (!maybe_result->ToObject(&result)) return maybe_result; 12206 if (!maybe_result->ToObject(&result)) return maybe_result;
12207 } 12207 }
12208 return JSArray::cast(result)->SetContent(instances); 12208 return JSArray::cast(result)->SetContent(instances);
12209 } 12209 }
12210 12210
12211 12211
12212 // Find the effective prototype object as returned by __proto__. 12212 // Find the effective prototype object as returned by __proto__.
12213 // args[0]: the object to find the prototype for. 12213 // args[0]: the object to find the prototype for.
12214 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugGetPrototype) { 12214 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugGetPrototype) {
12215 ASSERT(args.length() == 1); 12215 ASSERT(args.length() == 1);
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after
13069 // There is no value in the cache. Invoke the function and cache result. 13069 // There is no value in the cache. Invoke the function and cache result.
13070 HandleScope scope(isolate); 13070 HandleScope scope(isolate);
13071 13071
13072 Handle<JSFunctionResultCache> cache_handle(cache); 13072 Handle<JSFunctionResultCache> cache_handle(cache);
13073 Handle<Object> key_handle(key); 13073 Handle<Object> key_handle(key);
13074 Handle<Object> value; 13074 Handle<Object> value;
13075 { 13075 {
13076 Handle<JSFunction> factory(JSFunction::cast( 13076 Handle<JSFunction> factory(JSFunction::cast(
13077 cache_handle->get(JSFunctionResultCache::kFactoryIndex))); 13077 cache_handle->get(JSFunctionResultCache::kFactoryIndex)));
13078 // TODO(antonm): consider passing a receiver when constructing a cache. 13078 // TODO(antonm): consider passing a receiver when constructing a cache.
13079 Handle<Object> receiver(isolate->global_context()->global()); 13079 Handle<Object> receiver(isolate->native_context()->global());
13080 // This handle is nor shared, nor used later, so it's safe. 13080 // This handle is nor shared, nor used later, so it's safe.
13081 Handle<Object> argv[] = { key_handle }; 13081 Handle<Object> argv[] = { key_handle };
13082 bool pending_exception; 13082 bool pending_exception;
13083 value = Execution::Call(factory, 13083 value = Execution::Call(factory,
13084 receiver, 13084 receiver,
13085 ARRAY_SIZE(argv), 13085 ARRAY_SIZE(argv),
13086 argv, 13086 argv,
13087 &pending_exception); 13087 &pending_exception);
13088 if (pending_exception) return Failure::Exception(); 13088 if (pending_exception) return Failure::Exception();
13089 } 13089 }
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
13347 // Handle last resort GC and make sure to allow future allocations 13347 // Handle last resort GC and make sure to allow future allocations
13348 // to grow the heap without causing GCs (if possible). 13348 // to grow the heap without causing GCs (if possible).
13349 isolate->counters()->gc_last_resort_from_js()->Increment(); 13349 isolate->counters()->gc_last_resort_from_js()->Increment();
13350 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13350 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13351 "Runtime::PerformGC"); 13351 "Runtime::PerformGC");
13352 } 13352 }
13353 } 13353 }
13354 13354
13355 13355
13356 } } // namespace v8::internal 13356 } } // namespace v8::internal
OLDNEW
« src/heap.h ('K') | « src/profile-generator.cc ('k') | src/scopes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698