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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2567 FixedArrayBuilder array_builder_; | 2567 FixedArrayBuilder array_builder_; |
2568 Handle<String> subject_; | 2568 Handle<String> subject_; |
2569 int character_count_; | 2569 int character_count_; |
2570 bool is_ascii_; | 2570 bool is_ascii_; |
2571 }; | 2571 }; |
2572 | 2572 |
2573 | 2573 |
2574 class CompiledReplacement { | 2574 class CompiledReplacement { |
2575 public: | 2575 public: |
2576 explicit CompiledReplacement(Zone* zone) | 2576 explicit CompiledReplacement(Zone* zone) |
2577 : parts_(1, zone), replacement_substrings_(0, zone), | 2577 : parts_(1, zone), replacement_substrings_(0, zone), zone_(zone) {} |
2578 simple_hint_(false), | |
2579 zone_(zone) {} | |
2580 | 2578 |
2581 void Compile(Handle<String> replacement, | 2579 // Return whether the replacement is simple. |
| 2580 bool Compile(Handle<String> replacement, |
2582 int capture_count, | 2581 int capture_count, |
2583 int subject_length); | 2582 int subject_length); |
2584 | 2583 |
| 2584 // Use Apply only if Compile returned false. |
2585 void Apply(ReplacementStringBuilder* builder, | 2585 void Apply(ReplacementStringBuilder* builder, |
2586 int match_from, | 2586 int match_from, |
2587 int match_to, | 2587 int match_to, |
2588 Handle<JSArray> last_match_info); | 2588 int32_t* match); |
2589 | 2589 |
2590 // Number of distinct parts of the replacement pattern. | 2590 // Number of distinct parts of the replacement pattern. |
2591 int parts() { | 2591 int parts() { |
2592 return parts_.length(); | 2592 return parts_.length(); |
2593 } | 2593 } |
2594 | 2594 |
2595 bool simple_hint() { | |
2596 return simple_hint_; | |
2597 } | |
2598 | |
2599 Zone* zone() const { return zone_; } | 2595 Zone* zone() const { return zone_; } |
2600 | 2596 |
2601 private: | 2597 private: |
2602 enum PartType { | 2598 enum PartType { |
2603 SUBJECT_PREFIX = 1, | 2599 SUBJECT_PREFIX = 1, |
2604 SUBJECT_SUFFIX, | 2600 SUBJECT_SUFFIX, |
2605 SUBJECT_CAPTURE, | 2601 SUBJECT_CAPTURE, |
2606 REPLACEMENT_SUBSTRING, | 2602 REPLACEMENT_SUBSTRING, |
2607 REPLACEMENT_STRING, | 2603 REPLACEMENT_STRING, |
2608 | 2604 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2649 // tag == REPLACEMENT_STRING: data is index into array of substrings | 2645 // tag == REPLACEMENT_STRING: data is index into array of substrings |
2650 // of the replacement string. | 2646 // of the replacement string. |
2651 // tag <= 0: Temporary representation of the substring of the replacement | 2647 // tag <= 0: Temporary representation of the substring of the replacement |
2652 // string ranging over -tag .. data. | 2648 // string ranging over -tag .. data. |
2653 // Is replaced by REPLACEMENT_{SUB,}STRING when we create the | 2649 // Is replaced by REPLACEMENT_{SUB,}STRING when we create the |
2654 // substring objects. | 2650 // substring objects. |
2655 int data; | 2651 int data; |
2656 }; | 2652 }; |
2657 | 2653 |
2658 template<typename Char> | 2654 template<typename Char> |
2659 static bool ParseReplacementPattern(ZoneList<ReplacementPart>* parts, | 2655 bool ParseReplacementPattern(ZoneList<ReplacementPart>* parts, |
2660 Vector<Char> characters, | 2656 Vector<Char> characters, |
2661 int capture_count, | 2657 int capture_count, |
2662 int subject_length, | 2658 int subject_length, |
2663 Zone* zone) { | 2659 Zone* zone) { |
2664 int length = characters.length(); | 2660 int length = characters.length(); |
2665 int last = 0; | 2661 int last = 0; |
2666 for (int i = 0; i < length; i++) { | 2662 for (int i = 0; i < length; i++) { |
2667 Char c = characters[i]; | 2663 Char c = characters[i]; |
2668 if (c == '$') { | 2664 if (c == '$') { |
2669 int next_index = i + 1; | 2665 int next_index = i + 1; |
2670 if (next_index == length) { // No next character! | 2666 if (next_index == length) { // No next character! |
2671 break; | 2667 break; |
2672 } | 2668 } |
2673 Char c2 = characters[next_index]; | 2669 Char c2 = characters[next_index]; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2747 break; | 2743 break; |
2748 } | 2744 } |
2749 default: | 2745 default: |
2750 i = next_index; | 2746 i = next_index; |
2751 break; | 2747 break; |
2752 } | 2748 } |
2753 } | 2749 } |
2754 } | 2750 } |
2755 if (length > last) { | 2751 if (length > last) { |
2756 if (last == 0) { | 2752 if (last == 0) { |
2757 parts->Add(ReplacementPart::ReplacementString(), zone); | 2753 // Replacement is simple. Do not use Apply to do the replacement. |
2758 return true; | 2754 return true; |
2759 } else { | 2755 } else { |
2760 parts->Add(ReplacementPart::ReplacementSubString(last, length), zone); | 2756 parts->Add(ReplacementPart::ReplacementSubString(last, length), zone); |
2761 } | 2757 } |
2762 } | 2758 } |
2763 return false; | 2759 return false; |
2764 } | 2760 } |
2765 | 2761 |
2766 ZoneList<ReplacementPart> parts_; | 2762 ZoneList<ReplacementPart> parts_; |
2767 ZoneList<Handle<String> > replacement_substrings_; | 2763 ZoneList<Handle<String> > replacement_substrings_; |
2768 bool simple_hint_; | |
2769 Zone* zone_; | 2764 Zone* zone_; |
2770 }; | 2765 }; |
2771 | 2766 |
2772 | 2767 |
2773 void CompiledReplacement::Compile(Handle<String> replacement, | 2768 bool CompiledReplacement::Compile(Handle<String> replacement, |
2774 int capture_count, | 2769 int capture_count, |
2775 int subject_length) { | 2770 int subject_length) { |
2776 { | 2771 { |
2777 AssertNoAllocation no_alloc; | 2772 AssertNoAllocation no_alloc; |
2778 String::FlatContent content = replacement->GetFlatContent(); | 2773 String::FlatContent content = replacement->GetFlatContent(); |
2779 ASSERT(content.IsFlat()); | 2774 ASSERT(content.IsFlat()); |
| 2775 bool simple = false; |
2780 if (content.IsAscii()) { | 2776 if (content.IsAscii()) { |
2781 simple_hint_ = ParseReplacementPattern(&parts_, | 2777 simple = ParseReplacementPattern(&parts_, |
2782 content.ToAsciiVector(), | 2778 content.ToAsciiVector(), |
2783 capture_count, | 2779 capture_count, |
2784 subject_length, | 2780 subject_length, |
2785 zone()); | 2781 zone()); |
2786 } else { | 2782 } else { |
2787 ASSERT(content.IsTwoByte()); | 2783 ASSERT(content.IsTwoByte()); |
2788 simple_hint_ = ParseReplacementPattern(&parts_, | 2784 simple = ParseReplacementPattern(&parts_, |
2789 content.ToUC16Vector(), | 2785 content.ToUC16Vector(), |
2790 capture_count, | 2786 capture_count, |
2791 subject_length, | 2787 subject_length, |
2792 zone()); | 2788 zone()); |
2793 } | 2789 } |
| 2790 if (simple) return true; |
2794 } | 2791 } |
| 2792 |
2795 Isolate* isolate = replacement->GetIsolate(); | 2793 Isolate* isolate = replacement->GetIsolate(); |
2796 // Find substrings of replacement string and create them as String objects. | 2794 // Find substrings of replacement string and create them as String objects. |
2797 int substring_index = 0; | 2795 int substring_index = 0; |
2798 for (int i = 0, n = parts_.length(); i < n; i++) { | 2796 for (int i = 0, n = parts_.length(); i < n; i++) { |
2799 int tag = parts_[i].tag; | 2797 int tag = parts_[i].tag; |
2800 if (tag <= 0) { // A replacement string slice. | 2798 if (tag <= 0) { // A replacement string slice. |
2801 int from = -tag; | 2799 int from = -tag; |
2802 int to = parts_[i].data; | 2800 int to = parts_[i].data; |
2803 replacement_substrings_.Add( | 2801 replacement_substrings_.Add( |
2804 isolate->factory()->NewSubString(replacement, from, to), zone()); | 2802 isolate->factory()->NewSubString(replacement, from, to), zone()); |
2805 parts_[i].tag = REPLACEMENT_SUBSTRING; | 2803 parts_[i].tag = REPLACEMENT_SUBSTRING; |
2806 parts_[i].data = substring_index; | 2804 parts_[i].data = substring_index; |
2807 substring_index++; | 2805 substring_index++; |
2808 } else if (tag == REPLACEMENT_STRING) { | 2806 } else if (tag == REPLACEMENT_STRING) { |
2809 replacement_substrings_.Add(replacement, zone()); | 2807 replacement_substrings_.Add(replacement, zone()); |
2810 parts_[i].data = substring_index; | 2808 parts_[i].data = substring_index; |
2811 substring_index++; | 2809 substring_index++; |
2812 } | 2810 } |
2813 } | 2811 } |
| 2812 return false; |
2814 } | 2813 } |
2815 | 2814 |
2816 | 2815 |
2817 void CompiledReplacement::Apply(ReplacementStringBuilder* builder, | 2816 void CompiledReplacement::Apply(ReplacementStringBuilder* builder, |
2818 int match_from, | 2817 int match_from, |
2819 int match_to, | 2818 int match_to, |
2820 Handle<JSArray> last_match_info) { | 2819 int32_t* match) { |
| 2820 ASSERT_LT(0, parts_.length()); |
2821 for (int i = 0, n = parts_.length(); i < n; i++) { | 2821 for (int i = 0, n = parts_.length(); i < n; i++) { |
2822 ReplacementPart part = parts_[i]; | 2822 ReplacementPart part = parts_[i]; |
2823 switch (part.tag) { | 2823 switch (part.tag) { |
2824 case SUBJECT_PREFIX: | 2824 case SUBJECT_PREFIX: |
2825 if (match_from > 0) builder->AddSubjectSlice(0, match_from); | 2825 if (match_from > 0) builder->AddSubjectSlice(0, match_from); |
2826 break; | 2826 break; |
2827 case SUBJECT_SUFFIX: { | 2827 case SUBJECT_SUFFIX: { |
2828 int subject_length = part.data; | 2828 int subject_length = part.data; |
2829 if (match_to < subject_length) { | 2829 if (match_to < subject_length) { |
2830 builder->AddSubjectSlice(match_to, subject_length); | 2830 builder->AddSubjectSlice(match_to, subject_length); |
2831 } | 2831 } |
2832 break; | 2832 break; |
2833 } | 2833 } |
2834 case SUBJECT_CAPTURE: { | 2834 case SUBJECT_CAPTURE: { |
2835 int capture = part.data; | 2835 int capture = part.data; |
2836 FixedArray* match_info = FixedArray::cast(last_match_info->elements()); | 2836 int from = match[capture * 2]; |
2837 int from = RegExpImpl::GetCapture(match_info, capture * 2); | 2837 int to = match[capture * 2 + 1]; |
2838 int to = RegExpImpl::GetCapture(match_info, capture * 2 + 1); | |
2839 if (from >= 0 && to > from) { | 2838 if (from >= 0 && to > from) { |
2840 builder->AddSubjectSlice(from, to); | 2839 builder->AddSubjectSlice(from, to); |
2841 } | 2840 } |
2842 break; | 2841 break; |
2843 } | 2842 } |
2844 case REPLACEMENT_SUBSTRING: | 2843 case REPLACEMENT_SUBSTRING: |
2845 case REPLACEMENT_STRING: | 2844 case REPLACEMENT_STRING: |
2846 builder->AddString(replacement_substrings_[part.data]); | 2845 builder->AddString(replacement_substrings_[part.data]); |
2847 break; | 2846 break; |
2848 default: | 2847 default: |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2950 pattern_content.ToUC16Vector(), | 2949 pattern_content.ToUC16Vector(), |
2951 indices, | 2950 indices, |
2952 limit, | 2951 limit, |
2953 zone); | 2952 zone); |
2954 } | 2953 } |
2955 } | 2954 } |
2956 } | 2955 } |
2957 } | 2956 } |
2958 | 2957 |
2959 | 2958 |
2960 // Two smis before and after the match, for very long strings. | |
2961 const int kMaxBuilderEntriesPerRegExpMatch = 5; | |
2962 | |
2963 | |
2964 static void SetLastMatchInfoNoCaptures(Handle<String> subject, | |
2965 Handle<JSArray> last_match_info, | |
2966 int match_start, | |
2967 int match_end) { | |
2968 // Fill last_match_info with a single capture. | |
2969 last_match_info->EnsureSize(2 + RegExpImpl::kLastMatchOverhead); | |
2970 AssertNoAllocation no_gc; | |
2971 FixedArray* elements = FixedArray::cast(last_match_info->elements()); | |
2972 RegExpImpl::SetLastCaptureCount(elements, 2); | |
2973 RegExpImpl::SetLastInput(elements, *subject); | |
2974 RegExpImpl::SetLastSubject(elements, *subject); | |
2975 RegExpImpl::SetCapture(elements, 0, match_start); | |
2976 RegExpImpl::SetCapture(elements, 1, match_end); | |
2977 } | |
2978 | |
2979 | |
2980 template <typename SubjectChar, typename PatternChar> | |
2981 static bool SearchStringMultiple(Isolate* isolate, | |
2982 Vector<const SubjectChar> subject, | |
2983 Vector<const PatternChar> pattern, | |
2984 String* pattern_string, | |
2985 FixedArrayBuilder* builder, | |
2986 int* match_pos) { | |
2987 int pos = *match_pos; | |
2988 int subject_length = subject.length(); | |
2989 int pattern_length = pattern.length(); | |
2990 int max_search_start = subject_length - pattern_length; | |
2991 StringSearch<PatternChar, SubjectChar> search(isolate, pattern); | |
2992 while (pos <= max_search_start) { | |
2993 if (!builder->HasCapacity(kMaxBuilderEntriesPerRegExpMatch)) { | |
2994 *match_pos = pos; | |
2995 return false; | |
2996 } | |
2997 // Position of end of previous match. | |
2998 int match_end = pos + pattern_length; | |
2999 int new_pos = search.Search(subject, match_end); | |
3000 if (new_pos >= 0) { | |
3001 // A match. | |
3002 if (new_pos > match_end) { | |
3003 ReplacementStringBuilder::AddSubjectSlice(builder, | |
3004 match_end, | |
3005 new_pos); | |
3006 } | |
3007 pos = new_pos; | |
3008 builder->Add(pattern_string); | |
3009 } else { | |
3010 break; | |
3011 } | |
3012 } | |
3013 | |
3014 if (pos < max_search_start) { | |
3015 ReplacementStringBuilder::AddSubjectSlice(builder, | |
3016 pos + pattern_length, | |
3017 subject_length); | |
3018 } | |
3019 *match_pos = pos; | |
3020 return true; | |
3021 } | |
3022 | |
3023 | |
3024 | |
3025 | |
3026 template<typename ResultSeqString> | 2959 template<typename ResultSeqString> |
3027 MUST_USE_RESULT static MaybeObject* StringReplaceAtomRegExpWithString( | 2960 MUST_USE_RESULT static MaybeObject* StringReplaceAtomRegExpWithString( |
3028 Isolate* isolate, | 2961 Isolate* isolate, |
3029 Handle<String> subject, | 2962 Handle<String> subject, |
3030 Handle<JSRegExp> pattern_regexp, | 2963 Handle<JSRegExp> pattern_regexp, |
3031 Handle<String> replacement, | 2964 Handle<String> replacement, |
3032 Handle<JSArray> last_match_info, | 2965 Handle<JSArray> last_match_info) { |
3033 Zone* zone) { | |
3034 ASSERT(subject->IsFlat()); | 2966 ASSERT(subject->IsFlat()); |
3035 ASSERT(replacement->IsFlat()); | 2967 ASSERT(replacement->IsFlat()); |
3036 | 2968 |
3037 ZoneScope zone_space(isolate->runtime_zone(), DELETE_ON_EXIT); | 2969 Zone* zone = isolate->runtime_zone(); |
3038 ZoneList<int> indices(8, isolate->runtime_zone()); | 2970 ZoneScope zone_space(zone, DELETE_ON_EXIT); |
| 2971 ZoneList<int> indices(8, zone); |
3039 ASSERT_EQ(JSRegExp::ATOM, pattern_regexp->TypeTag()); | 2972 ASSERT_EQ(JSRegExp::ATOM, pattern_regexp->TypeTag()); |
3040 String* pattern = | 2973 String* pattern = |
3041 String::cast(pattern_regexp->DataAt(JSRegExp::kAtomPatternIndex)); | 2974 String::cast(pattern_regexp->DataAt(JSRegExp::kAtomPatternIndex)); |
3042 int subject_len = subject->length(); | 2975 int subject_len = subject->length(); |
3043 int pattern_len = pattern->length(); | 2976 int pattern_len = pattern->length(); |
3044 int replacement_len = replacement->length(); | 2977 int replacement_len = replacement->length(); |
3045 | 2978 |
3046 FindStringIndicesDispatch(isolate, *subject, pattern, &indices, 0xffffffff, | 2979 FindStringIndicesDispatch( |
3047 zone); | 2980 isolate, *subject, pattern, &indices, 0xffffffff, zone); |
3048 | 2981 |
3049 int matches = indices.length(); | 2982 int matches = indices.length(); |
3050 if (matches == 0) return *subject; | 2983 if (matches == 0) return *subject; |
3051 | 2984 |
3052 // Detect integer overflow. | 2985 // Detect integer overflow. |
3053 int64_t result_len_64 = | 2986 int64_t result_len_64 = |
3054 (static_cast<int64_t>(replacement_len) - | 2987 (static_cast<int64_t>(replacement_len) - |
3055 static_cast<int64_t>(pattern_len)) * | 2988 static_cast<int64_t>(pattern_len)) * |
3056 static_cast<int64_t>(matches) + | 2989 static_cast<int64_t>(matches) + |
3057 static_cast<int64_t>(subject_len); | 2990 static_cast<int64_t>(subject_len); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3092 subject_pos = indices.at(i) + pattern_len; | 3025 subject_pos = indices.at(i) + pattern_len; |
3093 } | 3026 } |
3094 // Add remaining subject content at the end. | 3027 // Add remaining subject content at the end. |
3095 if (subject_pos < subject_len) { | 3028 if (subject_pos < subject_len) { |
3096 String::WriteToFlat(*subject, | 3029 String::WriteToFlat(*subject, |
3097 result->GetChars() + result_pos, | 3030 result->GetChars() + result_pos, |
3098 subject_pos, | 3031 subject_pos, |
3099 subject_len); | 3032 subject_len); |
3100 } | 3033 } |
3101 | 3034 |
3102 SetLastMatchInfoNoCaptures(subject, | 3035 int32_t match_indices[] = { indices.at(matches - 1), |
3103 last_match_info, | 3036 indices.at(matches - 1) + pattern_len }; |
3104 indices.at(matches - 1), | 3037 RegExpImpl::SetLastMatchInfo(last_match_info, subject, 0, match_indices); |
3105 indices.at(matches - 1) + pattern_len); | |
3106 | 3038 |
3107 return *result; | 3039 return *result; |
3108 } | 3040 } |
3109 | 3041 |
3110 | 3042 |
3111 MUST_USE_RESULT static MaybeObject* StringReplaceRegExpWithString( | 3043 MUST_USE_RESULT static MaybeObject* StringReplaceRegExpWithString( |
3112 Isolate* isolate, | 3044 Isolate* isolate, |
3113 String* subject, | 3045 Handle<String> subject, |
3114 JSRegExp* regexp, | 3046 Handle<JSRegExp> regexp, |
3115 String* replacement, | 3047 Handle<String> replacement, |
3116 JSArray* last_match_info, | 3048 Handle<JSArray> last_match_info) { |
3117 Zone* zone) { | |
3118 ASSERT(subject->IsFlat()); | 3049 ASSERT(subject->IsFlat()); |
3119 ASSERT(replacement->IsFlat()); | 3050 ASSERT(replacement->IsFlat()); |
3120 | 3051 |
3121 HandleScope handles(isolate); | 3052 bool is_global = regexp->GetFlags().is_global(); |
3122 | 3053 int capture_count = regexp->CaptureCount(); |
3123 int length = subject->length(); | 3054 int subject_length = subject->length(); |
3124 Handle<String> subject_handle(subject); | |
3125 Handle<JSRegExp> regexp_handle(regexp); | |
3126 Handle<String> replacement_handle(replacement); | |
3127 Handle<JSArray> last_match_info_handle(last_match_info); | |
3128 Handle<Object> match = RegExpImpl::Exec(regexp_handle, | |
3129 subject_handle, | |
3130 0, | |
3131 last_match_info_handle); | |
3132 if (match.is_null()) { | |
3133 return Failure::Exception(); | |
3134 } | |
3135 if (match->IsNull()) { | |
3136 return *subject_handle; | |
3137 } | |
3138 | |
3139 int capture_count = regexp_handle->CaptureCount(); | |
3140 | 3055 |
3141 // CompiledReplacement uses zone allocation. | 3056 // CompiledReplacement uses zone allocation. |
| 3057 Zone* zone = isolate->runtime_zone(); |
3142 ZoneScope zonescope(zone, DELETE_ON_EXIT); | 3058 ZoneScope zonescope(zone, DELETE_ON_EXIT); |
3143 CompiledReplacement compiled_replacement(zone); | 3059 CompiledReplacement compiled_replacement(zone); |
3144 | 3060 bool simple_replace = compiled_replacement.Compile(replacement, |
3145 compiled_replacement.Compile(replacement_handle, | 3061 capture_count, |
3146 capture_count, | 3062 subject_length); |
3147 length); | |
3148 | |
3149 bool is_global = regexp_handle->GetFlags().is_global(); | |
3150 | 3063 |
3151 // Shortcut for simple non-regexp global replacements | 3064 // Shortcut for simple non-regexp global replacements |
3152 if (is_global && | 3065 if (is_global && |
3153 regexp_handle->TypeTag() == JSRegExp::ATOM && | 3066 regexp->TypeTag() == JSRegExp::ATOM && |
3154 compiled_replacement.simple_hint()) { | 3067 simple_replace) { |
3155 if (subject_handle->HasOnlyAsciiChars() && | 3068 if (subject->HasOnlyAsciiChars()) { |
3156 replacement_handle->HasOnlyAsciiChars()) { | |
3157 return StringReplaceAtomRegExpWithString<SeqAsciiString>( | 3069 return StringReplaceAtomRegExpWithString<SeqAsciiString>( |
3158 isolate, | 3070 isolate, subject, regexp, replacement, last_match_info); |
3159 subject_handle, | 3071 } else { |
3160 regexp_handle, | |
3161 replacement_handle, | |
3162 last_match_info_handle, | |
3163 zone); | |
3164 } else { | |
3165 return StringReplaceAtomRegExpWithString<SeqTwoByteString>( | 3072 return StringReplaceAtomRegExpWithString<SeqTwoByteString>( |
3166 isolate, | 3073 isolate, subject, regexp, replacement, last_match_info); |
3167 subject_handle, | |
3168 regexp_handle, | |
3169 replacement_handle, | |
3170 last_match_info_handle, | |
3171 zone); | |
3172 } | 3074 } |
3173 } | 3075 } |
3174 | 3076 |
| 3077 RegExpImpl::GlobalCache global_cache(regexp, subject, is_global, isolate); |
| 3078 if (global_cache.HasException()) return Failure::Exception(); |
| 3079 |
| 3080 int32_t* current_match = global_cache.FetchNext(); |
| 3081 if (current_match == NULL) { |
| 3082 if (global_cache.HasException()) return Failure::Exception(); |
| 3083 return *subject; |
| 3084 } |
| 3085 |
3175 // Guessing the number of parts that the final result string is built | 3086 // Guessing the number of parts that the final result string is built |
3176 // from. Global regexps can match any number of times, so we guess | 3087 // from. Global regexps can match any number of times, so we guess |
3177 // conservatively. | 3088 // conservatively. |
3178 int expected_parts = | 3089 int expected_parts = |
3179 (compiled_replacement.parts() + 1) * (is_global ? 4 : 1) + 1; | 3090 (compiled_replacement.parts() + 1) * (is_global ? 4 : 1) + 1; |
3180 ReplacementStringBuilder builder(isolate->heap(), | 3091 ReplacementStringBuilder builder(isolate->heap(), |
3181 subject_handle, | 3092 subject, |
3182 expected_parts); | 3093 expected_parts); |
3183 | 3094 |
3184 // Index of end of last match. | |
3185 int prev = 0; | |
3186 | |
3187 | |
3188 // Number of parts added by compiled replacement plus preceeding | 3095 // Number of parts added by compiled replacement plus preceeding |
3189 // string and possibly suffix after last match. It is possible for | 3096 // string and possibly suffix after last match. It is possible for |
3190 // all components to use two elements when encoded as two smis. | 3097 // all components to use two elements when encoded as two smis. |
3191 const int parts_added_per_loop = 2 * (compiled_replacement.parts() + 2); | 3098 const int parts_added_per_loop = 2 * (compiled_replacement.parts() + 2); |
3192 bool matched = true; | 3099 |
| 3100 int prev = 0; |
| 3101 |
3193 do { | 3102 do { |
3194 ASSERT(last_match_info_handle->HasFastObjectElements()); | |
3195 // Increase the capacity of the builder before entering local handle-scope, | |
3196 // so its internal buffer can safely allocate a new handle if it grows. | |
3197 builder.EnsureCapacity(parts_added_per_loop); | 3103 builder.EnsureCapacity(parts_added_per_loop); |
3198 | 3104 |
3199 HandleScope loop_scope(isolate); | 3105 int start = current_match[0]; |
3200 int start, end; | 3106 int end = current_match[1]; |
3201 { | |
3202 AssertNoAllocation match_info_array_is_not_in_a_handle; | |
3203 FixedArray* match_info_array = | |
3204 FixedArray::cast(last_match_info_handle->elements()); | |
3205 | |
3206 ASSERT_EQ(capture_count * 2 + 2, | |
3207 RegExpImpl::GetLastCaptureCount(match_info_array)); | |
3208 start = RegExpImpl::GetCapture(match_info_array, 0); | |
3209 end = RegExpImpl::GetCapture(match_info_array, 1); | |
3210 } | |
3211 | 3107 |
3212 if (prev < start) { | 3108 if (prev < start) { |
3213 builder.AddSubjectSlice(prev, start); | 3109 builder.AddSubjectSlice(prev, start); |
3214 } | 3110 } |
3215 compiled_replacement.Apply(&builder, | |
3216 start, | |
3217 end, | |
3218 last_match_info_handle); | |
3219 | 3111 |
| 3112 if (simple_replace) { |
| 3113 builder.AddString(replacement); |
| 3114 } else { |
| 3115 compiled_replacement.Apply(&builder, |
| 3116 start, |
| 3117 end, |
| 3118 current_match); |
| 3119 } |
3220 prev = end; | 3120 prev = end; |
3221 | 3121 |
3222 // Only continue checking for global regexps. | 3122 // Only continue checking for global regexps. |
3223 if (!is_global) break; | 3123 if (!is_global) break; |
3224 | 3124 |
3225 // Continue from where the match ended, unless it was an empty match. | 3125 current_match = global_cache.FetchNext(); |
3226 int next = end; | 3126 } while (current_match != NULL); |
3227 if (start == end) { | |
3228 next = end + 1; | |
3229 if (next > length) break; | |
3230 } | |
3231 | 3127 |
3232 match = RegExpImpl::Exec(regexp_handle, | 3128 if (global_cache.HasException()) return Failure::Exception(); |
3233 subject_handle, | |
3234 next, | |
3235 last_match_info_handle); | |
3236 if (match.is_null()) { | |
3237 return Failure::Exception(); | |
3238 } | |
3239 matched = !match->IsNull(); | |
3240 } while (matched); | |
3241 | 3129 |
3242 if (prev < length) { | 3130 if (prev < subject_length) { |
3243 builder.AddSubjectSlice(prev, length); | 3131 builder.EnsureCapacity(2); |
| 3132 builder.AddSubjectSlice(prev, subject_length); |
3244 } | 3133 } |
3245 | 3134 |
| 3135 RegExpImpl::SetLastMatchInfo(last_match_info, |
| 3136 subject, |
| 3137 capture_count, |
| 3138 global_cache.LastSuccessfulMatch()); |
| 3139 |
3246 return *(builder.ToString()); | 3140 return *(builder.ToString()); |
3247 } | 3141 } |
3248 | 3142 |
3249 | 3143 |
3250 template <typename ResultSeqString> | 3144 template <typename ResultSeqString> |
3251 MUST_USE_RESULT static MaybeObject* StringReplaceRegExpWithEmptyString( | 3145 MUST_USE_RESULT static MaybeObject* StringReplaceRegExpWithEmptyString( |
3252 Isolate* isolate, | 3146 Isolate* isolate, |
3253 String* subject, | 3147 Handle<String> subject, |
3254 JSRegExp* regexp, | 3148 Handle<JSRegExp> regexp, |
3255 JSArray* last_match_info, | 3149 Handle<JSArray> last_match_info) { |
3256 Zone* zone) { | |
3257 ASSERT(subject->IsFlat()); | 3150 ASSERT(subject->IsFlat()); |
3258 | 3151 |
3259 HandleScope handles(isolate); | 3152 bool is_global = regexp->GetFlags().is_global(); |
3260 | |
3261 Handle<String> subject_handle(subject); | |
3262 Handle<JSRegExp> regexp_handle(regexp); | |
3263 Handle<JSArray> last_match_info_handle(last_match_info); | |
3264 | 3153 |
3265 // Shortcut for simple non-regexp global replacements | 3154 // Shortcut for simple non-regexp global replacements |
3266 if (regexp_handle->GetFlags().is_global() && | 3155 if (is_global && |
3267 regexp_handle->TypeTag() == JSRegExp::ATOM) { | 3156 regexp->TypeTag() == JSRegExp::ATOM) { |
3268 Handle<String> empty_string_handle(HEAP->empty_string()); | 3157 Handle<String> empty_string(HEAP->empty_string()); |
3269 if (subject_handle->HasOnlyAsciiChars()) { | 3158 if (subject->HasOnlyAsciiChars()) { |
3270 return StringReplaceAtomRegExpWithString<SeqAsciiString>( | 3159 return StringReplaceAtomRegExpWithString<SeqAsciiString>( |
3271 isolate, | 3160 isolate, |
3272 subject_handle, | 3161 subject, |
3273 regexp_handle, | 3162 regexp, |
3274 empty_string_handle, | 3163 empty_string, |
3275 last_match_info_handle, | 3164 last_match_info); |
3276 zone); | |
3277 } else { | 3165 } else { |
3278 return StringReplaceAtomRegExpWithString<SeqTwoByteString>( | 3166 return StringReplaceAtomRegExpWithString<SeqTwoByteString>( |
3279 isolate, | 3167 isolate, |
3280 subject_handle, | 3168 subject, |
3281 regexp_handle, | 3169 regexp, |
3282 empty_string_handle, | 3170 empty_string, |
3283 last_match_info_handle, | 3171 last_match_info); |
3284 zone); | |
3285 } | 3172 } |
3286 } | 3173 } |
3287 | 3174 |
3288 Handle<Object> match = RegExpImpl::Exec(regexp_handle, | 3175 RegExpImpl::GlobalCache global_cache(regexp, subject, is_global, isolate); |
3289 subject_handle, | 3176 if (global_cache.HasException()) return Failure::Exception(); |
3290 0, | |
3291 last_match_info_handle); | |
3292 if (match.is_null()) return Failure::Exception(); | |
3293 if (match->IsNull()) return *subject_handle; | |
3294 | 3177 |
3295 ASSERT(last_match_info_handle->HasFastObjectElements()); | 3178 int32_t* current_match = global_cache.FetchNext(); |
3296 | 3179 if (current_match == NULL) { |
3297 int start, end; | 3180 if (global_cache.HasException()) return Failure::Exception(); |
3298 { | 3181 return *subject; |
3299 AssertNoAllocation match_info_array_is_not_in_a_handle; | |
3300 FixedArray* match_info_array = | |
3301 FixedArray::cast(last_match_info_handle->elements()); | |
3302 | |
3303 start = RegExpImpl::GetCapture(match_info_array, 0); | |
3304 end = RegExpImpl::GetCapture(match_info_array, 1); | |
3305 } | 3182 } |
3306 | 3183 |
3307 bool global = regexp_handle->GetFlags().is_global(); | 3184 int start = current_match[0]; |
| 3185 int end = current_match[1]; |
| 3186 int capture_count = regexp->CaptureCount(); |
| 3187 int subject_length = subject->length(); |
3308 | 3188 |
3309 if (start == end && !global) return *subject_handle; | 3189 int new_length = subject_length - (end - start); |
| 3190 if (new_length == 0) return isolate->heap()->empty_string(); |
3310 | 3191 |
3311 int length = subject_handle->length(); | |
3312 int new_length = length - (end - start); | |
3313 if (new_length == 0) { | |
3314 return isolate->heap()->empty_string(); | |
3315 } | |
3316 Handle<ResultSeqString> answer; | 3192 Handle<ResultSeqString> answer; |
3317 if (ResultSeqString::kHasAsciiEncoding) { | 3193 if (ResultSeqString::kHasAsciiEncoding) { |
3318 answer = Handle<ResultSeqString>::cast( | 3194 answer = Handle<ResultSeqString>::cast( |
3319 isolate->factory()->NewRawAsciiString(new_length)); | 3195 isolate->factory()->NewRawAsciiString(new_length)); |
3320 } else { | 3196 } else { |
3321 answer = Handle<ResultSeqString>::cast( | 3197 answer = Handle<ResultSeqString>::cast( |
3322 isolate->factory()->NewRawTwoByteString(new_length)); | 3198 isolate->factory()->NewRawTwoByteString(new_length)); |
3323 } | 3199 } |
3324 | 3200 |
3325 // If the regexp isn't global, only match once. | 3201 if (!is_global) { |
3326 if (!global) { | 3202 RegExpImpl::SetLastMatchInfo( |
3327 if (start > 0) { | 3203 last_match_info, subject, capture_count, current_match); |
3328 String::WriteToFlat(*subject_handle, | 3204 if (start == end) { |
3329 answer->GetChars(), | 3205 return *subject; |
3330 0, | 3206 } else { |
3331 start); | 3207 if (start > 0) { |
| 3208 String::WriteToFlat(*subject, answer->GetChars(), 0, start); |
| 3209 } |
| 3210 if (end < subject_length) { |
| 3211 String::WriteToFlat( |
| 3212 *subject, answer->GetChars() + start, end, subject_length); |
| 3213 } |
| 3214 return *answer; |
3332 } | 3215 } |
3333 if (end < length) { | |
3334 String::WriteToFlat(*subject_handle, | |
3335 answer->GetChars() + start, | |
3336 end, | |
3337 length); | |
3338 } | |
3339 return *answer; | |
3340 } | 3216 } |
3341 | 3217 |
3342 int prev = 0; // Index of end of last match. | 3218 int prev = 0; |
3343 int next = 0; // Start of next search (prev unless last match was empty). | |
3344 int position = 0; | 3219 int position = 0; |
3345 | 3220 |
3346 do { | 3221 do { |
| 3222 start = current_match[0]; |
| 3223 end = current_match[1]; |
3347 if (prev < start) { | 3224 if (prev < start) { |
3348 // Add substring subject[prev;start] to answer string. | 3225 // Add substring subject[prev;start] to answer string. |
3349 String::WriteToFlat(*subject_handle, | 3226 String::WriteToFlat( |
3350 answer->GetChars() + position, | 3227 *subject, answer->GetChars() + position, prev, start); |
3351 prev, | |
3352 start); | |
3353 position += start - prev; | 3228 position += start - prev; |
3354 } | 3229 } |
3355 prev = end; | 3230 prev = end; |
3356 next = end; | |
3357 // Continue from where the match ended, unless it was an empty match. | |
3358 if (start == end) { | |
3359 next++; | |
3360 if (next > length) break; | |
3361 } | |
3362 match = RegExpImpl::Exec(regexp_handle, | |
3363 subject_handle, | |
3364 next, | |
3365 last_match_info_handle); | |
3366 if (match.is_null()) return Failure::Exception(); | |
3367 if (match->IsNull()) break; | |
3368 | 3231 |
3369 ASSERT(last_match_info_handle->HasFastObjectElements()); | 3232 current_match = global_cache.FetchNext(); |
3370 HandleScope loop_scope(isolate); | 3233 } while (current_match != NULL); |
3371 { | |
3372 AssertNoAllocation match_info_array_is_not_in_a_handle; | |
3373 FixedArray* match_info_array = | |
3374 FixedArray::cast(last_match_info_handle->elements()); | |
3375 start = RegExpImpl::GetCapture(match_info_array, 0); | |
3376 end = RegExpImpl::GetCapture(match_info_array, 1); | |
3377 } | |
3378 } while (true); | |
3379 | 3234 |
3380 if (prev < length) { | 3235 if (global_cache.HasException()) return Failure::Exception(); |
| 3236 |
| 3237 RegExpImpl::SetLastMatchInfo(last_match_info, |
| 3238 subject, |
| 3239 capture_count, |
| 3240 global_cache.LastSuccessfulMatch()); |
| 3241 |
| 3242 if (prev < subject_length) { |
3381 // Add substring subject[prev;length] to answer string. | 3243 // Add substring subject[prev;length] to answer string. |
3382 String::WriteToFlat(*subject_handle, | 3244 String::WriteToFlat( |
3383 answer->GetChars() + position, | 3245 *subject, answer->GetChars() + position, prev, subject_length); |
3384 prev, | 3246 position += subject_length - prev; |
3385 length); | |
3386 position += length - prev; | |
3387 } | 3247 } |
3388 | 3248 |
3389 if (position == 0) { | 3249 if (position == 0) return isolate->heap()->empty_string(); |
3390 return isolate->heap()->empty_string(); | |
3391 } | |
3392 | 3250 |
3393 // Shorten string and fill | 3251 // Shorten string and fill |
3394 int string_size = ResultSeqString::SizeFor(position); | 3252 int string_size = ResultSeqString::SizeFor(position); |
3395 int allocated_string_size = ResultSeqString::SizeFor(new_length); | 3253 int allocated_string_size = ResultSeqString::SizeFor(new_length); |
3396 int delta = allocated_string_size - string_size; | 3254 int delta = allocated_string_size - string_size; |
3397 | 3255 |
3398 answer->set_length(position); | 3256 answer->set_length(position); |
3399 if (delta == 0) return *answer; | 3257 if (delta == 0) return *answer; |
3400 | 3258 |
3401 Address end_of_string = answer->address() + string_size; | 3259 Address end_of_string = answer->address() + string_size; |
3402 isolate->heap()->CreateFillerObjectAt(end_of_string, delta); | 3260 isolate->heap()->CreateFillerObjectAt(end_of_string, delta); |
3403 if (Marking::IsBlack(Marking::MarkBitFrom(*answer))) { | 3261 if (Marking::IsBlack(Marking::MarkBitFrom(*answer))) { |
3404 MemoryChunk::IncrementLiveBytesFromMutator(answer->address(), -delta); | 3262 MemoryChunk::IncrementLiveBytesFromMutator(answer->address(), -delta); |
3405 } | 3263 } |
3406 | 3264 |
3407 return *answer; | 3265 return *answer; |
3408 } | 3266 } |
3409 | 3267 |
3410 | 3268 |
3411 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringReplaceRegExpWithString) { | 3269 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringReplaceRegExpWithString) { |
3412 ASSERT(args.length() == 4); | 3270 ASSERT(args.length() == 4); |
3413 | 3271 |
3414 CONVERT_ARG_CHECKED(String, subject, 0); | 3272 HandleScope scope(isolate); |
3415 if (!subject->IsFlat()) { | |
3416 Object* flat_subject; | |
3417 { MaybeObject* maybe_flat_subject = subject->TryFlatten(); | |
3418 if (!maybe_flat_subject->ToObject(&flat_subject)) { | |
3419 return maybe_flat_subject; | |
3420 } | |
3421 } | |
3422 subject = String::cast(flat_subject); | |
3423 } | |
3424 | 3273 |
3425 CONVERT_ARG_CHECKED(String, replacement, 2); | 3274 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); |
3426 if (!replacement->IsFlat()) { | 3275 CONVERT_ARG_HANDLE_CHECKED(String, replacement, 2); |
3427 Object* flat_replacement; | 3276 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); |
3428 { MaybeObject* maybe_flat_replacement = replacement->TryFlatten(); | 3277 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 3); |
3429 if (!maybe_flat_replacement->ToObject(&flat_replacement)) { | |
3430 return maybe_flat_replacement; | |
3431 } | |
3432 } | |
3433 replacement = String::cast(flat_replacement); | |
3434 } | |
3435 | 3278 |
3436 CONVERT_ARG_CHECKED(JSRegExp, regexp, 1); | 3279 if (!subject->IsFlat()) subject = FlattenGetString(subject); |
3437 CONVERT_ARG_CHECKED(JSArray, last_match_info, 3); | 3280 |
| 3281 if (!replacement->IsFlat()) replacement = FlattenGetString(replacement); |
3438 | 3282 |
3439 ASSERT(last_match_info->HasFastObjectElements()); | 3283 ASSERT(last_match_info->HasFastObjectElements()); |
3440 | 3284 |
3441 Zone* zone = isolate->runtime_zone(); | |
3442 if (replacement->length() == 0) { | 3285 if (replacement->length() == 0) { |
3443 if (subject->HasOnlyAsciiChars()) { | 3286 if (subject->HasOnlyAsciiChars()) { |
3444 return StringReplaceRegExpWithEmptyString<SeqAsciiString>( | 3287 return StringReplaceRegExpWithEmptyString<SeqAsciiString>( |
3445 isolate, subject, regexp, last_match_info, zone); | 3288 isolate, subject, regexp, last_match_info); |
3446 } else { | 3289 } else { |
3447 return StringReplaceRegExpWithEmptyString<SeqTwoByteString>( | 3290 return StringReplaceRegExpWithEmptyString<SeqTwoByteString>( |
3448 isolate, subject, regexp, last_match_info, zone); | 3291 isolate, subject, regexp, last_match_info); |
3449 } | 3292 } |
3450 } | 3293 } |
3451 | 3294 |
3452 return StringReplaceRegExpWithString(isolate, | 3295 return StringReplaceRegExpWithString( |
3453 subject, | 3296 isolate, subject, regexp, replacement, last_match_info); |
3454 regexp, | |
3455 replacement, | |
3456 last_match_info, | |
3457 zone); | |
3458 } | 3297 } |
3459 | 3298 |
3460 | 3299 |
3461 Handle<String> Runtime::StringReplaceOneCharWithString(Isolate* isolate, | 3300 Handle<String> Runtime::StringReplaceOneCharWithString(Isolate* isolate, |
3462 Handle<String> subject, | 3301 Handle<String> subject, |
3463 Handle<String> search, | 3302 Handle<String> search, |
3464 Handle<String> replace, | 3303 Handle<String> replace, |
3465 bool* found, | 3304 bool* found, |
3466 int recursion_limit) { | 3305 int recursion_limit) { |
3467 if (recursion_limit == 0) return Handle<String>::null(); | 3306 if (recursion_limit == 0) return Handle<String>::null(); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3770 | 3609 |
3771 | 3610 |
3772 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringMatch) { | 3611 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringMatch) { |
3773 ASSERT_EQ(3, args.length()); | 3612 ASSERT_EQ(3, args.length()); |
3774 | 3613 |
3775 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); | 3614 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); |
3776 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); | 3615 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); |
3777 CONVERT_ARG_HANDLE_CHECKED(JSArray, regexp_info, 2); | 3616 CONVERT_ARG_HANDLE_CHECKED(JSArray, regexp_info, 2); |
3778 HandleScope handles; | 3617 HandleScope handles; |
3779 | 3618 |
3780 Handle<Object> match = RegExpImpl::Exec(regexp, subject, 0, regexp_info); | 3619 RegExpImpl::GlobalCache global_cache(regexp, subject, true, isolate); |
| 3620 if (global_cache.HasException()) return Failure::Exception(); |
3781 | 3621 |
3782 if (match.is_null()) { | 3622 int capture_count = regexp->CaptureCount(); |
3783 return Failure::Exception(); | |
3784 } | |
3785 if (match->IsNull()) { | |
3786 return isolate->heap()->null_value(); | |
3787 } | |
3788 int length = subject->length(); | |
3789 | 3623 |
3790 Zone* zone = isolate->runtime_zone(); | 3624 Zone* zone = isolate->runtime_zone(); |
3791 ZoneScope zone_space(zone, DELETE_ON_EXIT); | 3625 ZoneScope zone_space(zone, DELETE_ON_EXIT); |
3792 ZoneList<int> offsets(8, zone); | 3626 ZoneList<int> offsets(8, zone); |
3793 int start; | 3627 |
3794 int end; | 3628 while (true) { |
3795 do { | 3629 int32_t* match = global_cache.FetchNext(); |
3796 { | 3630 if (match == NULL) break; |
3797 AssertNoAllocation no_alloc; | 3631 offsets.Add(match[0], zone); // start |
3798 FixedArray* elements = FixedArray::cast(regexp_info->elements()); | 3632 offsets.Add(match[1], zone); // end |
3799 start = Smi::cast(elements->get(RegExpImpl::kFirstCapture))->value(); | 3633 } |
3800 end = Smi::cast(elements->get(RegExpImpl::kFirstCapture + 1))->value(); | 3634 |
3801 } | 3635 if (global_cache.HasException()) return Failure::Exception(); |
3802 offsets.Add(start, zone); | 3636 |
3803 offsets.Add(end, zone); | 3637 if (offsets.length() == 0) { |
3804 if (start == end) if (++end > length) break; | 3638 // Not a single match. |
3805 match = RegExpImpl::Exec(regexp, subject, end, regexp_info); | 3639 return isolate->heap()->null_value(); |
3806 if (match.is_null()) { | 3640 } |
3807 return Failure::Exception(); | 3641 |
3808 } | 3642 RegExpImpl::SetLastMatchInfo(regexp_info, |
3809 } while (!match->IsNull()); | 3643 subject, |
| 3644 capture_count, |
| 3645 global_cache.LastSuccessfulMatch()); |
| 3646 |
3810 int matches = offsets.length() / 2; | 3647 int matches = offsets.length() / 2; |
3811 Handle<FixedArray> elements = isolate->factory()->NewFixedArray(matches); | 3648 Handle<FixedArray> elements = isolate->factory()->NewFixedArray(matches); |
3812 Handle<String> substring = isolate->factory()-> | 3649 Handle<String> substring = |
3813 NewSubString(subject, offsets.at(0), offsets.at(1)); | 3650 isolate->factory()->NewSubString(subject, offsets.at(0), offsets.at(1)); |
3814 elements->set(0, *substring); | 3651 elements->set(0, *substring); |
3815 for (int i = 1; i < matches ; i++) { | 3652 for (int i = 1; i < matches; i++) { |
| 3653 HandleScope temp_scope(isolate); |
3816 int from = offsets.at(i * 2); | 3654 int from = offsets.at(i * 2); |
3817 int to = offsets.at(i * 2 + 1); | 3655 int to = offsets.at(i * 2 + 1); |
3818 Handle<String> substring = isolate->factory()-> | 3656 Handle<String> substring = |
3819 NewProperSubString(subject, from, to); | 3657 isolate->factory()->NewProperSubString(subject, from, to); |
3820 elements->set(i, *substring); | 3658 elements->set(i, *substring); |
3821 } | 3659 } |
3822 Handle<JSArray> result = isolate->factory()->NewJSArrayWithElements(elements); | 3660 Handle<JSArray> result = isolate->factory()->NewJSArrayWithElements(elements); |
3823 result->set_length(Smi::FromInt(matches)); | 3661 result->set_length(Smi::FromInt(matches)); |
3824 return *result; | 3662 return *result; |
3825 } | 3663 } |
3826 | 3664 |
3827 | 3665 |
3828 static bool SearchStringMultiple(Isolate* isolate, | 3666 // Only called from Runtime_RegExpExecMultiple so it doesn't need to maintain |
3829 Handle<String> subject, | 3667 // separate last match info. See comment on that function. |
3830 Handle<String> pattern, | 3668 template<bool has_capture> |
3831 Handle<JSArray> last_match_info, | 3669 static int SearchRegExpMultiple( |
3832 FixedArrayBuilder* builder) { | |
3833 ASSERT(subject->IsFlat()); | |
3834 ASSERT(pattern->IsFlat()); | |
3835 | |
3836 // Treating as if a previous match was before first character. | |
3837 int match_pos = -pattern->length(); | |
3838 | |
3839 for (;;) { // Break when search complete. | |
3840 builder->EnsureCapacity(kMaxBuilderEntriesPerRegExpMatch); | |
3841 AssertNoAllocation no_gc; | |
3842 String::FlatContent subject_content = subject->GetFlatContent(); | |
3843 String::FlatContent pattern_content = pattern->GetFlatContent(); | |
3844 if (subject_content.IsAscii()) { | |
3845 Vector<const char> subject_vector = subject_content.ToAsciiVector(); | |
3846 if (pattern_content.IsAscii()) { | |
3847 if (SearchStringMultiple(isolate, | |
3848 subject_vector, | |
3849 pattern_content.ToAsciiVector(), | |
3850 *pattern, | |
3851 builder, | |
3852 &match_pos)) break; | |
3853 } else { | |
3854 if (SearchStringMultiple(isolate, | |
3855 subject_vector, | |
3856 pattern_content.ToUC16Vector(), | |
3857 *pattern, | |
3858 builder, | |
3859 &match_pos)) break; | |
3860 } | |
3861 } else { | |
3862 Vector<const uc16> subject_vector = subject_content.ToUC16Vector(); | |
3863 if (pattern_content.IsAscii()) { | |
3864 if (SearchStringMultiple(isolate, | |
3865 subject_vector, | |
3866 pattern_content.ToAsciiVector(), | |
3867 *pattern, | |
3868 builder, | |
3869 &match_pos)) break; | |
3870 } else { | |
3871 if (SearchStringMultiple(isolate, | |
3872 subject_vector, | |
3873 pattern_content.ToUC16Vector(), | |
3874 *pattern, | |
3875 builder, | |
3876 &match_pos)) break; | |
3877 } | |
3878 } | |
3879 } | |
3880 | |
3881 if (match_pos >= 0) { | |
3882 SetLastMatchInfoNoCaptures(subject, | |
3883 last_match_info, | |
3884 match_pos, | |
3885 match_pos + pattern->length()); | |
3886 return true; | |
3887 } | |
3888 return false; // No matches at all. | |
3889 } | |
3890 | |
3891 | |
3892 static int SearchRegExpNoCaptureMultiple( | |
3893 Isolate* isolate, | 3670 Isolate* isolate, |
3894 Handle<String> subject, | 3671 Handle<String> subject, |
3895 Handle<JSRegExp> regexp, | 3672 Handle<JSRegExp> regexp, |
3896 Handle<JSArray> last_match_array, | 3673 Handle<JSArray> last_match_array, |
3897 FixedArrayBuilder* builder) { | 3674 FixedArrayBuilder* builder) { |
3898 ASSERT(subject->IsFlat()); | 3675 ASSERT(subject->IsFlat()); |
3899 ASSERT(regexp->CaptureCount() == 0); | 3676 ASSERT_NE(has_capture, regexp->CaptureCount() == 0); |
| 3677 |
| 3678 RegExpImpl::GlobalCache global_cache(regexp, subject, true, isolate); |
| 3679 if (global_cache.HasException()) return RegExpImpl::RE_EXCEPTION; |
| 3680 |
| 3681 int capture_count = regexp->CaptureCount(); |
| 3682 int subject_length = subject->length(); |
| 3683 |
| 3684 // Position to search from. |
3900 int match_start = -1; | 3685 int match_start = -1; |
3901 int match_end = 0; | 3686 int match_end = 0; |
3902 int pos = 0; | 3687 bool first = true; |
3903 int registers_per_match = RegExpImpl::IrregexpPrepare(regexp, subject); | |
3904 if (registers_per_match < 0) return RegExpImpl::RE_EXCEPTION; | |
3905 | 3688 |
3906 int max_matches; | 3689 // Two smis before and after the match, for very long strings. |
3907 int num_registers = RegExpImpl::GlobalOffsetsVectorSize(regexp, | 3690 static const int kMaxBuilderEntriesPerRegExpMatch = 5; |
3908 registers_per_match, | 3691 |
3909 &max_matches); | 3692 while (true) { |
3910 OffsetsVector registers(num_registers, isolate); | 3693 int32_t* current_match = global_cache.FetchNext(); |
3911 Vector<int32_t> register_vector(registers.vector(), registers.length()); | 3694 if (current_match == NULL) break; |
3912 int subject_length = subject->length(); | 3695 match_start = current_match[0]; |
3913 bool first = true; | 3696 builder->EnsureCapacity(kMaxBuilderEntriesPerRegExpMatch); |
3914 for (;;) { // Break on failure, return on exception. | 3697 if (match_end < match_start) { |
3915 int num_matches = RegExpImpl::IrregexpExecRaw(regexp, | 3698 ReplacementStringBuilder::AddSubjectSlice(builder, |
3916 subject, | 3699 match_end, |
3917 pos, | 3700 match_start); |
3918 register_vector); | 3701 } |
3919 if (num_matches > 0) { | 3702 match_end = current_match[1]; |
3920 for (int match_index = 0; match_index < num_matches; match_index++) { | 3703 { |
3921 int32_t* current_match = ®ister_vector[match_index * 2]; | 3704 // Avoid accumulating new handles inside loop. |
3922 match_start = current_match[0]; | 3705 HandleScope temp_scope(isolate); |
3923 builder->EnsureCapacity(kMaxBuilderEntriesPerRegExpMatch); | 3706 Handle<String> match; |
3924 if (match_end < match_start) { | 3707 if (!first) { |
3925 ReplacementStringBuilder::AddSubjectSlice(builder, | 3708 match = isolate->factory()->NewProperSubString(subject, |
3926 match_end, | 3709 match_start, |
3927 match_start); | 3710 match_end); |
3928 } | 3711 } else { |
3929 match_end = current_match[1]; | 3712 match = isolate->factory()->NewSubString(subject, |
3930 HandleScope loop_scope(isolate); | 3713 match_start, |
3931 if (!first) { | 3714 match_end); |
3932 builder->Add(*isolate->factory()->NewProperSubString(subject, | 3715 first = false; |
3933 match_start, | |
3934 match_end)); | |
3935 } else { | |
3936 builder->Add(*isolate->factory()->NewSubString(subject, | |
3937 match_start, | |
3938 match_end)); | |
3939 first = false; | |
3940 } | |
3941 } | 3716 } |
3942 | 3717 |
3943 // If we did not get the maximum number of matches, we can stop here | 3718 if (has_capture) { |
3944 // since there are no matches left. | 3719 // Arguments array to replace function is match, captures, index and |
3945 if (num_matches < max_matches) break; | 3720 // subject, i.e., 3 + capture count in total. |
| 3721 Handle<FixedArray> elements = |
| 3722 isolate->factory()->NewFixedArray(3 + capture_count); |
3946 | 3723 |
3947 if (match_start != match_end) { | 3724 elements->set(0, *match); |
3948 pos = match_end; | 3725 for (int i = 1; i <= capture_count; i++) { |
| 3726 int start = current_match[i * 2]; |
| 3727 if (start >= 0) { |
| 3728 int end = current_match[i * 2 + 1]; |
| 3729 ASSERT(start <= end); |
| 3730 Handle<String> substring = |
| 3731 isolate->factory()->NewSubString(subject, start, end); |
| 3732 elements->set(i, *substring); |
| 3733 } else { |
| 3734 ASSERT(current_match[i * 2 + 1] < 0); |
| 3735 elements->set(i, isolate->heap()->undefined_value()); |
| 3736 } |
| 3737 } |
| 3738 elements->set(capture_count + 1, Smi::FromInt(match_start)); |
| 3739 elements->set(capture_count + 2, *subject); |
| 3740 builder->Add(*isolate->factory()->NewJSArrayWithElements(elements)); |
3949 } else { | 3741 } else { |
3950 pos = match_end + 1; | 3742 builder->Add(*match); |
3951 if (pos > subject_length) break; | |
3952 } | 3743 } |
3953 } else if (num_matches == 0) { | |
3954 break; | |
3955 } else { | |
3956 ASSERT_EQ(num_matches, RegExpImpl::RE_EXCEPTION); | |
3957 return RegExpImpl::RE_EXCEPTION; | |
3958 } | 3744 } |
3959 } | 3745 } |
3960 | 3746 |
| 3747 if (global_cache.HasException()) return RegExpImpl::RE_EXCEPTION; |
| 3748 |
3961 if (match_start >= 0) { | 3749 if (match_start >= 0) { |
| 3750 // Finished matching, with at least one match. |
3962 if (match_end < subject_length) { | 3751 if (match_end < subject_length) { |
3963 ReplacementStringBuilder::AddSubjectSlice(builder, | 3752 ReplacementStringBuilder::AddSubjectSlice(builder, |
3964 match_end, | 3753 match_end, |
3965 subject_length); | 3754 subject_length); |
3966 } | 3755 } |
3967 SetLastMatchInfoNoCaptures(subject, | 3756 |
3968 last_match_array, | 3757 RegExpImpl::SetLastMatchInfo( |
3969 match_start, | 3758 last_match_array, subject, capture_count, NULL); |
3970 match_end); | 3759 |
3971 return RegExpImpl::RE_SUCCESS; | 3760 return RegExpImpl::RE_SUCCESS; |
3972 } else { | 3761 } else { |
3973 return RegExpImpl::RE_FAILURE; // No matches at all. | 3762 return RegExpImpl::RE_FAILURE; // No matches at all. |
3974 } | 3763 } |
3975 } | 3764 } |
3976 | 3765 |
3977 | 3766 |
3978 // Only called from Runtime_RegExpExecMultiple so it doesn't need to maintain | |
3979 // separate last match info. See comment on that function. | |
3980 static int SearchRegExpMultiple( | |
3981 Isolate* isolate, | |
3982 Handle<String> subject, | |
3983 Handle<JSRegExp> regexp, | |
3984 Handle<JSArray> last_match_array, | |
3985 FixedArrayBuilder* builder, | |
3986 Zone* zone) { | |
3987 | |
3988 ASSERT(subject->IsFlat()); | |
3989 int registers_per_match = RegExpImpl::IrregexpPrepare(regexp, subject); | |
3990 if (registers_per_match < 0) return RegExpImpl::RE_EXCEPTION; | |
3991 | |
3992 int max_matches; | |
3993 int num_registers = RegExpImpl::GlobalOffsetsVectorSize(regexp, | |
3994 registers_per_match, | |
3995 &max_matches); | |
3996 OffsetsVector registers(num_registers, isolate); | |
3997 Vector<int32_t> register_vector(registers.vector(), registers.length()); | |
3998 | |
3999 int num_matches = RegExpImpl::IrregexpExecRaw(regexp, | |
4000 subject, | |
4001 0, | |
4002 register_vector); | |
4003 | |
4004 int capture_count = regexp->CaptureCount(); | |
4005 int subject_length = subject->length(); | |
4006 | |
4007 // Position to search from. | |
4008 int pos = 0; | |
4009 // End of previous match. Differs from pos if match was empty. | |
4010 int match_end = 0; | |
4011 bool first = true; | |
4012 | |
4013 if (num_matches > 0) { | |
4014 do { | |
4015 int match_start = 0; | |
4016 for (int match_index = 0; match_index < num_matches; match_index++) { | |
4017 int32_t* current_match = | |
4018 ®ister_vector[match_index * registers_per_match]; | |
4019 match_start = current_match[0]; | |
4020 builder->EnsureCapacity(kMaxBuilderEntriesPerRegExpMatch); | |
4021 if (match_end < match_start) { | |
4022 ReplacementStringBuilder::AddSubjectSlice(builder, | |
4023 match_end, | |
4024 match_start); | |
4025 } | |
4026 match_end = current_match[1]; | |
4027 | |
4028 { | |
4029 // Avoid accumulating new handles inside loop. | |
4030 HandleScope temp_scope(isolate); | |
4031 // Arguments array to replace function is match, captures, index and | |
4032 // subject, i.e., 3 + capture count in total. | |
4033 Handle<FixedArray> elements = | |
4034 isolate->factory()->NewFixedArray(3 + capture_count); | |
4035 Handle<String> match; | |
4036 if (!first) { | |
4037 match = isolate->factory()->NewProperSubString(subject, | |
4038 match_start, | |
4039 match_end); | |
4040 } else { | |
4041 match = isolate->factory()->NewSubString(subject, | |
4042 match_start, | |
4043 match_end); | |
4044 } | |
4045 elements->set(0, *match); | |
4046 for (int i = 1; i <= capture_count; i++) { | |
4047 int start = current_match[i * 2]; | |
4048 if (start >= 0) { | |
4049 int end = current_match[i * 2 + 1]; | |
4050 ASSERT(start <= end); | |
4051 Handle<String> substring; | |
4052 if (!first) { | |
4053 substring = | |
4054 isolate->factory()->NewProperSubString(subject, start, end); | |
4055 } else { | |
4056 substring = | |
4057 isolate->factory()->NewSubString(subject, start, end); | |
4058 } | |
4059 elements->set(i, *substring); | |
4060 } else { | |
4061 ASSERT(current_match[i * 2 + 1] < 0); | |
4062 elements->set(i, isolate->heap()->undefined_value()); | |
4063 } | |
4064 } | |
4065 elements->set(capture_count + 1, Smi::FromInt(match_start)); | |
4066 elements->set(capture_count + 2, *subject); | |
4067 builder->Add(*isolate->factory()->NewJSArrayWithElements(elements)); | |
4068 } | |
4069 first = false; | |
4070 } | |
4071 | |
4072 // If we did not get the maximum number of matches, we can stop here | |
4073 // since there are no matches left. | |
4074 if (num_matches < max_matches) break; | |
4075 | |
4076 if (match_end > match_start) { | |
4077 pos = match_end; | |
4078 } else { | |
4079 pos = match_end + 1; | |
4080 if (pos > subject_length) { | |
4081 break; | |
4082 } | |
4083 } | |
4084 | |
4085 num_matches = RegExpImpl::IrregexpExecRaw(regexp, | |
4086 subject, | |
4087 pos, | |
4088 register_vector); | |
4089 } while (num_matches > 0); | |
4090 | |
4091 if (num_matches != RegExpImpl::RE_EXCEPTION) { | |
4092 // Finished matching, with at least one match. | |
4093 if (match_end < subject_length) { | |
4094 ReplacementStringBuilder::AddSubjectSlice(builder, | |
4095 match_end, | |
4096 subject_length); | |
4097 } | |
4098 | |
4099 int last_match_capture_count = (capture_count + 1) * 2; | |
4100 int last_match_array_size = | |
4101 last_match_capture_count + RegExpImpl::kLastMatchOverhead; | |
4102 last_match_array->EnsureSize(last_match_array_size); | |
4103 AssertNoAllocation no_gc; | |
4104 FixedArray* elements = FixedArray::cast(last_match_array->elements()); | |
4105 // We have to set this even though the rest of the last match array is | |
4106 // ignored. | |
4107 RegExpImpl::SetLastCaptureCount(elements, last_match_capture_count); | |
4108 // These are also read without consulting the override. | |
4109 RegExpImpl::SetLastSubject(elements, *subject); | |
4110 RegExpImpl::SetLastInput(elements, *subject); | |
4111 return RegExpImpl::RE_SUCCESS; | |
4112 } | |
4113 } | |
4114 // No matches at all, return failure or exception result directly. | |
4115 return num_matches; | |
4116 } | |
4117 | |
4118 | |
4119 // This is only called for StringReplaceGlobalRegExpWithFunction. This sets | 3767 // This is only called for StringReplaceGlobalRegExpWithFunction. This sets |
4120 // lastMatchInfoOverride to maintain the last match info, so we don't need to | 3768 // lastMatchInfoOverride to maintain the last match info, so we don't need to |
4121 // set any other last match array info. | 3769 // set any other last match array info. |
4122 RUNTIME_FUNCTION(MaybeObject*, Runtime_RegExpExecMultiple) { | 3770 RUNTIME_FUNCTION(MaybeObject*, Runtime_RegExpExecMultiple) { |
4123 ASSERT(args.length() == 4); | 3771 ASSERT(args.length() == 4); |
4124 HandleScope handles(isolate); | 3772 HandleScope handles(isolate); |
4125 | 3773 |
4126 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1); | 3774 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1); |
4127 if (!subject->IsFlat()) FlattenString(subject); | 3775 if (!subject->IsFlat()) FlattenString(subject); |
4128 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); | 3776 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); |
4129 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 2); | 3777 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 2); |
4130 CONVERT_ARG_HANDLE_CHECKED(JSArray, result_array, 3); | 3778 CONVERT_ARG_HANDLE_CHECKED(JSArray, result_array, 3); |
4131 | 3779 |
4132 ASSERT(last_match_info->HasFastObjectElements()); | 3780 ASSERT(last_match_info->HasFastObjectElements()); |
4133 ASSERT(regexp->GetFlags().is_global()); | 3781 ASSERT(regexp->GetFlags().is_global()); |
4134 Handle<FixedArray> result_elements; | 3782 Handle<FixedArray> result_elements; |
4135 if (result_array->HasFastObjectElements()) { | 3783 if (result_array->HasFastObjectElements()) { |
4136 result_elements = | 3784 result_elements = |
4137 Handle<FixedArray>(FixedArray::cast(result_array->elements())); | 3785 Handle<FixedArray>(FixedArray::cast(result_array->elements())); |
4138 } | 3786 } |
4139 if (result_elements.is_null() || result_elements->length() < 16) { | 3787 if (result_elements.is_null() || result_elements->length() < 16) { |
4140 result_elements = isolate->factory()->NewFixedArrayWithHoles(16); | 3788 result_elements = isolate->factory()->NewFixedArrayWithHoles(16); |
4141 } | 3789 } |
4142 FixedArrayBuilder builder(result_elements); | 3790 FixedArrayBuilder builder(result_elements); |
4143 | 3791 |
4144 if (regexp->TypeTag() == JSRegExp::ATOM) { | 3792 int result; |
4145 Handle<String> pattern( | 3793 if (regexp->CaptureCount() == 0) { |
4146 String::cast(regexp->DataAt(JSRegExp::kAtomPatternIndex))); | 3794 result = SearchRegExpMultiple<false>( |
4147 ASSERT(pattern->IsFlat()); | 3795 isolate, subject, regexp, last_match_info, &builder); |
4148 if (SearchStringMultiple(isolate, subject, pattern, | 3796 } else { |
4149 last_match_info, &builder)) { | 3797 result = SearchRegExpMultiple<true>( |
4150 return *builder.ToJSArray(result_array); | 3798 isolate, subject, regexp, last_match_info, &builder); |
4151 } | |
4152 return isolate->heap()->null_value(); | |
4153 } | 3799 } |
4154 | 3800 |
4155 ASSERT_EQ(regexp->TypeTag(), JSRegExp::IRREGEXP); | |
4156 | |
4157 int result; | |
4158 if (regexp->CaptureCount() == 0) { | |
4159 result = SearchRegExpNoCaptureMultiple(isolate, | |
4160 subject, | |
4161 regexp, | |
4162 last_match_info, | |
4163 &builder); | |
4164 } else { | |
4165 result = SearchRegExpMultiple(isolate, | |
4166 subject, | |
4167 regexp, | |
4168 last_match_info, | |
4169 &builder, | |
4170 isolate->runtime_zone()); | |
4171 } | |
4172 if (result == RegExpImpl::RE_SUCCESS) return *builder.ToJSArray(result_array); | 3801 if (result == RegExpImpl::RE_SUCCESS) return *builder.ToJSArray(result_array); |
4173 if (result == RegExpImpl::RE_FAILURE) return isolate->heap()->null_value(); | 3802 if (result == RegExpImpl::RE_FAILURE) return isolate->heap()->null_value(); |
4174 ASSERT_EQ(result, RegExpImpl::RE_EXCEPTION); | 3803 ASSERT_EQ(result, RegExpImpl::RE_EXCEPTION); |
4175 return Failure::Exception(); | 3804 return Failure::Exception(); |
4176 } | 3805 } |
4177 | 3806 |
4178 | 3807 |
4179 RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToRadixString) { | 3808 RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToRadixString) { |
4180 NoHandleAllocation ha; | 3809 NoHandleAllocation ha; |
4181 ASSERT(args.length() == 2); | 3810 ASSERT(args.length() == 2); |
(...skipping 3991 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8173 // called using 'new' and creates a new JSFunction object that | 7802 // called using 'new' and creates a new JSFunction object that |
8174 // is returned. The receiver object is only used for error | 7803 // is returned. The receiver object is only used for error |
8175 // reporting if an error occurs when constructing the new | 7804 // reporting if an error occurs when constructing the new |
8176 // JSFunction. FACTORY->NewJSObject() should not be used to | 7805 // JSFunction. FACTORY->NewJSObject() should not be used to |
8177 // allocate JSFunctions since it does not properly initialize | 7806 // allocate JSFunctions since it does not properly initialize |
8178 // the shared part of the function. Since the receiver is | 7807 // the shared part of the function. Since the receiver is |
8179 // ignored anyway, we use the global object as the receiver | 7808 // ignored anyway, we use the global object as the receiver |
8180 // instead of a new JSFunction object. This way, errors are | 7809 // instead of a new JSFunction object. This way, errors are |
8181 // reported the same way whether or not 'Function' is called | 7810 // reported the same way whether or not 'Function' is called |
8182 // using 'new'. | 7811 // using 'new'. |
8183 return isolate->context()->global_object(); | 7812 return isolate->context()->global(); |
8184 } | 7813 } |
8185 } | 7814 } |
8186 | 7815 |
8187 // The function should be compiled for the optimization hints to be | 7816 // The function should be compiled for the optimization hints to be |
8188 // available. | 7817 // available. |
8189 JSFunction::EnsureCompiled(function, CLEAR_EXCEPTION); | 7818 JSFunction::EnsureCompiled(function, CLEAR_EXCEPTION); |
8190 | 7819 |
8191 Handle<SharedFunctionInfo> shared(function->shared(), isolate); | 7820 Handle<SharedFunctionInfo> shared(function->shared(), isolate); |
8192 if (!function->has_initial_map() && | 7821 if (!function->has_initial_map() && |
8193 shared->IsInobjectSlackTrackingInProgress()) { | 7822 shared->IsInobjectSlackTrackingInProgress()) { |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8776 } else { | 8405 } else { |
8777 return maybe_js_object; | 8406 return maybe_js_object; |
8778 } | 8407 } |
8779 } | 8408 } |
8780 } | 8409 } |
8781 | 8410 |
8782 JSFunction* function; | 8411 JSFunction* function; |
8783 if (args[1]->IsSmi()) { | 8412 if (args[1]->IsSmi()) { |
8784 // A smi sentinel indicates a context nested inside global code rather | 8413 // A smi sentinel indicates a context nested inside global code rather |
8785 // 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 |
8786 // gotten from the native context. | 8415 // gotten from the global context. |
8787 function = isolate->context()->native_context()->closure(); | 8416 function = isolate->context()->global_context()->closure(); |
8788 } else { | 8417 } else { |
8789 function = JSFunction::cast(args[1]); | 8418 function = JSFunction::cast(args[1]); |
8790 } | 8419 } |
8791 | 8420 |
8792 Context* context; | 8421 Context* context; |
8793 MaybeObject* maybe_context = | 8422 MaybeObject* maybe_context = |
8794 isolate->heap()->AllocateWithContext(function, | 8423 isolate->heap()->AllocateWithContext(function, |
8795 isolate->context(), | 8424 isolate->context(), |
8796 extension_object); | 8425 extension_object); |
8797 if (!maybe_context->To(&context)) return maybe_context; | 8426 if (!maybe_context->To(&context)) return maybe_context; |
8798 isolate->set_context(context); | 8427 isolate->set_context(context); |
8799 return context; | 8428 return context; |
8800 } | 8429 } |
8801 | 8430 |
8802 | 8431 |
8803 RUNTIME_FUNCTION(MaybeObject*, Runtime_PushCatchContext) { | 8432 RUNTIME_FUNCTION(MaybeObject*, Runtime_PushCatchContext) { |
8804 NoHandleAllocation ha; | 8433 NoHandleAllocation ha; |
8805 ASSERT(args.length() == 3); | 8434 ASSERT(args.length() == 3); |
8806 String* name = String::cast(args[0]); | 8435 String* name = String::cast(args[0]); |
8807 Object* thrown_object = args[1]; | 8436 Object* thrown_object = args[1]; |
8808 JSFunction* function; | 8437 JSFunction* function; |
8809 if (args[2]->IsSmi()) { | 8438 if (args[2]->IsSmi()) { |
8810 // A smi sentinel indicates a context nested inside global code rather | 8439 // A smi sentinel indicates a context nested inside global code rather |
8811 // 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 |
8812 // gotten from the native context. | 8441 // gotten from the global context. |
8813 function = isolate->context()->native_context()->closure(); | 8442 function = isolate->context()->global_context()->closure(); |
8814 } else { | 8443 } else { |
8815 function = JSFunction::cast(args[2]); | 8444 function = JSFunction::cast(args[2]); |
8816 } | 8445 } |
8817 Context* context; | 8446 Context* context; |
8818 MaybeObject* maybe_context = | 8447 MaybeObject* maybe_context = |
8819 isolate->heap()->AllocateCatchContext(function, | 8448 isolate->heap()->AllocateCatchContext(function, |
8820 isolate->context(), | 8449 isolate->context(), |
8821 name, | 8450 name, |
8822 thrown_object); | 8451 thrown_object); |
8823 if (!maybe_context->To(&context)) return maybe_context; | 8452 if (!maybe_context->To(&context)) return maybe_context; |
8824 isolate->set_context(context); | 8453 isolate->set_context(context); |
8825 return context; | 8454 return context; |
8826 } | 8455 } |
8827 | 8456 |
8828 | 8457 |
8829 RUNTIME_FUNCTION(MaybeObject*, Runtime_PushBlockContext) { | 8458 RUNTIME_FUNCTION(MaybeObject*, Runtime_PushBlockContext) { |
8830 NoHandleAllocation ha; | 8459 NoHandleAllocation ha; |
8831 ASSERT(args.length() == 2); | 8460 ASSERT(args.length() == 2); |
8832 ScopeInfo* scope_info = ScopeInfo::cast(args[0]); | 8461 ScopeInfo* scope_info = ScopeInfo::cast(args[0]); |
8833 JSFunction* function; | 8462 JSFunction* function; |
8834 if (args[1]->IsSmi()) { | 8463 if (args[1]->IsSmi()) { |
8835 // A smi sentinel indicates a context nested inside global code rather | 8464 // A smi sentinel indicates a context nested inside global code rather |
8836 // 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 |
8837 // gotten from the native context. | 8466 // gotten from the global context. |
8838 function = isolate->context()->native_context()->closure(); | 8467 function = isolate->context()->global_context()->closure(); |
8839 } else { | 8468 } else { |
8840 function = JSFunction::cast(args[1]); | 8469 function = JSFunction::cast(args[1]); |
8841 } | 8470 } |
8842 Context* context; | 8471 Context* context; |
8843 MaybeObject* maybe_context = | 8472 MaybeObject* maybe_context = |
8844 isolate->heap()->AllocateBlockContext(function, | 8473 isolate->heap()->AllocateBlockContext(function, |
8845 isolate->context(), | 8474 isolate->context(), |
8846 scope_info); | 8475 scope_info); |
8847 if (!maybe_context->To(&context)) return maybe_context; | 8476 if (!maybe_context->To(&context)) return maybe_context; |
8848 isolate->set_context(context); | 8477 isolate->set_context(context); |
(...skipping 12 matching lines...) Expand all Loading... |
8861 NoHandleAllocation ha; | 8490 NoHandleAllocation ha; |
8862 ASSERT(args.length() == 1); | 8491 ASSERT(args.length() == 1); |
8863 CONVERT_ARG_HANDLE_CHECKED(JSModule, instance, 0); | 8492 CONVERT_ARG_HANDLE_CHECKED(JSModule, instance, 0); |
8864 | 8493 |
8865 Context* context = Context::cast(instance->context()); | 8494 Context* context = Context::cast(instance->context()); |
8866 Context* previous = isolate->context(); | 8495 Context* previous = isolate->context(); |
8867 ASSERT(context->IsModuleContext()); | 8496 ASSERT(context->IsModuleContext()); |
8868 // Initialize the context links. | 8497 // Initialize the context links. |
8869 context->set_previous(previous); | 8498 context->set_previous(previous); |
8870 context->set_closure(previous->closure()); | 8499 context->set_closure(previous->closure()); |
8871 context->set_global_object(previous->global_object()); | 8500 context->set_global(previous->global()); |
8872 isolate->set_context(context); | 8501 isolate->set_context(context); |
8873 | 8502 |
8874 return context; | 8503 return context; |
8875 } | 8504 } |
8876 | 8505 |
8877 | 8506 |
8878 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeleteContextSlot) { | 8507 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeleteContextSlot) { |
8879 HandleScope scope(isolate); | 8508 HandleScope scope(isolate); |
8880 ASSERT(args.length() == 2); | 8509 ASSERT(args.length() == 2); |
8881 | 8510 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8947 return x->IsTheHole() ? heap->undefined_value() : x; | 8576 return x->IsTheHole() ? heap->undefined_value() : x; |
8948 } | 8577 } |
8949 | 8578 |
8950 | 8579 |
8951 static Object* ComputeReceiverForNonGlobal(Isolate* isolate, | 8580 static Object* ComputeReceiverForNonGlobal(Isolate* isolate, |
8952 JSObject* holder) { | 8581 JSObject* holder) { |
8953 ASSERT(!holder->IsGlobalObject()); | 8582 ASSERT(!holder->IsGlobalObject()); |
8954 Context* top = isolate->context(); | 8583 Context* top = isolate->context(); |
8955 // Get the context extension function. | 8584 // Get the context extension function. |
8956 JSFunction* context_extension_function = | 8585 JSFunction* context_extension_function = |
8957 top->native_context()->context_extension_function(); | 8586 top->global_context()->context_extension_function(); |
8958 // 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 |
8959 // as the receiver. This allows arguments objects to be used as | 8588 // as the receiver. This allows arguments objects to be used as |
8960 // 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 |
8961 // explicitly via a with-statement. | 8590 // explicitly via a with-statement. |
8962 Object* constructor = holder->map()->constructor(); | 8591 Object* constructor = holder->map()->constructor(); |
8963 if (constructor != context_extension_function) return holder; | 8592 if (constructor != context_extension_function) return holder; |
8964 // 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 |
8965 // 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 |
8966 // context extension object - introduced via eval. Implicit global | 8595 // context extension object - introduced via eval. Implicit global |
8967 // receivers are indicated with the hole value. | 8596 // receivers are indicated with the hole value. |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9126 | 8755 |
9127 if (strict_mode == kStrictMode) { | 8756 if (strict_mode == kStrictMode) { |
9128 // Throw in strict mode (assignment to undefined variable). | 8757 // Throw in strict mode (assignment to undefined variable). |
9129 Handle<Object> error = | 8758 Handle<Object> error = |
9130 isolate->factory()->NewReferenceError( | 8759 isolate->factory()->NewReferenceError( |
9131 "not_defined", HandleVector(&name, 1)); | 8760 "not_defined", HandleVector(&name, 1)); |
9132 return isolate->Throw(*error); | 8761 return isolate->Throw(*error); |
9133 } | 8762 } |
9134 // In non-strict mode, the property is added to the global object. | 8763 // In non-strict mode, the property is added to the global object. |
9135 attributes = NONE; | 8764 attributes = NONE; |
9136 object = Handle<JSObject>(isolate->context()->global_object()); | 8765 object = Handle<JSObject>(isolate->context()->global()); |
9137 } | 8766 } |
9138 | 8767 |
9139 // Set the property if it's not read only or doesn't yet exist. | 8768 // Set the property if it's not read only or doesn't yet exist. |
9140 if ((attributes & READ_ONLY) == 0 || | 8769 if ((attributes & READ_ONLY) == 0 || |
9141 (object->GetLocalPropertyAttribute(*name) == ABSENT)) { | 8770 (object->GetLocalPropertyAttribute(*name) == ABSENT)) { |
9142 RETURN_IF_EMPTY_HANDLE( | 8771 RETURN_IF_EMPTY_HANDLE( |
9143 isolate, | 8772 isolate, |
9144 JSReceiver::SetProperty(object, name, value, NONE, strict_mode)); | 8773 JSReceiver::SetProperty(object, name, value, NONE, strict_mode)); |
9145 } else if (strict_mode == kStrictMode && (attributes & READ_ONLY) != 0) { | 8774 } else if (strict_mode == kStrictMode && (attributes & READ_ONLY) != 0) { |
9146 // Setting read only property in strict mode. | 8775 // 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)); | 9038 return callback(v8::Utils::ToLocal(context)); |
9410 } | 9039 } |
9411 } | 9040 } |
9412 | 9041 |
9413 | 9042 |
9414 RUNTIME_FUNCTION(MaybeObject*, Runtime_CompileString) { | 9043 RUNTIME_FUNCTION(MaybeObject*, Runtime_CompileString) { |
9415 HandleScope scope(isolate); | 9044 HandleScope scope(isolate); |
9416 ASSERT_EQ(1, args.length()); | 9045 ASSERT_EQ(1, args.length()); |
9417 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); | 9046 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); |
9418 | 9047 |
9419 // Extract native context. | 9048 // Extract global context. |
9420 Handle<Context> context(isolate->context()->native_context()); | 9049 Handle<Context> context(isolate->context()->global_context()); |
9421 | 9050 |
9422 // Check if native context allows code generation from | 9051 // Check if global context allows code generation from |
9423 // strings. Throw an exception if it doesn't. | 9052 // strings. Throw an exception if it doesn't. |
9424 if (context->allow_code_gen_from_strings()->IsFalse() && | 9053 if (context->allow_code_gen_from_strings()->IsFalse() && |
9425 !CodeGenerationFromStringsAllowed(isolate, context)) { | 9054 !CodeGenerationFromStringsAllowed(isolate, context)) { |
9426 return isolate->Throw(*isolate->factory()->NewError( | 9055 return isolate->Throw(*isolate->factory()->NewError( |
9427 "code_gen_from_strings", HandleVector<Object>(NULL, 0))); | 9056 "code_gen_from_strings", HandleVector<Object>(NULL, 0))); |
9428 } | 9057 } |
9429 | 9058 |
9430 // Compile source string in the native context. | 9059 // Compile source string in the global context. |
9431 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( | 9060 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( |
9432 source, context, true, CLASSIC_MODE, RelocInfo::kNoPosition); | 9061 source, context, true, CLASSIC_MODE, RelocInfo::kNoPosition); |
9433 if (shared.is_null()) return Failure::Exception(); | 9062 if (shared.is_null()) return Failure::Exception(); |
9434 Handle<JSFunction> fun = | 9063 Handle<JSFunction> fun = |
9435 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, | 9064 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, |
9436 context, | 9065 context, |
9437 NOT_TENURED); | 9066 NOT_TENURED); |
9438 return *fun; | 9067 return *fun; |
9439 } | 9068 } |
9440 | 9069 |
9441 | 9070 |
9442 static ObjectPair CompileGlobalEval(Isolate* isolate, | 9071 static ObjectPair CompileGlobalEval(Isolate* isolate, |
9443 Handle<String> source, | 9072 Handle<String> source, |
9444 Handle<Object> receiver, | 9073 Handle<Object> receiver, |
9445 LanguageMode language_mode, | 9074 LanguageMode language_mode, |
9446 int scope_position) { | 9075 int scope_position) { |
9447 Handle<Context> context = Handle<Context>(isolate->context()); | 9076 Handle<Context> context = Handle<Context>(isolate->context()); |
9448 Handle<Context> native_context = Handle<Context>(context->native_context()); | 9077 Handle<Context> global_context = Handle<Context>(context->global_context()); |
9449 | 9078 |
9450 // Check if native context allows code generation from | 9079 // Check if global context allows code generation from |
9451 // strings. Throw an exception if it doesn't. | 9080 // strings. Throw an exception if it doesn't. |
9452 if (native_context->allow_code_gen_from_strings()->IsFalse() && | 9081 if (global_context->allow_code_gen_from_strings()->IsFalse() && |
9453 !CodeGenerationFromStringsAllowed(isolate, native_context)) { | 9082 !CodeGenerationFromStringsAllowed(isolate, global_context)) { |
9454 isolate->Throw(*isolate->factory()->NewError( | 9083 isolate->Throw(*isolate->factory()->NewError( |
9455 "code_gen_from_strings", HandleVector<Object>(NULL, 0))); | 9084 "code_gen_from_strings", HandleVector<Object>(NULL, 0))); |
9456 return MakePair(Failure::Exception(), NULL); | 9085 return MakePair(Failure::Exception(), NULL); |
9457 } | 9086 } |
9458 | 9087 |
9459 // 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 |
9460 // and return the compiled function bound in the local context. | 9089 // and return the compiled function bound in the local context. |
9461 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( | 9090 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( |
9462 source, | 9091 source, |
9463 Handle<Context>(isolate->context()), | 9092 Handle<Context>(isolate->context()), |
9464 context->IsNativeContext(), | 9093 context->IsGlobalContext(), |
9465 language_mode, | 9094 language_mode, |
9466 scope_position); | 9095 scope_position); |
9467 if (shared.is_null()) return MakePair(Failure::Exception(), NULL); | 9096 if (shared.is_null()) return MakePair(Failure::Exception(), NULL); |
9468 Handle<JSFunction> compiled = | 9097 Handle<JSFunction> compiled = |
9469 isolate->factory()->NewFunctionFromSharedFunctionInfo( | 9098 isolate->factory()->NewFunctionFromSharedFunctionInfo( |
9470 shared, context, NOT_TENURED); | 9099 shared, context, NOT_TENURED); |
9471 return MakePair(*compiled, *receiver); | 9100 return MakePair(*compiled, *receiver); |
9472 } | 9101 } |
9473 | 9102 |
9474 | 9103 |
9475 RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEval) { | 9104 RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEval) { |
9476 ASSERT(args.length() == 5); | 9105 ASSERT(args.length() == 5); |
9477 | 9106 |
9478 HandleScope scope(isolate); | 9107 HandleScope scope(isolate); |
9479 Handle<Object> callee = args.at<Object>(0); | 9108 Handle<Object> callee = args.at<Object>(0); |
9480 | 9109 |
9481 // 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 |
9482 // direct call to eval. | 9111 // direct call to eval. |
9483 // (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 |
9484 // 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 |
9485 // the first argument without doing anything). | 9114 // the first argument without doing anything). |
9486 if (*callee != isolate->native_context()->global_eval_fun() || | 9115 if (*callee != isolate->global_context()->global_eval_fun() || |
9487 !args[1]->IsString()) { | 9116 !args[1]->IsString()) { |
9488 return MakePair(*callee, isolate->heap()->the_hole_value()); | 9117 return MakePair(*callee, isolate->heap()->the_hole_value()); |
9489 } | 9118 } |
9490 | 9119 |
9491 CONVERT_LANGUAGE_MODE_ARG(language_mode, 3); | 9120 CONVERT_LANGUAGE_MODE_ARG(language_mode, 3); |
9492 ASSERT(args[4]->IsSmi()); | 9121 ASSERT(args[4]->IsSmi()); |
9493 return CompileGlobalEval(isolate, | 9122 return CompileGlobalEval(isolate, |
9494 args.at<String>(1), | 9123 args.at<String>(1), |
9495 args.at<Object>(2), | 9124 args.at<Object>(2), |
9496 language_mode, | 9125 language_mode, |
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10381 | 10010 |
10382 ASSERT(args.length() == 2); | 10011 ASSERT(args.length() == 2); |
10383 | 10012 |
10384 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); | 10013 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); |
10385 CONVERT_ARG_HANDLE_CHECKED(String, name, 1); | 10014 CONVERT_ARG_HANDLE_CHECKED(String, name, 1); |
10386 | 10015 |
10387 // 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 |
10388 // 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 |
10389 // is that for some property lookups (accessors and interceptors) callbacks | 10018 // is that for some property lookups (accessors and interceptors) callbacks |
10390 // into the embedding application can occour, and the embedding application | 10019 // into the embedding application can occour, and the embedding application |
10391 // could have the assumption that its own native context is the current | 10020 // could have the assumption that its own global context is the current |
10392 // context and not some internal debugger context. | 10021 // context and not some internal debugger context. |
10393 SaveContext save(isolate); | 10022 SaveContext save(isolate); |
10394 if (isolate->debug()->InDebugger()) { | 10023 if (isolate->debug()->InDebugger()) { |
10395 isolate->set_context(*isolate->debug()->debugger_entry()->GetContext()); | 10024 isolate->set_context(*isolate->debug()->debugger_entry()->GetContext()); |
10396 } | 10025 } |
10397 | 10026 |
10398 // 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 |
10399 // real global object. | 10028 // real global object. |
10400 if (obj->IsJSGlobalProxy()) { | 10029 if (obj->IsJSGlobalProxy()) { |
10401 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 Loading... |
10926 // THE FRAME ITERATOR TO WRAP THE RECEIVER. | 10555 // THE FRAME ITERATOR TO WRAP THE RECEIVER. |
10927 Handle<Object> receiver(it.frame()->receiver(), isolate); | 10556 Handle<Object> receiver(it.frame()->receiver(), isolate); |
10928 if (!receiver->IsJSObject() && | 10557 if (!receiver->IsJSObject() && |
10929 shared->is_classic_mode() && | 10558 shared->is_classic_mode() && |
10930 !shared->native()) { | 10559 !shared->native()) { |
10931 // 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 |
10932 // builtin or strict-mode we have hit an optimization where a | 10561 // builtin or strict-mode we have hit an optimization where a |
10933 // value object is not converted into a wrapped JS objects. To | 10562 // value object is not converted into a wrapped JS objects. To |
10934 // hide this optimization from the debugger, we wrap the receiver | 10563 // hide this optimization from the debugger, we wrap the receiver |
10935 // by creating correct wrapper object based on the calling frame's | 10564 // by creating correct wrapper object based on the calling frame's |
10936 // native context. | 10565 // global context. |
10937 it.Advance(); | 10566 it.Advance(); |
10938 Handle<Context> calling_frames_native_context( | 10567 Handle<Context> calling_frames_global_context( |
10939 Context::cast(Context::cast(it.frame()->context())->native_context())); | 10568 Context::cast(Context::cast(it.frame()->context())->global_context())); |
10940 receiver = | 10569 receiver = |
10941 isolate->factory()->ToObject(receiver, calling_frames_native_context); | 10570 isolate->factory()->ToObject(receiver, calling_frames_global_context); |
10942 } | 10571 } |
10943 details->set(kFrameDetailsReceiverIndex, *receiver); | 10572 details->set(kFrameDetailsReceiverIndex, *receiver); |
10944 | 10573 |
10945 ASSERT_EQ(details_size, details_index); | 10574 ASSERT_EQ(details_size, details_index); |
10946 return *isolate->factory()->NewJSArrayWithElements(details); | 10575 return *isolate->factory()->NewJSArrayWithElements(details); |
10947 } | 10576 } |
10948 | 10577 |
10949 | 10578 |
10950 // 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. |
10951 static bool CopyContextLocalsToScopeObject( | 10580 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()); | 10652 Handle<Context> function_context(frame_context->declaration_context()); |
11024 if (!CopyContextLocalsToScopeObject( | 10653 if (!CopyContextLocalsToScopeObject( |
11025 isolate, scope_info, function_context, local_scope)) { | 10654 isolate, scope_info, function_context, local_scope)) { |
11026 return Handle<JSObject>(); | 10655 return Handle<JSObject>(); |
11027 } | 10656 } |
11028 | 10657 |
11029 // Finally copy any properties from the function context extension. | 10658 // Finally copy any properties from the function context extension. |
11030 // These will be variables introduced by eval. | 10659 // These will be variables introduced by eval. |
11031 if (function_context->closure() == *function) { | 10660 if (function_context->closure() == *function) { |
11032 if (function_context->has_extension() && | 10661 if (function_context->has_extension() && |
11033 !function_context->IsNativeContext()) { | 10662 !function_context->IsGlobalContext()) { |
11034 Handle<JSObject> ext(JSObject::cast(function_context->extension())); | 10663 Handle<JSObject> ext(JSObject::cast(function_context->extension())); |
11035 bool threw = false; | 10664 bool threw = false; |
11036 Handle<FixedArray> keys = | 10665 Handle<FixedArray> keys = |
11037 GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS, &threw); | 10666 GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS, &threw); |
11038 if (threw) return Handle<JSObject>(); | 10667 if (threw) return Handle<JSObject>(); |
11039 | 10668 |
11040 for (int i = 0; i < keys->length(); i++) { | 10669 for (int i = 0; i < keys->length(); i++) { |
11041 // Names of variables introduced by eval are strings. | 10670 // Names of variables introduced by eval are strings. |
11042 ASSERT(keys->get(i)->IsString()); | 10671 ASSERT(keys->get(i)->IsString()); |
11043 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 Loading... |
11285 } | 10914 } |
11286 | 10915 |
11287 // More scopes? | 10916 // More scopes? |
11288 bool Done() { return context_.is_null(); } | 10917 bool Done() { return context_.is_null(); } |
11289 | 10918 |
11290 // Move to the next scope. | 10919 // Move to the next scope. |
11291 void Next() { | 10920 void Next() { |
11292 ScopeType scope_type = Type(); | 10921 ScopeType scope_type = Type(); |
11293 if (scope_type == ScopeTypeGlobal) { | 10922 if (scope_type == ScopeTypeGlobal) { |
11294 // The global scope is always the last in the chain. | 10923 // The global scope is always the last in the chain. |
11295 ASSERT(context_->IsNativeContext()); | 10924 ASSERT(context_->IsGlobalContext()); |
11296 context_ = Handle<Context>(); | 10925 context_ = Handle<Context>(); |
11297 return; | 10926 return; |
11298 } | 10927 } |
11299 if (nested_scope_chain_.is_empty()) { | 10928 if (nested_scope_chain_.is_empty()) { |
11300 context_ = Handle<Context>(context_->previous(), isolate_); | 10929 context_ = Handle<Context>(context_->previous(), isolate_); |
11301 } else { | 10930 } else { |
11302 if (nested_scope_chain_.last()->HasContext()) { | 10931 if (nested_scope_chain_.last()->HasContext()) { |
11303 ASSERT(context_->previous() != NULL); | 10932 ASSERT(context_->previous() != NULL); |
11304 context_ = Handle<Context>(context_->previous(), isolate_); | 10933 context_ = Handle<Context>(context_->previous(), isolate_); |
11305 } | 10934 } |
11306 nested_scope_chain_.RemoveLast(); | 10935 nested_scope_chain_.RemoveLast(); |
11307 } | 10936 } |
11308 } | 10937 } |
11309 | 10938 |
11310 // Return the type of the current scope. | 10939 // Return the type of the current scope. |
11311 ScopeType Type() { | 10940 ScopeType Type() { |
11312 if (!nested_scope_chain_.is_empty()) { | 10941 if (!nested_scope_chain_.is_empty()) { |
11313 Handle<ScopeInfo> scope_info = nested_scope_chain_.last(); | 10942 Handle<ScopeInfo> scope_info = nested_scope_chain_.last(); |
11314 switch (scope_info->Type()) { | 10943 switch (scope_info->Type()) { |
11315 case FUNCTION_SCOPE: | 10944 case FUNCTION_SCOPE: |
11316 ASSERT(context_->IsFunctionContext() || | 10945 ASSERT(context_->IsFunctionContext() || |
11317 !scope_info->HasContext()); | 10946 !scope_info->HasContext()); |
11318 return ScopeTypeLocal; | 10947 return ScopeTypeLocal; |
11319 case MODULE_SCOPE: | 10948 case MODULE_SCOPE: |
11320 ASSERT(context_->IsModuleContext()); | 10949 ASSERT(context_->IsModuleContext()); |
11321 return ScopeTypeModule; | 10950 return ScopeTypeModule; |
11322 case GLOBAL_SCOPE: | 10951 case GLOBAL_SCOPE: |
11323 ASSERT(context_->IsNativeContext()); | 10952 ASSERT(context_->IsGlobalContext()); |
11324 return ScopeTypeGlobal; | 10953 return ScopeTypeGlobal; |
11325 case WITH_SCOPE: | 10954 case WITH_SCOPE: |
11326 ASSERT(context_->IsWithContext()); | 10955 ASSERT(context_->IsWithContext()); |
11327 return ScopeTypeWith; | 10956 return ScopeTypeWith; |
11328 case CATCH_SCOPE: | 10957 case CATCH_SCOPE: |
11329 ASSERT(context_->IsCatchContext()); | 10958 ASSERT(context_->IsCatchContext()); |
11330 return ScopeTypeCatch; | 10959 return ScopeTypeCatch; |
11331 case BLOCK_SCOPE: | 10960 case BLOCK_SCOPE: |
11332 ASSERT(!scope_info->HasContext() || | 10961 ASSERT(!scope_info->HasContext() || |
11333 context_->IsBlockContext()); | 10962 context_->IsBlockContext()); |
11334 return ScopeTypeBlock; | 10963 return ScopeTypeBlock; |
11335 case EVAL_SCOPE: | 10964 case EVAL_SCOPE: |
11336 UNREACHABLE(); | 10965 UNREACHABLE(); |
11337 } | 10966 } |
11338 } | 10967 } |
11339 if (context_->IsNativeContext()) { | 10968 if (context_->IsGlobalContext()) { |
11340 ASSERT(context_->global_object()->IsGlobalObject()); | 10969 ASSERT(context_->global()->IsGlobalObject()); |
11341 return ScopeTypeGlobal; | 10970 return ScopeTypeGlobal; |
11342 } | 10971 } |
11343 if (context_->IsFunctionContext()) { | 10972 if (context_->IsFunctionContext()) { |
11344 return ScopeTypeClosure; | 10973 return ScopeTypeClosure; |
11345 } | 10974 } |
11346 if (context_->IsCatchContext()) { | 10975 if (context_->IsCatchContext()) { |
11347 return ScopeTypeCatch; | 10976 return ScopeTypeCatch; |
11348 } | 10977 } |
11349 if (context_->IsBlockContext()) { | 10978 if (context_->IsBlockContext()) { |
11350 return ScopeTypeBlock; | 10979 return ScopeTypeBlock; |
11351 } | 10980 } |
11352 if (context_->IsModuleContext()) { | 10981 if (context_->IsModuleContext()) { |
11353 return ScopeTypeModule; | 10982 return ScopeTypeModule; |
11354 } | 10983 } |
11355 ASSERT(context_->IsWithContext()); | 10984 ASSERT(context_->IsWithContext()); |
11356 return ScopeTypeWith; | 10985 return ScopeTypeWith; |
11357 } | 10986 } |
11358 | 10987 |
11359 // Return the JavaScript object with the content of the current scope. | 10988 // Return the JavaScript object with the content of the current scope. |
11360 Handle<JSObject> ScopeObject() { | 10989 Handle<JSObject> ScopeObject() { |
11361 switch (Type()) { | 10990 switch (Type()) { |
11362 case ScopeIterator::ScopeTypeGlobal: | 10991 case ScopeIterator::ScopeTypeGlobal: |
11363 return Handle<JSObject>(CurrentContext()->global_object()); | 10992 return Handle<JSObject>(CurrentContext()->global()); |
11364 case ScopeIterator::ScopeTypeLocal: | 10993 case ScopeIterator::ScopeTypeLocal: |
11365 // Materialize the content of the local scope into a JSObject. | 10994 // Materialize the content of the local scope into a JSObject. |
11366 ASSERT(nested_scope_chain_.length() == 1); | 10995 ASSERT(nested_scope_chain_.length() == 1); |
11367 return MaterializeLocalScope(isolate_, frame_, inlined_jsframe_index_); | 10996 return MaterializeLocalScope(isolate_, frame_, inlined_jsframe_index_); |
11368 case ScopeIterator::ScopeTypeWith: | 10997 case ScopeIterator::ScopeTypeWith: |
11369 // Return the with object. | 10998 // Return the with object. |
11370 return Handle<JSObject>(JSObject::cast(CurrentContext()->extension())); | 10999 return Handle<JSObject>(JSObject::cast(CurrentContext()->extension())); |
11371 case ScopeIterator::ScopeTypeCatch: | 11000 case ScopeIterator::ScopeTypeCatch: |
11372 return MaterializeCatchScope(isolate_, CurrentContext()); | 11001 return MaterializeCatchScope(isolate_, CurrentContext()); |
11373 case ScopeIterator::ScopeTypeClosure: | 11002 case ScopeIterator::ScopeTypeClosure: |
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12218 | 11847 |
12219 Handle<String> function_source = | 11848 Handle<String> function_source = |
12220 isolate->factory()->NewStringFromAscii( | 11849 isolate->factory()->NewStringFromAscii( |
12221 Vector<const char>(kSourceStr, sizeof(kSourceStr) - 1)); | 11850 Vector<const char>(kSourceStr, sizeof(kSourceStr) - 1)); |
12222 | 11851 |
12223 // Currently, the eval code will be executed in non-strict mode, | 11852 // Currently, the eval code will be executed in non-strict mode, |
12224 // even in the strict code context. | 11853 // even in the strict code context. |
12225 Handle<SharedFunctionInfo> shared = | 11854 Handle<SharedFunctionInfo> shared = |
12226 Compiler::CompileEval(function_source, | 11855 Compiler::CompileEval(function_source, |
12227 context, | 11856 context, |
12228 context->IsNativeContext(), | 11857 context->IsGlobalContext(), |
12229 CLASSIC_MODE, | 11858 CLASSIC_MODE, |
12230 RelocInfo::kNoPosition); | 11859 RelocInfo::kNoPosition); |
12231 if (shared.is_null()) return Failure::Exception(); | 11860 if (shared.is_null()) return Failure::Exception(); |
12232 Handle<JSFunction> compiled_function = | 11861 Handle<JSFunction> compiled_function = |
12233 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context); | 11862 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context); |
12234 | 11863 |
12235 // Invoke the result of the compilation to get the evaluation function. | 11864 // Invoke the result of the compilation to get the evaluation function. |
12236 bool has_pending_exception; | 11865 bool has_pending_exception; |
12237 Handle<Object> receiver(frame->receiver(), isolate); | 11866 Handle<Object> receiver(frame->receiver(), isolate); |
12238 Handle<Object> evaluation_function = | 11867 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. | 11918 // Enter the top context from before the debugger was invoked. |
12290 SaveContext save(isolate); | 11919 SaveContext save(isolate); |
12291 SaveContext* top = &save; | 11920 SaveContext* top = &save; |
12292 while (top != NULL && *top->context() == *isolate->debug()->debug_context()) { | 11921 while (top != NULL && *top->context() == *isolate->debug()->debug_context()) { |
12293 top = top->prev(); | 11922 top = top->prev(); |
12294 } | 11923 } |
12295 if (top != NULL) { | 11924 if (top != NULL) { |
12296 isolate->set_context(*top->context()); | 11925 isolate->set_context(*top->context()); |
12297 } | 11926 } |
12298 | 11927 |
12299 // Get the native context now set to the top context from before the | 11928 // Get the global context now set to the top context from before the |
12300 // debugger was invoked. | 11929 // debugger was invoked. |
12301 Handle<Context> context = isolate->native_context(); | 11930 Handle<Context> context = isolate->global_context(); |
12302 | 11931 |
12303 bool is_global = true; | 11932 bool is_global = true; |
12304 | 11933 |
12305 if (additional_context->IsJSObject()) { | 11934 if (additional_context->IsJSObject()) { |
12306 // Create a new with context with the additional context information between | 11935 // 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. | 11936 // the context of the debugged function and the eval code to be executed. |
12308 context = isolate->factory()->NewWithContext( | 11937 context = isolate->factory()->NewWithContext( |
12309 Handle<JSFunction>(context->closure()), | 11938 Handle<JSFunction>(context->closure()), |
12310 context, | 11939 context, |
12311 Handle<JSObject>::cast(additional_context)); | 11940 Handle<JSObject>::cast(additional_context)); |
(...skipping 10 matching lines...) Expand all Loading... |
12322 CLASSIC_MODE, | 11951 CLASSIC_MODE, |
12323 RelocInfo::kNoPosition); | 11952 RelocInfo::kNoPosition); |
12324 if (shared.is_null()) return Failure::Exception(); | 11953 if (shared.is_null()) return Failure::Exception(); |
12325 Handle<JSFunction> compiled_function = | 11954 Handle<JSFunction> compiled_function = |
12326 Handle<JSFunction>( | 11955 Handle<JSFunction>( |
12327 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, | 11956 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, |
12328 context)); | 11957 context)); |
12329 | 11958 |
12330 // Invoke the result of the compilation to get the evaluation function. | 11959 // Invoke the result of the compilation to get the evaluation function. |
12331 bool has_pending_exception; | 11960 bool has_pending_exception; |
12332 Handle<Object> receiver = isolate->global_object(); | 11961 Handle<Object> receiver = isolate->global(); |
12333 Handle<Object> result = | 11962 Handle<Object> result = |
12334 Execution::Call(compiled_function, receiver, 0, NULL, | 11963 Execution::Call(compiled_function, receiver, 0, NULL, |
12335 &has_pending_exception); | 11964 &has_pending_exception); |
12336 // Clear the oneshot breakpoints so that the debugger does not step further. | 11965 // Clear the oneshot breakpoints so that the debugger does not step further. |
12337 isolate->debug()->ClearStepping(); | 11966 isolate->debug()->ClearStepping(); |
12338 if (has_pending_exception) return Failure::Exception(); | 11967 if (has_pending_exception) return Failure::Exception(); |
12339 return *result; | 11968 return *result; |
12340 } | 11969 } |
12341 | 11970 |
12342 | 11971 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12456 CONVERT_ARG_CHECKED(JSObject, target, 0); | 12085 CONVERT_ARG_CHECKED(JSObject, target, 0); |
12457 Object* instance_filter = args[1]; | 12086 Object* instance_filter = args[1]; |
12458 RUNTIME_ASSERT(instance_filter->IsUndefined() || | 12087 RUNTIME_ASSERT(instance_filter->IsUndefined() || |
12459 instance_filter->IsJSObject()); | 12088 instance_filter->IsJSObject()); |
12460 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]); | 12089 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]); |
12461 RUNTIME_ASSERT(max_references >= 0); | 12090 RUNTIME_ASSERT(max_references >= 0); |
12462 | 12091 |
12463 | 12092 |
12464 // Get the constructor function for context extension and arguments array. | 12093 // Get the constructor function for context extension and arguments array. |
12465 JSObject* arguments_boilerplate = | 12094 JSObject* arguments_boilerplate = |
12466 isolate->context()->native_context()->arguments_boilerplate(); | 12095 isolate->context()->global_context()->arguments_boilerplate(); |
12467 JSFunction* arguments_function = | 12096 JSFunction* arguments_function = |
12468 JSFunction::cast(arguments_boilerplate->map()->constructor()); | 12097 JSFunction::cast(arguments_boilerplate->map()->constructor()); |
12469 | 12098 |
12470 // Get the number of referencing objects. | 12099 // Get the number of referencing objects. |
12471 int count; | 12100 int count; |
12472 HeapIterator heap_iterator; | 12101 HeapIterator heap_iterator; |
12473 count = DebugReferencedBy(&heap_iterator, | 12102 count = DebugReferencedBy(&heap_iterator, |
12474 target, instance_filter, max_references, | 12103 target, instance_filter, max_references, |
12475 NULL, 0, arguments_function); | 12104 NULL, 0, arguments_function); |
12476 | 12105 |
12477 // Allocate an array to hold the result. | 12106 // Allocate an array to hold the result. |
12478 Object* object; | 12107 Object* object; |
12479 { MaybeObject* maybe_object = isolate->heap()->AllocateFixedArray(count); | 12108 { MaybeObject* maybe_object = isolate->heap()->AllocateFixedArray(count); |
12480 if (!maybe_object->ToObject(&object)) return maybe_object; | 12109 if (!maybe_object->ToObject(&object)) return maybe_object; |
12481 } | 12110 } |
12482 FixedArray* instances = FixedArray::cast(object); | 12111 FixedArray* instances = FixedArray::cast(object); |
12483 | 12112 |
12484 // Fill the referencing objects. | 12113 // Fill the referencing objects. |
12485 // AllocateFixedArray above does not make the heap non-iterable. | 12114 // AllocateFixedArray above does not make the heap non-iterable. |
12486 ASSERT(HEAP->IsHeapIterable()); | 12115 ASSERT(HEAP->IsHeapIterable()); |
12487 HeapIterator heap_iterator2; | 12116 HeapIterator heap_iterator2; |
12488 count = DebugReferencedBy(&heap_iterator2, | 12117 count = DebugReferencedBy(&heap_iterator2, |
12489 target, instance_filter, max_references, | 12118 target, instance_filter, max_references, |
12490 instances, count, arguments_function); | 12119 instances, count, arguments_function); |
12491 | 12120 |
12492 // Return result as JS array. | 12121 // Return result as JS array. |
12493 Object* result; | 12122 Object* result; |
12494 MaybeObject* maybe_result = isolate->heap()->AllocateJSObject( | 12123 MaybeObject* maybe_result = isolate->heap()->AllocateJSObject( |
12495 isolate->context()->native_context()->array_function()); | 12124 isolate->context()->global_context()->array_function()); |
12496 if (!maybe_result->ToObject(&result)) return maybe_result; | 12125 if (!maybe_result->ToObject(&result)) return maybe_result; |
12497 return JSArray::cast(result)->SetContent(instances); | 12126 return JSArray::cast(result)->SetContent(instances); |
12498 } | 12127 } |
12499 | 12128 |
12500 | 12129 |
12501 // Helper function used by Runtime_DebugConstructedBy below. | 12130 // Helper function used by Runtime_DebugConstructedBy below. |
12502 static int DebugConstructedBy(HeapIterator* iterator, | 12131 static int DebugConstructedBy(HeapIterator* iterator, |
12503 JSFunction* constructor, | 12132 JSFunction* constructor, |
12504 int max_references, | 12133 int max_references, |
12505 FixedArray* instances, | 12134 FixedArray* instances, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12566 HeapIterator heap_iterator2; | 12195 HeapIterator heap_iterator2; |
12567 count = DebugConstructedBy(&heap_iterator2, | 12196 count = DebugConstructedBy(&heap_iterator2, |
12568 constructor, | 12197 constructor, |
12569 max_references, | 12198 max_references, |
12570 instances, | 12199 instances, |
12571 count); | 12200 count); |
12572 | 12201 |
12573 // Return result as JS array. | 12202 // Return result as JS array. |
12574 Object* result; | 12203 Object* result; |
12575 { MaybeObject* maybe_result = isolate->heap()->AllocateJSObject( | 12204 { MaybeObject* maybe_result = isolate->heap()->AllocateJSObject( |
12576 isolate->context()->native_context()->array_function()); | 12205 isolate->context()->global_context()->array_function()); |
12577 if (!maybe_result->ToObject(&result)) return maybe_result; | 12206 if (!maybe_result->ToObject(&result)) return maybe_result; |
12578 } | 12207 } |
12579 return JSArray::cast(result)->SetContent(instances); | 12208 return JSArray::cast(result)->SetContent(instances); |
12580 } | 12209 } |
12581 | 12210 |
12582 | 12211 |
12583 // Find the effective prototype object as returned by __proto__. | 12212 // Find the effective prototype object as returned by __proto__. |
12584 // args[0]: the object to find the prototype for. | 12213 // args[0]: the object to find the prototype for. |
12585 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugGetPrototype) { | 12214 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugGetPrototype) { |
12586 ASSERT(args.length() == 1); | 12215 ASSERT(args.length() == 1); |
12587 | 12216 |
12588 CONVERT_ARG_CHECKED(JSObject, obj, 0); | 12217 CONVERT_ARG_CHECKED(JSObject, obj, 0); |
12589 | 12218 |
12590 // Use the __proto__ accessor. | 12219 // Use the __proto__ accessor. |
12591 return Accessors::ObjectPrototype.getter(obj, NULL); | 12220 return Accessors::ObjectPrototype.getter(obj, NULL); |
12592 } | 12221 } |
12593 | 12222 |
12594 | 12223 |
12595 // Patches script source (should be called upon BeforeCompile event). | 12224 // Patches script source (should be called upon BeforeCompile event). |
12596 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugSetScriptSource) { | 12225 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugSetScriptSource) { |
12597 HandleScope scope(isolate); | 12226 HandleScope scope(isolate); |
12598 ASSERT(args.length() == 2); | 12227 ASSERT(args.length() == 2); |
12599 | 12228 |
12600 CONVERT_ARG_HANDLE_CHECKED(JSValue, script_wrapper, 0); | 12229 CONVERT_ARG_HANDLE_CHECKED(JSValue, script_wrapper, 0); |
12601 CONVERT_ARG_HANDLE_CHECKED(String, source, 1); | 12230 Handle<String> source(String::cast(args[1])); |
12602 | 12231 |
12603 RUNTIME_ASSERT(script_wrapper->value()->IsScript()); | 12232 RUNTIME_ASSERT(script_wrapper->value()->IsScript()); |
12604 Handle<Script> script(Script::cast(script_wrapper->value())); | 12233 Handle<Script> script(Script::cast(script_wrapper->value())); |
12605 | 12234 |
12606 int compilation_state = Smi::cast(script->compilation_state())->value(); | 12235 int compilation_state = Smi::cast(script->compilation_state())->value(); |
12607 RUNTIME_ASSERT(compilation_state == Script::COMPILATION_STATE_INITIAL); | 12236 RUNTIME_ASSERT(compilation_state == Script::COMPILATION_STATE_INITIAL); |
12608 script->set_source(*source); | 12237 script->set_source(*source); |
12609 | 12238 |
12610 return isolate->heap()->undefined_value(); | 12239 return isolate->heap()->undefined_value(); |
12611 } | 12240 } |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12957 RUNTIME_FUNCTION(MaybeObject*, Runtime_ExecuteInDebugContext) { | 12586 RUNTIME_FUNCTION(MaybeObject*, Runtime_ExecuteInDebugContext) { |
12958 ASSERT(args.length() == 2); | 12587 ASSERT(args.length() == 2); |
12959 HandleScope scope(isolate); | 12588 HandleScope scope(isolate); |
12960 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); | 12589 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); |
12961 CONVERT_BOOLEAN_ARG_CHECKED(without_debugger, 1); | 12590 CONVERT_BOOLEAN_ARG_CHECKED(without_debugger, 1); |
12962 | 12591 |
12963 Handle<Object> result; | 12592 Handle<Object> result; |
12964 bool pending_exception; | 12593 bool pending_exception; |
12965 { | 12594 { |
12966 if (without_debugger) { | 12595 if (without_debugger) { |
12967 result = Execution::Call(function, isolate->global_object(), 0, NULL, | 12596 result = Execution::Call(function, isolate->global(), 0, NULL, |
12968 &pending_exception); | 12597 &pending_exception); |
12969 } else { | 12598 } else { |
12970 EnterDebugger enter_debugger; | 12599 EnterDebugger enter_debugger; |
12971 result = Execution::Call(function, isolate->global_object(), 0, NULL, | 12600 result = Execution::Call(function, isolate->global(), 0, NULL, |
12972 &pending_exception); | 12601 &pending_exception); |
12973 } | 12602 } |
12974 } | 12603 } |
12975 if (!pending_exception) { | 12604 if (!pending_exception) { |
12976 return *result; | 12605 return *result; |
12977 } else { | 12606 } else { |
12978 return Failure::Exception(); | 12607 return Failure::Exception(); |
12979 } | 12608 } |
12980 } | 12609 } |
12981 | 12610 |
(...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. | 13069 // There is no value in the cache. Invoke the function and cache result. |
13441 HandleScope scope(isolate); | 13070 HandleScope scope(isolate); |
13442 | 13071 |
13443 Handle<JSFunctionResultCache> cache_handle(cache); | 13072 Handle<JSFunctionResultCache> cache_handle(cache); |
13444 Handle<Object> key_handle(key); | 13073 Handle<Object> key_handle(key); |
13445 Handle<Object> value; | 13074 Handle<Object> value; |
13446 { | 13075 { |
13447 Handle<JSFunction> factory(JSFunction::cast( | 13076 Handle<JSFunction> factory(JSFunction::cast( |
13448 cache_handle->get(JSFunctionResultCache::kFactoryIndex))); | 13077 cache_handle->get(JSFunctionResultCache::kFactoryIndex))); |
13449 // TODO(antonm): consider passing a receiver when constructing a cache. | 13078 // TODO(antonm): consider passing a receiver when constructing a cache. |
13450 Handle<Object> receiver(isolate->native_context()->global_object()); | 13079 Handle<Object> receiver(isolate->global_context()->global()); |
13451 // 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. |
13452 Handle<Object> argv[] = { key_handle }; | 13081 Handle<Object> argv[] = { key_handle }; |
13453 bool pending_exception; | 13082 bool pending_exception; |
13454 value = Execution::Call(factory, | 13083 value = Execution::Call(factory, |
13455 receiver, | 13084 receiver, |
13456 ARRAY_SIZE(argv), | 13085 ARRAY_SIZE(argv), |
13457 argv, | 13086 argv, |
13458 &pending_exception); | 13087 &pending_exception); |
13459 if (pending_exception) return Failure::Exception(); | 13088 if (pending_exception) return Failure::Exception(); |
13460 } | 13089 } |
(...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 | 13347 // Handle last resort GC and make sure to allow future allocations |
13719 // to grow the heap without causing GCs (if possible). | 13348 // to grow the heap without causing GCs (if possible). |
13720 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13349 isolate->counters()->gc_last_resort_from_js()->Increment(); |
13721 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13350 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
13722 "Runtime::PerformGC"); | 13351 "Runtime::PerformGC"); |
13723 } | 13352 } |
13724 } | 13353 } |
13725 | 13354 |
13726 | 13355 |
13727 } } // namespace v8::internal | 13356 } } // namespace v8::internal |
OLD | NEW |