OLD | NEW |
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 Loading... |
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 native context. | 306 // use the map cache in the global 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 Loading... |
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 native context from the literals array. This is the | 345 // Get the global 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 native context | 348 // not use the object function from the current global 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::NativeContextFromLiterals(*literals)); | 352 Handle<Context>(JSFunction::GlobalContextFromLiterals(*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 Loading... |
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::NativeContextFromLiterals(*literals)->array_function()); | 467 JSFunction::GlobalContextFromLiterals(*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* native_context = isolate->context()->native_context(); | 477 Context* global_context = isolate->context()->global_context(); |
478 Object* maybe_maps_array = native_context->js_array_maps(); | 478 Object* maybe_maps_array = global_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 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1331 Handle<Object> error = | 1331 Handle<Object> error = |
1332 isolate->factory()->NewTypeError("redeclaration", HandleVector(args, 2)); | 1332 isolate->factory()->NewTypeError("redeclaration", HandleVector(args, 2)); |
1333 return isolate->Throw(*error); | 1333 return isolate->Throw(*error); |
1334 } | 1334 } |
1335 | 1335 |
1336 | 1336 |
1337 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeclareGlobals) { | 1337 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeclareGlobals) { |
1338 ASSERT(args.length() == 3); | 1338 ASSERT(args.length() == 3); |
1339 HandleScope scope(isolate); | 1339 HandleScope scope(isolate); |
1340 Handle<GlobalObject> global = Handle<GlobalObject>( | 1340 Handle<GlobalObject> global = Handle<GlobalObject>( |
1341 isolate->context()->global_object()); | 1341 isolate->context()->global()); |
1342 | 1342 |
1343 Handle<Context> context = args.at<Context>(0); | 1343 Handle<Context> context = args.at<Context>(0); |
1344 CONVERT_ARG_HANDLE_CHECKED(FixedArray, pairs, 1); | 1344 CONVERT_ARG_HANDLE_CHECKED(FixedArray, pairs, 1); |
1345 CONVERT_SMI_ARG_CHECKED(flags, 2); | 1345 CONVERT_SMI_ARG_CHECKED(flags, 2); |
1346 | 1346 |
1347 // Traverse the name/value pairs and set the properties. | 1347 // Traverse the name/value pairs and set the properties. |
1348 int length = pairs->length(); | 1348 int length = pairs->length(); |
1349 for (int i = 0; i < length; i += 2) { | 1349 for (int i = 0; i < length; i += 2) { |
1350 HandleScope scope(isolate); | 1350 HandleScope scope(isolate); |
1351 Handle<String> name(String::cast(pairs->get(i))); | 1351 Handle<String> name(String::cast(pairs->get(i))); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 native context. In the | 1449 // Declarations are always made in a function or global 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 Loading... |
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 native context. | 1488 // function context or the global object of a global 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1549 // args[0] == name | 1549 // args[0] == name |
1550 // args[1] == language_mode | 1550 // args[1] == language_mode |
1551 // args[2] == value (optional) | 1551 // args[2] == value (optional) |
1552 | 1552 |
1553 // Determine if we need to assign to the variable if it already | 1553 // Determine if we need to assign to the variable if it already |
1554 // exists (based on the number of arguments). | 1554 // exists (based on the number of arguments). |
1555 RUNTIME_ASSERT(args.length() == 2 || args.length() == 3); | 1555 RUNTIME_ASSERT(args.length() == 2 || args.length() == 3); |
1556 bool assign = args.length() == 3; | 1556 bool assign = args.length() == 3; |
1557 | 1557 |
1558 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); | 1558 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); |
1559 GlobalObject* global = isolate->context()->global_object(); | 1559 GlobalObject* global = isolate->context()->global(); |
1560 RUNTIME_ASSERT(args[1]->IsSmi()); | 1560 RUNTIME_ASSERT(args[1]->IsSmi()); |
1561 CONVERT_LANGUAGE_MODE_ARG(language_mode, 1); | 1561 CONVERT_LANGUAGE_MODE_ARG(language_mode, 1); |
1562 StrictModeFlag strict_mode_flag = (language_mode == CLASSIC_MODE) | 1562 StrictModeFlag strict_mode_flag = (language_mode == CLASSIC_MODE) |
1563 ? kNonStrictMode : kStrictMode; | 1563 ? kNonStrictMode : kStrictMode; |
1564 | 1564 |
1565 // According to ECMA-262, section 12.2, page 62, the property must | 1565 // According to ECMA-262, section 12.2, page 62, the property must |
1566 // not be deletable. | 1566 // not be deletable. |
1567 PropertyAttributes attributes = DONT_DELETE; | 1567 PropertyAttributes attributes = DONT_DELETE; |
1568 | 1568 |
1569 // Lookup the property locally in the global object. If it isn't | 1569 // Lookup the property locally in the global object. If it isn't |
(...skipping 22 matching lines...) Expand all Loading... |
1592 &lookup, *name, args[2], attributes, strict_mode_flag); | 1592 &lookup, *name, args[2], attributes, strict_mode_flag); |
1593 } else { | 1593 } else { |
1594 return isolate->heap()->undefined_value(); | 1594 return isolate->heap()->undefined_value(); |
1595 } | 1595 } |
1596 } | 1596 } |
1597 } | 1597 } |
1598 object = raw_holder->GetPrototype(); | 1598 object = raw_holder->GetPrototype(); |
1599 } | 1599 } |
1600 | 1600 |
1601 // Reload global in case the loop above performed a GC. | 1601 // Reload global in case the loop above performed a GC. |
1602 global = isolate->context()->global_object(); | 1602 global = isolate->context()->global(); |
1603 if (assign) { | 1603 if (assign) { |
1604 return global->SetProperty(*name, args[2], attributes, strict_mode_flag); | 1604 return global->SetProperty(*name, args[2], attributes, strict_mode_flag); |
1605 } | 1605 } |
1606 return isolate->heap()->undefined_value(); | 1606 return isolate->heap()->undefined_value(); |
1607 } | 1607 } |
1608 | 1608 |
1609 | 1609 |
1610 RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeConstGlobal) { | 1610 RUNTIME_FUNCTION(MaybeObject*, Runtime_InitializeConstGlobal) { |
1611 // All constants are declared with an initial value. The name | 1611 // All constants are declared with an initial value. The name |
1612 // of the constant is the first argument and the initial value | 1612 // of the constant is the first argument and the initial value |
1613 // is the second. | 1613 // is the second. |
1614 RUNTIME_ASSERT(args.length() == 2); | 1614 RUNTIME_ASSERT(args.length() == 2); |
1615 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); | 1615 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); |
1616 Handle<Object> value = args.at<Object>(1); | 1616 Handle<Object> value = args.at<Object>(1); |
1617 | 1617 |
1618 // Get the current global object from top. | 1618 // Get the current global object from top. |
1619 GlobalObject* global = isolate->context()->global_object(); | 1619 GlobalObject* global = isolate->context()->global(); |
1620 | 1620 |
1621 // According to ECMA-262, section 12.2, page 62, the property must | 1621 // According to ECMA-262, section 12.2, page 62, the property must |
1622 // not be deletable. Since it's a const, it must be READ_ONLY too. | 1622 // not be deletable. Since it's a const, it must be READ_ONLY too. |
1623 PropertyAttributes attributes = | 1623 PropertyAttributes attributes = |
1624 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY); | 1624 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY); |
1625 | 1625 |
1626 // Lookup the property locally in the global object. If it isn't | 1626 // Lookup the property locally in the global object. If it isn't |
1627 // there, we add the property and take special precautions to always | 1627 // there, we add the property and take special precautions to always |
1628 // add it as a local property even in case of callbacks in the | 1628 // add it as a local property even in case of callbacks in the |
1629 // prototype chain (this rules out using SetProperty). | 1629 // prototype chain (this rules out using SetProperty). |
1630 // We use SetLocalPropertyIgnoreAttributes instead | 1630 // We use SetLocalPropertyIgnoreAttributes instead |
1631 LookupResult lookup(isolate); | 1631 LookupResult lookup(isolate); |
1632 global->LocalLookup(*name, &lookup); | 1632 global->LocalLookup(*name, &lookup); |
1633 if (!lookup.IsFound()) { | 1633 if (!lookup.IsFound()) { |
1634 return global->SetLocalPropertyIgnoreAttributes(*name, | 1634 return global->SetLocalPropertyIgnoreAttributes(*name, |
1635 *value, | 1635 *value, |
1636 attributes); | 1636 attributes); |
1637 } | 1637 } |
1638 | 1638 |
1639 if (!lookup.IsReadOnly()) { | 1639 if (!lookup.IsReadOnly()) { |
1640 // Restore global object from context (in case of GC) and continue | 1640 // Restore global object from context (in case of GC) and continue |
1641 // with setting the value. | 1641 // with setting the value. |
1642 HandleScope handle_scope(isolate); | 1642 HandleScope handle_scope(isolate); |
1643 Handle<GlobalObject> global(isolate->context()->global_object()); | 1643 Handle<GlobalObject> global(isolate->context()->global()); |
1644 | 1644 |
1645 // BUG 1213575: Handle the case where we have to set a read-only | 1645 // BUG 1213575: Handle the case where we have to set a read-only |
1646 // property through an interceptor and only do it if it's | 1646 // property through an interceptor and only do it if it's |
1647 // uninitialized, e.g. the hole. Nirk... | 1647 // uninitialized, e.g. the hole. Nirk... |
1648 // Passing non-strict mode because the property is writable. | 1648 // Passing non-strict mode because the property is writable. |
1649 RETURN_IF_EMPTY_HANDLE( | 1649 RETURN_IF_EMPTY_HANDLE( |
1650 isolate, | 1650 isolate, |
1651 JSReceiver::SetProperty(global, name, value, attributes, | 1651 JSReceiver::SetProperty(global, name, value, attributes, |
1652 kNonStrictMode)); | 1652 kNonStrictMode)); |
1653 return *value; | 1653 return *value; |
(...skipping 25 matching lines...) Expand all Loading... |
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 native context. | 1689 // Initializations are always done in a function or global 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 = |
1700 context->Lookup(name, flags, &index, &attributes, &binding_flags); | 1700 context->Lookup(name, flags, &index, &attributes, &binding_flags); |
1701 | 1701 |
1702 if (index >= 0) { | 1702 if (index >= 0) { |
1703 ASSERT(holder->IsContext()); | 1703 ASSERT(holder->IsContext()); |
1704 // Property was found in a context. Perform the assignment if we | 1704 // Property was found in a context. Perform the assignment if we |
1705 // found some non-constant or an uninitialized constant. | 1705 // found some non-constant or an uninitialized constant. |
1706 Handle<Context> context = Handle<Context>::cast(holder); | 1706 Handle<Context> context = Handle<Context>::cast(holder); |
1707 if ((attributes & READ_ONLY) == 0 || context->get(index)->IsTheHole()) { | 1707 if ((attributes & READ_ONLY) == 0 || context->get(index)->IsTheHole()) { |
1708 context->set(index, *value); | 1708 context->set(index, *value); |
1709 } | 1709 } |
1710 return *value; | 1710 return *value; |
1711 } | 1711 } |
1712 | 1712 |
1713 // The property could not be found, we introduce it as a property of the | 1713 // The property could not be found, we introduce it as a property of the |
1714 // global object. | 1714 // global object. |
1715 if (attributes == ABSENT) { | 1715 if (attributes == ABSENT) { |
1716 Handle<JSObject> global = Handle<JSObject>( | 1716 Handle<JSObject> global = Handle<JSObject>( |
1717 isolate->context()->global_object()); | 1717 isolate->context()->global()); |
1718 // Strict mode not needed (const disallowed in strict mode). | 1718 // Strict mode not needed (const disallowed in strict mode). |
1719 RETURN_IF_EMPTY_HANDLE( | 1719 RETURN_IF_EMPTY_HANDLE( |
1720 isolate, | 1720 isolate, |
1721 JSReceiver::SetProperty(global, name, value, NONE, kNonStrictMode)); | 1721 JSReceiver::SetProperty(global, name, value, NONE, kNonStrictMode)); |
1722 return *value; | 1722 return *value; |
1723 } | 1723 } |
1724 | 1724 |
1725 // The property was present in some function's context extension object, | 1725 // The property was present in some function's context extension object, |
1726 // as a property on the subject of a with, or as a property of the global | 1726 // as a property on the subject of a with, or as a property of the global |
1727 // object. | 1727 // object. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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->native_context()->regexp_result_map()); | 1838 set_map(isolate->global_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 Loading... |
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* native_context = | 1990 Context* global_context = |
1991 function->context()->global_object()->native_context(); | 1991 function->context()->global()->global_context(); |
1992 return native_context->global_object()->global_receiver(); | 1992 return global_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 native context because this might be the RegExp function | 2007 // current global 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::NativeContextFromLiterals(*literals)->regexp_function()); | 2011 JSFunction::GlobalContextFromLiterals(*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 Loading... |
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::kLiteralNativeContextIndex, | 2265 literals->set(JSFunction::kLiteralGlobalContextIndex, |
2266 context->native_context()); | 2266 context->global_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 5896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8173 // called using 'new' and creates a new JSFunction object that | 8173 // called using 'new' and creates a new JSFunction object that |
8174 // is returned. The receiver object is only used for error | 8174 // is returned. The receiver object is only used for error |
8175 // reporting if an error occurs when constructing the new | 8175 // reporting if an error occurs when constructing the new |
8176 // JSFunction. FACTORY->NewJSObject() should not be used to | 8176 // JSFunction. FACTORY->NewJSObject() should not be used to |
8177 // allocate JSFunctions since it does not properly initialize | 8177 // allocate JSFunctions since it does not properly initialize |
8178 // the shared part of the function. Since the receiver is | 8178 // the shared part of the function. Since the receiver is |
8179 // ignored anyway, we use the global object as the receiver | 8179 // ignored anyway, we use the global object as the receiver |
8180 // instead of a new JSFunction object. This way, errors are | 8180 // instead of a new JSFunction object. This way, errors are |
8181 // reported the same way whether or not 'Function' is called | 8181 // reported the same way whether or not 'Function' is called |
8182 // using 'new'. | 8182 // using 'new'. |
8183 return isolate->context()->global_object(); | 8183 return isolate->context()->global(); |
8184 } | 8184 } |
8185 } | 8185 } |
8186 | 8186 |
8187 // The function should be compiled for the optimization hints to be | 8187 // The function should be compiled for the optimization hints to be |
8188 // available. | 8188 // available. |
8189 JSFunction::EnsureCompiled(function, CLEAR_EXCEPTION); | 8189 JSFunction::EnsureCompiled(function, CLEAR_EXCEPTION); |
8190 | 8190 |
8191 Handle<SharedFunctionInfo> shared(function->shared(), isolate); | 8191 Handle<SharedFunctionInfo> shared(function->shared(), isolate); |
8192 if (!function->has_initial_map() && | 8192 if (!function->has_initial_map() && |
8193 shared->IsInobjectSlackTrackingInProgress()) { | 8193 shared->IsInobjectSlackTrackingInProgress()) { |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8776 } else { | 8776 } else { |
8777 return maybe_js_object; | 8777 return maybe_js_object; |
8778 } | 8778 } |
8779 } | 8779 } |
8780 } | 8780 } |
8781 | 8781 |
8782 JSFunction* function; | 8782 JSFunction* function; |
8783 if (args[1]->IsSmi()) { | 8783 if (args[1]->IsSmi()) { |
8784 // A smi sentinel indicates a context nested inside global code rather | 8784 // A smi sentinel indicates a context nested inside global code rather |
8785 // than some function. There is a canonical empty function that can be | 8785 // than some function. There is a canonical empty function that can be |
8786 // gotten from the native context. | 8786 // gotten from the global context. |
8787 function = isolate->context()->native_context()->closure(); | 8787 function = isolate->context()->global_context()->closure(); |
8788 } else { | 8788 } else { |
8789 function = JSFunction::cast(args[1]); | 8789 function = JSFunction::cast(args[1]); |
8790 } | 8790 } |
8791 | 8791 |
8792 Context* context; | 8792 Context* context; |
8793 MaybeObject* maybe_context = | 8793 MaybeObject* maybe_context = |
8794 isolate->heap()->AllocateWithContext(function, | 8794 isolate->heap()->AllocateWithContext(function, |
8795 isolate->context(), | 8795 isolate->context(), |
8796 extension_object); | 8796 extension_object); |
8797 if (!maybe_context->To(&context)) return maybe_context; | 8797 if (!maybe_context->To(&context)) return maybe_context; |
8798 isolate->set_context(context); | 8798 isolate->set_context(context); |
8799 return context; | 8799 return context; |
8800 } | 8800 } |
8801 | 8801 |
8802 | 8802 |
8803 RUNTIME_FUNCTION(MaybeObject*, Runtime_PushCatchContext) { | 8803 RUNTIME_FUNCTION(MaybeObject*, Runtime_PushCatchContext) { |
8804 NoHandleAllocation ha; | 8804 NoHandleAllocation ha; |
8805 ASSERT(args.length() == 3); | 8805 ASSERT(args.length() == 3); |
8806 String* name = String::cast(args[0]); | 8806 String* name = String::cast(args[0]); |
8807 Object* thrown_object = args[1]; | 8807 Object* thrown_object = args[1]; |
8808 JSFunction* function; | 8808 JSFunction* function; |
8809 if (args[2]->IsSmi()) { | 8809 if (args[2]->IsSmi()) { |
8810 // A smi sentinel indicates a context nested inside global code rather | 8810 // A smi sentinel indicates a context nested inside global code rather |
8811 // than some function. There is a canonical empty function that can be | 8811 // than some function. There is a canonical empty function that can be |
8812 // gotten from the native context. | 8812 // gotten from the global context. |
8813 function = isolate->context()->native_context()->closure(); | 8813 function = isolate->context()->global_context()->closure(); |
8814 } else { | 8814 } else { |
8815 function = JSFunction::cast(args[2]); | 8815 function = JSFunction::cast(args[2]); |
8816 } | 8816 } |
8817 Context* context; | 8817 Context* context; |
8818 MaybeObject* maybe_context = | 8818 MaybeObject* maybe_context = |
8819 isolate->heap()->AllocateCatchContext(function, | 8819 isolate->heap()->AllocateCatchContext(function, |
8820 isolate->context(), | 8820 isolate->context(), |
8821 name, | 8821 name, |
8822 thrown_object); | 8822 thrown_object); |
8823 if (!maybe_context->To(&context)) return maybe_context; | 8823 if (!maybe_context->To(&context)) return maybe_context; |
8824 isolate->set_context(context); | 8824 isolate->set_context(context); |
8825 return context; | 8825 return context; |
8826 } | 8826 } |
8827 | 8827 |
8828 | 8828 |
8829 RUNTIME_FUNCTION(MaybeObject*, Runtime_PushBlockContext) { | 8829 RUNTIME_FUNCTION(MaybeObject*, Runtime_PushBlockContext) { |
8830 NoHandleAllocation ha; | 8830 NoHandleAllocation ha; |
8831 ASSERT(args.length() == 2); | 8831 ASSERT(args.length() == 2); |
8832 ScopeInfo* scope_info = ScopeInfo::cast(args[0]); | 8832 ScopeInfo* scope_info = ScopeInfo::cast(args[0]); |
8833 JSFunction* function; | 8833 JSFunction* function; |
8834 if (args[1]->IsSmi()) { | 8834 if (args[1]->IsSmi()) { |
8835 // A smi sentinel indicates a context nested inside global code rather | 8835 // A smi sentinel indicates a context nested inside global code rather |
8836 // than some function. There is a canonical empty function that can be | 8836 // than some function. There is a canonical empty function that can be |
8837 // gotten from the native context. | 8837 // gotten from the global context. |
8838 function = isolate->context()->native_context()->closure(); | 8838 function = isolate->context()->global_context()->closure(); |
8839 } else { | 8839 } else { |
8840 function = JSFunction::cast(args[1]); | 8840 function = JSFunction::cast(args[1]); |
8841 } | 8841 } |
8842 Context* context; | 8842 Context* context; |
8843 MaybeObject* maybe_context = | 8843 MaybeObject* maybe_context = |
8844 isolate->heap()->AllocateBlockContext(function, | 8844 isolate->heap()->AllocateBlockContext(function, |
8845 isolate->context(), | 8845 isolate->context(), |
8846 scope_info); | 8846 scope_info); |
8847 if (!maybe_context->To(&context)) return maybe_context; | 8847 if (!maybe_context->To(&context)) return maybe_context; |
8848 isolate->set_context(context); | 8848 isolate->set_context(context); |
(...skipping 12 matching lines...) Expand all Loading... |
8861 NoHandleAllocation ha; | 8861 NoHandleAllocation ha; |
8862 ASSERT(args.length() == 1); | 8862 ASSERT(args.length() == 1); |
8863 CONVERT_ARG_HANDLE_CHECKED(JSModule, instance, 0); | 8863 CONVERT_ARG_HANDLE_CHECKED(JSModule, instance, 0); |
8864 | 8864 |
8865 Context* context = Context::cast(instance->context()); | 8865 Context* context = Context::cast(instance->context()); |
8866 Context* previous = isolate->context(); | 8866 Context* previous = isolate->context(); |
8867 ASSERT(context->IsModuleContext()); | 8867 ASSERT(context->IsModuleContext()); |
8868 // Initialize the context links. | 8868 // Initialize the context links. |
8869 context->set_previous(previous); | 8869 context->set_previous(previous); |
8870 context->set_closure(previous->closure()); | 8870 context->set_closure(previous->closure()); |
8871 context->set_global_object(previous->global_object()); | 8871 context->set_global(previous->global()); |
8872 isolate->set_context(context); | 8872 isolate->set_context(context); |
8873 | 8873 |
8874 return context; | 8874 return context; |
8875 } | 8875 } |
8876 | 8876 |
8877 | 8877 |
8878 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeleteContextSlot) { | 8878 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeleteContextSlot) { |
8879 HandleScope scope(isolate); | 8879 HandleScope scope(isolate); |
8880 ASSERT(args.length() == 2); | 8880 ASSERT(args.length() == 2); |
8881 | 8881 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8947 return x->IsTheHole() ? heap->undefined_value() : x; | 8947 return x->IsTheHole() ? heap->undefined_value() : x; |
8948 } | 8948 } |
8949 | 8949 |
8950 | 8950 |
8951 static Object* ComputeReceiverForNonGlobal(Isolate* isolate, | 8951 static Object* ComputeReceiverForNonGlobal(Isolate* isolate, |
8952 JSObject* holder) { | 8952 JSObject* holder) { |
8953 ASSERT(!holder->IsGlobalObject()); | 8953 ASSERT(!holder->IsGlobalObject()); |
8954 Context* top = isolate->context(); | 8954 Context* top = isolate->context(); |
8955 // Get the context extension function. | 8955 // Get the context extension function. |
8956 JSFunction* context_extension_function = | 8956 JSFunction* context_extension_function = |
8957 top->native_context()->context_extension_function(); | 8957 top->global_context()->context_extension_function(); |
8958 // If the holder isn't a context extension object, we just return it | 8958 // If the holder isn't a context extension object, we just return it |
8959 // as the receiver. This allows arguments objects to be used as | 8959 // as the receiver. This allows arguments objects to be used as |
8960 // receivers, but only if they are put in the context scope chain | 8960 // receivers, but only if they are put in the context scope chain |
8961 // explicitly via a with-statement. | 8961 // explicitly via a with-statement. |
8962 Object* constructor = holder->map()->constructor(); | 8962 Object* constructor = holder->map()->constructor(); |
8963 if (constructor != context_extension_function) return holder; | 8963 if (constructor != context_extension_function) return holder; |
8964 // Fall back to using the global object as the implicit receiver if | 8964 // Fall back to using the global object as the implicit receiver if |
8965 // the property turns out to be a local variable allocated in a | 8965 // the property turns out to be a local variable allocated in a |
8966 // context extension object - introduced via eval. Implicit global | 8966 // context extension object - introduced via eval. Implicit global |
8967 // receivers are indicated with the hole value. | 8967 // receivers are indicated with the hole value. |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9126 | 9126 |
9127 if (strict_mode == kStrictMode) { | 9127 if (strict_mode == kStrictMode) { |
9128 // Throw in strict mode (assignment to undefined variable). | 9128 // Throw in strict mode (assignment to undefined variable). |
9129 Handle<Object> error = | 9129 Handle<Object> error = |
9130 isolate->factory()->NewReferenceError( | 9130 isolate->factory()->NewReferenceError( |
9131 "not_defined", HandleVector(&name, 1)); | 9131 "not_defined", HandleVector(&name, 1)); |
9132 return isolate->Throw(*error); | 9132 return isolate->Throw(*error); |
9133 } | 9133 } |
9134 // In non-strict mode, the property is added to the global object. | 9134 // In non-strict mode, the property is added to the global object. |
9135 attributes = NONE; | 9135 attributes = NONE; |
9136 object = Handle<JSObject>(isolate->context()->global_object()); | 9136 object = Handle<JSObject>(isolate->context()->global()); |
9137 } | 9137 } |
9138 | 9138 |
9139 // Set the property if it's not read only or doesn't yet exist. | 9139 // Set the property if it's not read only or doesn't yet exist. |
9140 if ((attributes & READ_ONLY) == 0 || | 9140 if ((attributes & READ_ONLY) == 0 || |
9141 (object->GetLocalPropertyAttribute(*name) == ABSENT)) { | 9141 (object->GetLocalPropertyAttribute(*name) == ABSENT)) { |
9142 RETURN_IF_EMPTY_HANDLE( | 9142 RETURN_IF_EMPTY_HANDLE( |
9143 isolate, | 9143 isolate, |
9144 JSReceiver::SetProperty(object, name, value, NONE, strict_mode)); | 9144 JSReceiver::SetProperty(object, name, value, NONE, strict_mode)); |
9145 } else if (strict_mode == kStrictMode && (attributes & READ_ONLY) != 0) { | 9145 } else if (strict_mode == kStrictMode && (attributes & READ_ONLY) != 0) { |
9146 // Setting read only property in strict mode. | 9146 // Setting read only property in strict mode. |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9409 return callback(v8::Utils::ToLocal(context)); | 9409 return callback(v8::Utils::ToLocal(context)); |
9410 } | 9410 } |
9411 } | 9411 } |
9412 | 9412 |
9413 | 9413 |
9414 RUNTIME_FUNCTION(MaybeObject*, Runtime_CompileString) { | 9414 RUNTIME_FUNCTION(MaybeObject*, Runtime_CompileString) { |
9415 HandleScope scope(isolate); | 9415 HandleScope scope(isolate); |
9416 ASSERT_EQ(1, args.length()); | 9416 ASSERT_EQ(1, args.length()); |
9417 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); | 9417 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); |
9418 | 9418 |
9419 // Extract native context. | 9419 // Extract global context. |
9420 Handle<Context> context(isolate->context()->native_context()); | 9420 Handle<Context> context(isolate->context()->global_context()); |
9421 | 9421 |
9422 // Check if native context allows code generation from | 9422 // Check if global context allows code generation from |
9423 // strings. Throw an exception if it doesn't. | 9423 // strings. Throw an exception if it doesn't. |
9424 if (context->allow_code_gen_from_strings()->IsFalse() && | 9424 if (context->allow_code_gen_from_strings()->IsFalse() && |
9425 !CodeGenerationFromStringsAllowed(isolate, context)) { | 9425 !CodeGenerationFromStringsAllowed(isolate, context)) { |
9426 return isolate->Throw(*isolate->factory()->NewError( | 9426 return isolate->Throw(*isolate->factory()->NewError( |
9427 "code_gen_from_strings", HandleVector<Object>(NULL, 0))); | 9427 "code_gen_from_strings", HandleVector<Object>(NULL, 0))); |
9428 } | 9428 } |
9429 | 9429 |
9430 // Compile source string in the native context. | 9430 // Compile source string in the global context. |
9431 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( | 9431 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( |
9432 source, context, true, CLASSIC_MODE, RelocInfo::kNoPosition); | 9432 source, context, true, CLASSIC_MODE, RelocInfo::kNoPosition); |
9433 if (shared.is_null()) return Failure::Exception(); | 9433 if (shared.is_null()) return Failure::Exception(); |
9434 Handle<JSFunction> fun = | 9434 Handle<JSFunction> fun = |
9435 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, | 9435 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, |
9436 context, | 9436 context, |
9437 NOT_TENURED); | 9437 NOT_TENURED); |
9438 return *fun; | 9438 return *fun; |
9439 } | 9439 } |
9440 | 9440 |
9441 | 9441 |
9442 static ObjectPair CompileGlobalEval(Isolate* isolate, | 9442 static ObjectPair CompileGlobalEval(Isolate* isolate, |
9443 Handle<String> source, | 9443 Handle<String> source, |
9444 Handle<Object> receiver, | 9444 Handle<Object> receiver, |
9445 LanguageMode language_mode, | 9445 LanguageMode language_mode, |
9446 int scope_position) { | 9446 int scope_position) { |
9447 Handle<Context> context = Handle<Context>(isolate->context()); | 9447 Handle<Context> context = Handle<Context>(isolate->context()); |
9448 Handle<Context> native_context = Handle<Context>(context->native_context()); | 9448 Handle<Context> global_context = Handle<Context>(context->global_context()); |
9449 | 9449 |
9450 // Check if native context allows code generation from | 9450 // Check if global context allows code generation from |
9451 // strings. Throw an exception if it doesn't. | 9451 // strings. Throw an exception if it doesn't. |
9452 if (native_context->allow_code_gen_from_strings()->IsFalse() && | 9452 if (global_context->allow_code_gen_from_strings()->IsFalse() && |
9453 !CodeGenerationFromStringsAllowed(isolate, native_context)) { | 9453 !CodeGenerationFromStringsAllowed(isolate, global_context)) { |
9454 isolate->Throw(*isolate->factory()->NewError( | 9454 isolate->Throw(*isolate->factory()->NewError( |
9455 "code_gen_from_strings", HandleVector<Object>(NULL, 0))); | 9455 "code_gen_from_strings", HandleVector<Object>(NULL, 0))); |
9456 return MakePair(Failure::Exception(), NULL); | 9456 return MakePair(Failure::Exception(), NULL); |
9457 } | 9457 } |
9458 | 9458 |
9459 // Deal with a normal eval call with a string argument. Compile it | 9459 // Deal with a normal eval call with a string argument. Compile it |
9460 // and return the compiled function bound in the local context. | 9460 // and return the compiled function bound in the local context. |
9461 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( | 9461 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( |
9462 source, | 9462 source, |
9463 Handle<Context>(isolate->context()), | 9463 Handle<Context>(isolate->context()), |
9464 context->IsNativeContext(), | 9464 context->IsGlobalContext(), |
9465 language_mode, | 9465 language_mode, |
9466 scope_position); | 9466 scope_position); |
9467 if (shared.is_null()) return MakePair(Failure::Exception(), NULL); | 9467 if (shared.is_null()) return MakePair(Failure::Exception(), NULL); |
9468 Handle<JSFunction> compiled = | 9468 Handle<JSFunction> compiled = |
9469 isolate->factory()->NewFunctionFromSharedFunctionInfo( | 9469 isolate->factory()->NewFunctionFromSharedFunctionInfo( |
9470 shared, context, NOT_TENURED); | 9470 shared, context, NOT_TENURED); |
9471 return MakePair(*compiled, *receiver); | 9471 return MakePair(*compiled, *receiver); |
9472 } | 9472 } |
9473 | 9473 |
9474 | 9474 |
9475 RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEval) { | 9475 RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEval) { |
9476 ASSERT(args.length() == 5); | 9476 ASSERT(args.length() == 5); |
9477 | 9477 |
9478 HandleScope scope(isolate); | 9478 HandleScope scope(isolate); |
9479 Handle<Object> callee = args.at<Object>(0); | 9479 Handle<Object> callee = args.at<Object>(0); |
9480 | 9480 |
9481 // If "eval" didn't refer to the original GlobalEval, it's not a | 9481 // If "eval" didn't refer to the original GlobalEval, it's not a |
9482 // direct call to eval. | 9482 // direct call to eval. |
9483 // (And even if it is, but the first argument isn't a string, just let | 9483 // (And even if it is, but the first argument isn't a string, just let |
9484 // execution default to an indirect call to eval, which will also return | 9484 // execution default to an indirect call to eval, which will also return |
9485 // the first argument without doing anything). | 9485 // the first argument without doing anything). |
9486 if (*callee != isolate->native_context()->global_eval_fun() || | 9486 if (*callee != isolate->global_context()->global_eval_fun() || |
9487 !args[1]->IsString()) { | 9487 !args[1]->IsString()) { |
9488 return MakePair(*callee, isolate->heap()->the_hole_value()); | 9488 return MakePair(*callee, isolate->heap()->the_hole_value()); |
9489 } | 9489 } |
9490 | 9490 |
9491 CONVERT_LANGUAGE_MODE_ARG(language_mode, 3); | 9491 CONVERT_LANGUAGE_MODE_ARG(language_mode, 3); |
9492 ASSERT(args[4]->IsSmi()); | 9492 ASSERT(args[4]->IsSmi()); |
9493 return CompileGlobalEval(isolate, | 9493 return CompileGlobalEval(isolate, |
9494 args.at<String>(1), | 9494 args.at<String>(1), |
9495 args.at<Object>(2), | 9495 args.at<Object>(2), |
9496 language_mode, | 9496 language_mode, |
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10381 | 10381 |
10382 ASSERT(args.length() == 2); | 10382 ASSERT(args.length() == 2); |
10383 | 10383 |
10384 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); | 10384 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); |
10385 CONVERT_ARG_HANDLE_CHECKED(String, name, 1); | 10385 CONVERT_ARG_HANDLE_CHECKED(String, name, 1); |
10386 | 10386 |
10387 // Make sure to set the current context to the context before the debugger was | 10387 // Make sure to set the current context to the context before the debugger was |
10388 // entered (if the debugger is entered). The reason for switching context here | 10388 // entered (if the debugger is entered). The reason for switching context here |
10389 // is that for some property lookups (accessors and interceptors) callbacks | 10389 // is that for some property lookups (accessors and interceptors) callbacks |
10390 // into the embedding application can occour, and the embedding application | 10390 // into the embedding application can occour, and the embedding application |
10391 // could have the assumption that its own native context is the current | 10391 // could have the assumption that its own global context is the current |
10392 // context and not some internal debugger context. | 10392 // context and not some internal debugger context. |
10393 SaveContext save(isolate); | 10393 SaveContext save(isolate); |
10394 if (isolate->debug()->InDebugger()) { | 10394 if (isolate->debug()->InDebugger()) { |
10395 isolate->set_context(*isolate->debug()->debugger_entry()->GetContext()); | 10395 isolate->set_context(*isolate->debug()->debugger_entry()->GetContext()); |
10396 } | 10396 } |
10397 | 10397 |
10398 // Skip the global proxy as it has no properties and always delegates to the | 10398 // Skip the global proxy as it has no properties and always delegates to the |
10399 // real global object. | 10399 // real global object. |
10400 if (obj->IsJSGlobalProxy()) { | 10400 if (obj->IsJSGlobalProxy()) { |
10401 obj = Handle<JSObject>(JSObject::cast(obj->GetPrototype())); | 10401 obj = Handle<JSObject>(JSObject::cast(obj->GetPrototype())); |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10926 // THE FRAME ITERATOR TO WRAP THE RECEIVER. | 10926 // THE FRAME ITERATOR TO WRAP THE RECEIVER. |
10927 Handle<Object> receiver(it.frame()->receiver(), isolate); | 10927 Handle<Object> receiver(it.frame()->receiver(), isolate); |
10928 if (!receiver->IsJSObject() && | 10928 if (!receiver->IsJSObject() && |
10929 shared->is_classic_mode() && | 10929 shared->is_classic_mode() && |
10930 !shared->native()) { | 10930 !shared->native()) { |
10931 // If the receiver is not a JSObject and the function is not a | 10931 // If the receiver is not a JSObject and the function is not a |
10932 // builtin or strict-mode we have hit an optimization where a | 10932 // builtin or strict-mode we have hit an optimization where a |
10933 // value object is not converted into a wrapped JS objects. To | 10933 // value object is not converted into a wrapped JS objects. To |
10934 // hide this optimization from the debugger, we wrap the receiver | 10934 // hide this optimization from the debugger, we wrap the receiver |
10935 // by creating correct wrapper object based on the calling frame's | 10935 // by creating correct wrapper object based on the calling frame's |
10936 // native context. | 10936 // global context. |
10937 it.Advance(); | 10937 it.Advance(); |
10938 Handle<Context> calling_frames_native_context( | 10938 Handle<Context> calling_frames_global_context( |
10939 Context::cast(Context::cast(it.frame()->context())->native_context())); | 10939 Context::cast(Context::cast(it.frame()->context())->global_context())); |
10940 receiver = | 10940 receiver = |
10941 isolate->factory()->ToObject(receiver, calling_frames_native_context); | 10941 isolate->factory()->ToObject(receiver, calling_frames_global_context); |
10942 } | 10942 } |
10943 details->set(kFrameDetailsReceiverIndex, *receiver); | 10943 details->set(kFrameDetailsReceiverIndex, *receiver); |
10944 | 10944 |
10945 ASSERT_EQ(details_size, details_index); | 10945 ASSERT_EQ(details_size, details_index); |
10946 return *isolate->factory()->NewJSArrayWithElements(details); | 10946 return *isolate->factory()->NewJSArrayWithElements(details); |
10947 } | 10947 } |
10948 | 10948 |
10949 | 10949 |
10950 // Copy all the context locals into an object used to materialize a scope. | 10950 // Copy all the context locals into an object used to materialize a scope. |
10951 static bool CopyContextLocalsToScopeObject( | 10951 static bool CopyContextLocalsToScopeObject( |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11023 Handle<Context> function_context(frame_context->declaration_context()); | 11023 Handle<Context> function_context(frame_context->declaration_context()); |
11024 if (!CopyContextLocalsToScopeObject( | 11024 if (!CopyContextLocalsToScopeObject( |
11025 isolate, scope_info, function_context, local_scope)) { | 11025 isolate, scope_info, function_context, local_scope)) { |
11026 return Handle<JSObject>(); | 11026 return Handle<JSObject>(); |
11027 } | 11027 } |
11028 | 11028 |
11029 // Finally copy any properties from the function context extension. | 11029 // Finally copy any properties from the function context extension. |
11030 // These will be variables introduced by eval. | 11030 // These will be variables introduced by eval. |
11031 if (function_context->closure() == *function) { | 11031 if (function_context->closure() == *function) { |
11032 if (function_context->has_extension() && | 11032 if (function_context->has_extension() && |
11033 !function_context->IsNativeContext()) { | 11033 !function_context->IsGlobalContext()) { |
11034 Handle<JSObject> ext(JSObject::cast(function_context->extension())); | 11034 Handle<JSObject> ext(JSObject::cast(function_context->extension())); |
11035 bool threw = false; | 11035 bool threw = false; |
11036 Handle<FixedArray> keys = | 11036 Handle<FixedArray> keys = |
11037 GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS, &threw); | 11037 GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS, &threw); |
11038 if (threw) return Handle<JSObject>(); | 11038 if (threw) return Handle<JSObject>(); |
11039 | 11039 |
11040 for (int i = 0; i < keys->length(); i++) { | 11040 for (int i = 0; i < keys->length(); i++) { |
11041 // Names of variables introduced by eval are strings. | 11041 // Names of variables introduced by eval are strings. |
11042 ASSERT(keys->get(i)->IsString()); | 11042 ASSERT(keys->get(i)->IsString()); |
11043 Handle<String> key(String::cast(keys->get(i))); | 11043 Handle<String> key(String::cast(keys->get(i))); |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11285 } | 11285 } |
11286 | 11286 |
11287 // More scopes? | 11287 // More scopes? |
11288 bool Done() { return context_.is_null(); } | 11288 bool Done() { return context_.is_null(); } |
11289 | 11289 |
11290 // Move to the next scope. | 11290 // Move to the next scope. |
11291 void Next() { | 11291 void Next() { |
11292 ScopeType scope_type = Type(); | 11292 ScopeType scope_type = Type(); |
11293 if (scope_type == ScopeTypeGlobal) { | 11293 if (scope_type == ScopeTypeGlobal) { |
11294 // The global scope is always the last in the chain. | 11294 // The global scope is always the last in the chain. |
11295 ASSERT(context_->IsNativeContext()); | 11295 ASSERT(context_->IsGlobalContext()); |
11296 context_ = Handle<Context>(); | 11296 context_ = Handle<Context>(); |
11297 return; | 11297 return; |
11298 } | 11298 } |
11299 if (nested_scope_chain_.is_empty()) { | 11299 if (nested_scope_chain_.is_empty()) { |
11300 context_ = Handle<Context>(context_->previous(), isolate_); | 11300 context_ = Handle<Context>(context_->previous(), isolate_); |
11301 } else { | 11301 } else { |
11302 if (nested_scope_chain_.last()->HasContext()) { | 11302 if (nested_scope_chain_.last()->HasContext()) { |
11303 ASSERT(context_->previous() != NULL); | 11303 ASSERT(context_->previous() != NULL); |
11304 context_ = Handle<Context>(context_->previous(), isolate_); | 11304 context_ = Handle<Context>(context_->previous(), isolate_); |
11305 } | 11305 } |
11306 nested_scope_chain_.RemoveLast(); | 11306 nested_scope_chain_.RemoveLast(); |
11307 } | 11307 } |
11308 } | 11308 } |
11309 | 11309 |
11310 // Return the type of the current scope. | 11310 // Return the type of the current scope. |
11311 ScopeType Type() { | 11311 ScopeType Type() { |
11312 if (!nested_scope_chain_.is_empty()) { | 11312 if (!nested_scope_chain_.is_empty()) { |
11313 Handle<ScopeInfo> scope_info = nested_scope_chain_.last(); | 11313 Handle<ScopeInfo> scope_info = nested_scope_chain_.last(); |
11314 switch (scope_info->Type()) { | 11314 switch (scope_info->Type()) { |
11315 case FUNCTION_SCOPE: | 11315 case FUNCTION_SCOPE: |
11316 ASSERT(context_->IsFunctionContext() || | 11316 ASSERT(context_->IsFunctionContext() || |
11317 !scope_info->HasContext()); | 11317 !scope_info->HasContext()); |
11318 return ScopeTypeLocal; | 11318 return ScopeTypeLocal; |
11319 case MODULE_SCOPE: | 11319 case MODULE_SCOPE: |
11320 ASSERT(context_->IsModuleContext()); | 11320 ASSERT(context_->IsModuleContext()); |
11321 return ScopeTypeModule; | 11321 return ScopeTypeModule; |
11322 case GLOBAL_SCOPE: | 11322 case GLOBAL_SCOPE: |
11323 ASSERT(context_->IsNativeContext()); | 11323 ASSERT(context_->IsGlobalContext()); |
11324 return ScopeTypeGlobal; | 11324 return ScopeTypeGlobal; |
11325 case WITH_SCOPE: | 11325 case WITH_SCOPE: |
11326 ASSERT(context_->IsWithContext()); | 11326 ASSERT(context_->IsWithContext()); |
11327 return ScopeTypeWith; | 11327 return ScopeTypeWith; |
11328 case CATCH_SCOPE: | 11328 case CATCH_SCOPE: |
11329 ASSERT(context_->IsCatchContext()); | 11329 ASSERT(context_->IsCatchContext()); |
11330 return ScopeTypeCatch; | 11330 return ScopeTypeCatch; |
11331 case BLOCK_SCOPE: | 11331 case BLOCK_SCOPE: |
11332 ASSERT(!scope_info->HasContext() || | 11332 ASSERT(!scope_info->HasContext() || |
11333 context_->IsBlockContext()); | 11333 context_->IsBlockContext()); |
11334 return ScopeTypeBlock; | 11334 return ScopeTypeBlock; |
11335 case EVAL_SCOPE: | 11335 case EVAL_SCOPE: |
11336 UNREACHABLE(); | 11336 UNREACHABLE(); |
11337 } | 11337 } |
11338 } | 11338 } |
11339 if (context_->IsNativeContext()) { | 11339 if (context_->IsGlobalContext()) { |
11340 ASSERT(context_->global_object()->IsGlobalObject()); | 11340 ASSERT(context_->global()->IsGlobalObject()); |
11341 return ScopeTypeGlobal; | 11341 return ScopeTypeGlobal; |
11342 } | 11342 } |
11343 if (context_->IsFunctionContext()) { | 11343 if (context_->IsFunctionContext()) { |
11344 return ScopeTypeClosure; | 11344 return ScopeTypeClosure; |
11345 } | 11345 } |
11346 if (context_->IsCatchContext()) { | 11346 if (context_->IsCatchContext()) { |
11347 return ScopeTypeCatch; | 11347 return ScopeTypeCatch; |
11348 } | 11348 } |
11349 if (context_->IsBlockContext()) { | 11349 if (context_->IsBlockContext()) { |
11350 return ScopeTypeBlock; | 11350 return ScopeTypeBlock; |
11351 } | 11351 } |
11352 if (context_->IsModuleContext()) { | 11352 if (context_->IsModuleContext()) { |
11353 return ScopeTypeModule; | 11353 return ScopeTypeModule; |
11354 } | 11354 } |
11355 ASSERT(context_->IsWithContext()); | 11355 ASSERT(context_->IsWithContext()); |
11356 return ScopeTypeWith; | 11356 return ScopeTypeWith; |
11357 } | 11357 } |
11358 | 11358 |
11359 // Return the JavaScript object with the content of the current scope. | 11359 // Return the JavaScript object with the content of the current scope. |
11360 Handle<JSObject> ScopeObject() { | 11360 Handle<JSObject> ScopeObject() { |
11361 switch (Type()) { | 11361 switch (Type()) { |
11362 case ScopeIterator::ScopeTypeGlobal: | 11362 case ScopeIterator::ScopeTypeGlobal: |
11363 return Handle<JSObject>(CurrentContext()->global_object()); | 11363 return Handle<JSObject>(CurrentContext()->global()); |
11364 case ScopeIterator::ScopeTypeLocal: | 11364 case ScopeIterator::ScopeTypeLocal: |
11365 // Materialize the content of the local scope into a JSObject. | 11365 // Materialize the content of the local scope into a JSObject. |
11366 ASSERT(nested_scope_chain_.length() == 1); | 11366 ASSERT(nested_scope_chain_.length() == 1); |
11367 return MaterializeLocalScope(isolate_, frame_, inlined_jsframe_index_); | 11367 return MaterializeLocalScope(isolate_, frame_, inlined_jsframe_index_); |
11368 case ScopeIterator::ScopeTypeWith: | 11368 case ScopeIterator::ScopeTypeWith: |
11369 // Return the with object. | 11369 // Return the with object. |
11370 return Handle<JSObject>(JSObject::cast(CurrentContext()->extension())); | 11370 return Handle<JSObject>(JSObject::cast(CurrentContext()->extension())); |
11371 case ScopeIterator::ScopeTypeCatch: | 11371 case ScopeIterator::ScopeTypeCatch: |
11372 return MaterializeCatchScope(isolate_, CurrentContext()); | 11372 return MaterializeCatchScope(isolate_, CurrentContext()); |
11373 case ScopeIterator::ScopeTypeClosure: | 11373 case ScopeIterator::ScopeTypeClosure: |
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12218 | 12218 |
12219 Handle<String> function_source = | 12219 Handle<String> function_source = |
12220 isolate->factory()->NewStringFromAscii( | 12220 isolate->factory()->NewStringFromAscii( |
12221 Vector<const char>(kSourceStr, sizeof(kSourceStr) - 1)); | 12221 Vector<const char>(kSourceStr, sizeof(kSourceStr) - 1)); |
12222 | 12222 |
12223 // Currently, the eval code will be executed in non-strict mode, | 12223 // Currently, the eval code will be executed in non-strict mode, |
12224 // even in the strict code context. | 12224 // even in the strict code context. |
12225 Handle<SharedFunctionInfo> shared = | 12225 Handle<SharedFunctionInfo> shared = |
12226 Compiler::CompileEval(function_source, | 12226 Compiler::CompileEval(function_source, |
12227 context, | 12227 context, |
12228 context->IsNativeContext(), | 12228 context->IsGlobalContext(), |
12229 CLASSIC_MODE, | 12229 CLASSIC_MODE, |
12230 RelocInfo::kNoPosition); | 12230 RelocInfo::kNoPosition); |
12231 if (shared.is_null()) return Failure::Exception(); | 12231 if (shared.is_null()) return Failure::Exception(); |
12232 Handle<JSFunction> compiled_function = | 12232 Handle<JSFunction> compiled_function = |
12233 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context); | 12233 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context); |
12234 | 12234 |
12235 // Invoke the result of the compilation to get the evaluation function. | 12235 // Invoke the result of the compilation to get the evaluation function. |
12236 bool has_pending_exception; | 12236 bool has_pending_exception; |
12237 Handle<Object> receiver(frame->receiver(), isolate); | 12237 Handle<Object> receiver(frame->receiver(), isolate); |
12238 Handle<Object> evaluation_function = | 12238 Handle<Object> evaluation_function = |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12289 // Enter the top context from before the debugger was invoked. | 12289 // Enter the top context from before the debugger was invoked. |
12290 SaveContext save(isolate); | 12290 SaveContext save(isolate); |
12291 SaveContext* top = &save; | 12291 SaveContext* top = &save; |
12292 while (top != NULL && *top->context() == *isolate->debug()->debug_context()) { | 12292 while (top != NULL && *top->context() == *isolate->debug()->debug_context()) { |
12293 top = top->prev(); | 12293 top = top->prev(); |
12294 } | 12294 } |
12295 if (top != NULL) { | 12295 if (top != NULL) { |
12296 isolate->set_context(*top->context()); | 12296 isolate->set_context(*top->context()); |
12297 } | 12297 } |
12298 | 12298 |
12299 // Get the native context now set to the top context from before the | 12299 // Get the global context now set to the top context from before the |
12300 // debugger was invoked. | 12300 // debugger was invoked. |
12301 Handle<Context> context = isolate->native_context(); | 12301 Handle<Context> context = isolate->global_context(); |
12302 | 12302 |
12303 bool is_global = true; | 12303 bool is_global = true; |
12304 | 12304 |
12305 if (additional_context->IsJSObject()) { | 12305 if (additional_context->IsJSObject()) { |
12306 // Create a new with context with the additional context information between | 12306 // Create a new with context with the additional context information between |
12307 // the context of the debugged function and the eval code to be executed. | 12307 // the context of the debugged function and the eval code to be executed. |
12308 context = isolate->factory()->NewWithContext( | 12308 context = isolate->factory()->NewWithContext( |
12309 Handle<JSFunction>(context->closure()), | 12309 Handle<JSFunction>(context->closure()), |
12310 context, | 12310 context, |
12311 Handle<JSObject>::cast(additional_context)); | 12311 Handle<JSObject>::cast(additional_context)); |
(...skipping 10 matching lines...) Expand all Loading... |
12322 CLASSIC_MODE, | 12322 CLASSIC_MODE, |
12323 RelocInfo::kNoPosition); | 12323 RelocInfo::kNoPosition); |
12324 if (shared.is_null()) return Failure::Exception(); | 12324 if (shared.is_null()) return Failure::Exception(); |
12325 Handle<JSFunction> compiled_function = | 12325 Handle<JSFunction> compiled_function = |
12326 Handle<JSFunction>( | 12326 Handle<JSFunction>( |
12327 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, | 12327 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, |
12328 context)); | 12328 context)); |
12329 | 12329 |
12330 // Invoke the result of the compilation to get the evaluation function. | 12330 // Invoke the result of the compilation to get the evaluation function. |
12331 bool has_pending_exception; | 12331 bool has_pending_exception; |
12332 Handle<Object> receiver = isolate->global_object(); | 12332 Handle<Object> receiver = isolate->global(); |
12333 Handle<Object> result = | 12333 Handle<Object> result = |
12334 Execution::Call(compiled_function, receiver, 0, NULL, | 12334 Execution::Call(compiled_function, receiver, 0, NULL, |
12335 &has_pending_exception); | 12335 &has_pending_exception); |
12336 // Clear the oneshot breakpoints so that the debugger does not step further. | 12336 // Clear the oneshot breakpoints so that the debugger does not step further. |
12337 isolate->debug()->ClearStepping(); | 12337 isolate->debug()->ClearStepping(); |
12338 if (has_pending_exception) return Failure::Exception(); | 12338 if (has_pending_exception) return Failure::Exception(); |
12339 return *result; | 12339 return *result; |
12340 } | 12340 } |
12341 | 12341 |
12342 | 12342 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12456 CONVERT_ARG_CHECKED(JSObject, target, 0); | 12456 CONVERT_ARG_CHECKED(JSObject, target, 0); |
12457 Object* instance_filter = args[1]; | 12457 Object* instance_filter = args[1]; |
12458 RUNTIME_ASSERT(instance_filter->IsUndefined() || | 12458 RUNTIME_ASSERT(instance_filter->IsUndefined() || |
12459 instance_filter->IsJSObject()); | 12459 instance_filter->IsJSObject()); |
12460 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]); | 12460 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]); |
12461 RUNTIME_ASSERT(max_references >= 0); | 12461 RUNTIME_ASSERT(max_references >= 0); |
12462 | 12462 |
12463 | 12463 |
12464 // Get the constructor function for context extension and arguments array. | 12464 // Get the constructor function for context extension and arguments array. |
12465 JSObject* arguments_boilerplate = | 12465 JSObject* arguments_boilerplate = |
12466 isolate->context()->native_context()->arguments_boilerplate(); | 12466 isolate->context()->global_context()->arguments_boilerplate(); |
12467 JSFunction* arguments_function = | 12467 JSFunction* arguments_function = |
12468 JSFunction::cast(arguments_boilerplate->map()->constructor()); | 12468 JSFunction::cast(arguments_boilerplate->map()->constructor()); |
12469 | 12469 |
12470 // Get the number of referencing objects. | 12470 // Get the number of referencing objects. |
12471 int count; | 12471 int count; |
12472 HeapIterator heap_iterator; | 12472 HeapIterator heap_iterator; |
12473 count = DebugReferencedBy(&heap_iterator, | 12473 count = DebugReferencedBy(&heap_iterator, |
12474 target, instance_filter, max_references, | 12474 target, instance_filter, max_references, |
12475 NULL, 0, arguments_function); | 12475 NULL, 0, arguments_function); |
12476 | 12476 |
12477 // Allocate an array to hold the result. | 12477 // Allocate an array to hold the result. |
12478 Object* object; | 12478 Object* object; |
12479 { MaybeObject* maybe_object = isolate->heap()->AllocateFixedArray(count); | 12479 { MaybeObject* maybe_object = isolate->heap()->AllocateFixedArray(count); |
12480 if (!maybe_object->ToObject(&object)) return maybe_object; | 12480 if (!maybe_object->ToObject(&object)) return maybe_object; |
12481 } | 12481 } |
12482 FixedArray* instances = FixedArray::cast(object); | 12482 FixedArray* instances = FixedArray::cast(object); |
12483 | 12483 |
12484 // Fill the referencing objects. | 12484 // Fill the referencing objects. |
12485 // AllocateFixedArray above does not make the heap non-iterable. | 12485 // AllocateFixedArray above does not make the heap non-iterable. |
12486 ASSERT(HEAP->IsHeapIterable()); | 12486 ASSERT(HEAP->IsHeapIterable()); |
12487 HeapIterator heap_iterator2; | 12487 HeapIterator heap_iterator2; |
12488 count = DebugReferencedBy(&heap_iterator2, | 12488 count = DebugReferencedBy(&heap_iterator2, |
12489 target, instance_filter, max_references, | 12489 target, instance_filter, max_references, |
12490 instances, count, arguments_function); | 12490 instances, count, arguments_function); |
12491 | 12491 |
12492 // Return result as JS array. | 12492 // Return result as JS array. |
12493 Object* result; | 12493 Object* result; |
12494 MaybeObject* maybe_result = isolate->heap()->AllocateJSObject( | 12494 MaybeObject* maybe_result = isolate->heap()->AllocateJSObject( |
12495 isolate->context()->native_context()->array_function()); | 12495 isolate->context()->global_context()->array_function()); |
12496 if (!maybe_result->ToObject(&result)) return maybe_result; | 12496 if (!maybe_result->ToObject(&result)) return maybe_result; |
12497 return JSArray::cast(result)->SetContent(instances); | 12497 return JSArray::cast(result)->SetContent(instances); |
12498 } | 12498 } |
12499 | 12499 |
12500 | 12500 |
12501 // Helper function used by Runtime_DebugConstructedBy below. | 12501 // Helper function used by Runtime_DebugConstructedBy below. |
12502 static int DebugConstructedBy(HeapIterator* iterator, | 12502 static int DebugConstructedBy(HeapIterator* iterator, |
12503 JSFunction* constructor, | 12503 JSFunction* constructor, |
12504 int max_references, | 12504 int max_references, |
12505 FixedArray* instances, | 12505 FixedArray* instances, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12566 HeapIterator heap_iterator2; | 12566 HeapIterator heap_iterator2; |
12567 count = DebugConstructedBy(&heap_iterator2, | 12567 count = DebugConstructedBy(&heap_iterator2, |
12568 constructor, | 12568 constructor, |
12569 max_references, | 12569 max_references, |
12570 instances, | 12570 instances, |
12571 count); | 12571 count); |
12572 | 12572 |
12573 // Return result as JS array. | 12573 // Return result as JS array. |
12574 Object* result; | 12574 Object* result; |
12575 { MaybeObject* maybe_result = isolate->heap()->AllocateJSObject( | 12575 { MaybeObject* maybe_result = isolate->heap()->AllocateJSObject( |
12576 isolate->context()->native_context()->array_function()); | 12576 isolate->context()->global_context()->array_function()); |
12577 if (!maybe_result->ToObject(&result)) return maybe_result; | 12577 if (!maybe_result->ToObject(&result)) return maybe_result; |
12578 } | 12578 } |
12579 return JSArray::cast(result)->SetContent(instances); | 12579 return JSArray::cast(result)->SetContent(instances); |
12580 } | 12580 } |
12581 | 12581 |
12582 | 12582 |
12583 // Find the effective prototype object as returned by __proto__. | 12583 // Find the effective prototype object as returned by __proto__. |
12584 // args[0]: the object to find the prototype for. | 12584 // args[0]: the object to find the prototype for. |
12585 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugGetPrototype) { | 12585 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugGetPrototype) { |
12586 ASSERT(args.length() == 1); | 12586 ASSERT(args.length() == 1); |
12587 | 12587 |
12588 CONVERT_ARG_CHECKED(JSObject, obj, 0); | 12588 CONVERT_ARG_CHECKED(JSObject, obj, 0); |
12589 | 12589 |
12590 // Use the __proto__ accessor. | 12590 // Use the __proto__ accessor. |
12591 return Accessors::ObjectPrototype.getter(obj, NULL); | 12591 return Accessors::ObjectPrototype.getter(obj, NULL); |
12592 } | 12592 } |
12593 | 12593 |
12594 | 12594 |
12595 // Patches script source (should be called upon BeforeCompile event). | 12595 // Patches script source (should be called upon BeforeCompile event). |
12596 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugSetScriptSource) { | 12596 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugSetScriptSource) { |
12597 HandleScope scope(isolate); | 12597 HandleScope scope(isolate); |
12598 ASSERT(args.length() == 2); | 12598 ASSERT(args.length() == 2); |
12599 | 12599 |
12600 CONVERT_ARG_HANDLE_CHECKED(JSValue, script_wrapper, 0); | 12600 CONVERT_ARG_HANDLE_CHECKED(JSValue, script_wrapper, 0); |
12601 CONVERT_ARG_HANDLE_CHECKED(String, source, 1); | 12601 Handle<String> source(String::cast(args[1])); |
12602 | 12602 |
12603 RUNTIME_ASSERT(script_wrapper->value()->IsScript()); | 12603 RUNTIME_ASSERT(script_wrapper->value()->IsScript()); |
12604 Handle<Script> script(Script::cast(script_wrapper->value())); | 12604 Handle<Script> script(Script::cast(script_wrapper->value())); |
12605 | 12605 |
12606 int compilation_state = Smi::cast(script->compilation_state())->value(); | 12606 int compilation_state = Smi::cast(script->compilation_state())->value(); |
12607 RUNTIME_ASSERT(compilation_state == Script::COMPILATION_STATE_INITIAL); | 12607 RUNTIME_ASSERT(compilation_state == Script::COMPILATION_STATE_INITIAL); |
12608 script->set_source(*source); | 12608 script->set_source(*source); |
12609 | 12609 |
12610 return isolate->heap()->undefined_value(); | 12610 return isolate->heap()->undefined_value(); |
12611 } | 12611 } |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12957 RUNTIME_FUNCTION(MaybeObject*, Runtime_ExecuteInDebugContext) { | 12957 RUNTIME_FUNCTION(MaybeObject*, Runtime_ExecuteInDebugContext) { |
12958 ASSERT(args.length() == 2); | 12958 ASSERT(args.length() == 2); |
12959 HandleScope scope(isolate); | 12959 HandleScope scope(isolate); |
12960 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); | 12960 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); |
12961 CONVERT_BOOLEAN_ARG_CHECKED(without_debugger, 1); | 12961 CONVERT_BOOLEAN_ARG_CHECKED(without_debugger, 1); |
12962 | 12962 |
12963 Handle<Object> result; | 12963 Handle<Object> result; |
12964 bool pending_exception; | 12964 bool pending_exception; |
12965 { | 12965 { |
12966 if (without_debugger) { | 12966 if (without_debugger) { |
12967 result = Execution::Call(function, isolate->global_object(), 0, NULL, | 12967 result = Execution::Call(function, isolate->global(), 0, NULL, |
12968 &pending_exception); | 12968 &pending_exception); |
12969 } else { | 12969 } else { |
12970 EnterDebugger enter_debugger; | 12970 EnterDebugger enter_debugger; |
12971 result = Execution::Call(function, isolate->global_object(), 0, NULL, | 12971 result = Execution::Call(function, isolate->global(), 0, NULL, |
12972 &pending_exception); | 12972 &pending_exception); |
12973 } | 12973 } |
12974 } | 12974 } |
12975 if (!pending_exception) { | 12975 if (!pending_exception) { |
12976 return *result; | 12976 return *result; |
12977 } else { | 12977 } else { |
12978 return Failure::Exception(); | 12978 return Failure::Exception(); |
12979 } | 12979 } |
12980 } | 12980 } |
12981 | 12981 |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13440 // There is no value in the cache. Invoke the function and cache result. | 13440 // There is no value in the cache. Invoke the function and cache result. |
13441 HandleScope scope(isolate); | 13441 HandleScope scope(isolate); |
13442 | 13442 |
13443 Handle<JSFunctionResultCache> cache_handle(cache); | 13443 Handle<JSFunctionResultCache> cache_handle(cache); |
13444 Handle<Object> key_handle(key); | 13444 Handle<Object> key_handle(key); |
13445 Handle<Object> value; | 13445 Handle<Object> value; |
13446 { | 13446 { |
13447 Handle<JSFunction> factory(JSFunction::cast( | 13447 Handle<JSFunction> factory(JSFunction::cast( |
13448 cache_handle->get(JSFunctionResultCache::kFactoryIndex))); | 13448 cache_handle->get(JSFunctionResultCache::kFactoryIndex))); |
13449 // TODO(antonm): consider passing a receiver when constructing a cache. | 13449 // TODO(antonm): consider passing a receiver when constructing a cache. |
13450 Handle<Object> receiver(isolate->native_context()->global_object()); | 13450 Handle<Object> receiver(isolate->global_context()->global()); |
13451 // This handle is nor shared, nor used later, so it's safe. | 13451 // This handle is nor shared, nor used later, so it's safe. |
13452 Handle<Object> argv[] = { key_handle }; | 13452 Handle<Object> argv[] = { key_handle }; |
13453 bool pending_exception; | 13453 bool pending_exception; |
13454 value = Execution::Call(factory, | 13454 value = Execution::Call(factory, |
13455 receiver, | 13455 receiver, |
13456 ARRAY_SIZE(argv), | 13456 ARRAY_SIZE(argv), |
13457 argv, | 13457 argv, |
13458 &pending_exception); | 13458 &pending_exception); |
13459 if (pending_exception) return Failure::Exception(); | 13459 if (pending_exception) return Failure::Exception(); |
13460 } | 13460 } |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13718 // Handle last resort GC and make sure to allow future allocations | 13718 // Handle last resort GC and make sure to allow future allocations |
13719 // to grow the heap without causing GCs (if possible). | 13719 // to grow the heap without causing GCs (if possible). |
13720 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13720 isolate->counters()->gc_last_resort_from_js()->Increment(); |
13721 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13721 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
13722 "Runtime::PerformGC"); | 13722 "Runtime::PerformGC"); |
13723 } | 13723 } |
13724 } | 13724 } |
13725 | 13725 |
13726 | 13726 |
13727 } } // namespace v8::internal | 13727 } } // namespace v8::internal |
OLD | NEW |