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

Side by Side Diff: src/objects.cc

Issue 1689733002: Optimize @@species based on a global 'protector' cell (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/objects.h" 5 #include "src/objects.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <iomanip> 8 #include <iomanip>
9 #include <sstream> 9 #include <sstream>
10 10
(...skipping 1533 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 Simd128Value* b = Simd128Value::cast(other); 1544 Simd128Value* b = Simd128Value::cast(other);
1545 return a->map() == b->map() && a->BitwiseEquals(b); 1545 return a->map() == b->map() && a->BitwiseEquals(b);
1546 } 1546 }
1547 return false; 1547 return false;
1548 } 1548 }
1549 1549
1550 1550
1551 MaybeHandle<Object> Object::ArraySpeciesConstructor( 1551 MaybeHandle<Object> Object::ArraySpeciesConstructor(
1552 Isolate* isolate, Handle<Object> original_array) { 1552 Isolate* isolate, Handle<Object> original_array) {
1553 Handle<Context> native_context = isolate->native_context(); 1553 Handle<Context> native_context = isolate->native_context();
1554 Handle<Object> default_species = isolate->array_function();
1554 if (!FLAG_harmony_species) { 1555 if (!FLAG_harmony_species) {
1555 return Handle<Object>(native_context->array_function(), isolate); 1556 return default_species;
1557 }
1558 if (original_array->IsJSArray() &&
1559 Handle<JSReceiver>::cast(original_array)->map()->new_target_is_base() &&
1560 isolate->IsArraySpeciesLookupChainIntact()) {
1561 return default_species;
1556 } 1562 }
1557 Handle<Object> constructor = isolate->factory()->undefined_value(); 1563 Handle<Object> constructor = isolate->factory()->undefined_value();
1558 Maybe<bool> is_array = Object::IsArray(original_array); 1564 Maybe<bool> is_array = Object::IsArray(original_array);
1559 MAYBE_RETURN_NULL(is_array); 1565 MAYBE_RETURN_NULL(is_array);
1560 if (is_array.FromJust()) { 1566 if (is_array.FromJust()) {
1561 ASSIGN_RETURN_ON_EXCEPTION( 1567 ASSIGN_RETURN_ON_EXCEPTION(
1562 isolate, constructor, 1568 isolate, constructor,
1563 Object::GetProperty(original_array, 1569 Object::GetProperty(original_array,
1564 isolate->factory()->constructor_string()), 1570 isolate->factory()->constructor_string()),
1565 Object); 1571 Object);
(...skipping 13 matching lines...) Expand all
1579 isolate, constructor, 1585 isolate, constructor,
1580 Object::GetProperty(constructor, 1586 Object::GetProperty(constructor,
1581 isolate->factory()->species_symbol()), 1587 isolate->factory()->species_symbol()),
1582 Object); 1588 Object);
1583 if (constructor->IsNull()) { 1589 if (constructor->IsNull()) {
1584 constructor = isolate->factory()->undefined_value(); 1590 constructor = isolate->factory()->undefined_value();
1585 } 1591 }
1586 } 1592 }
1587 } 1593 }
1588 if (constructor->IsUndefined()) { 1594 if (constructor->IsUndefined()) {
1589 return Handle<Object>(native_context->array_function(), isolate); 1595 return default_species;
1590 } else { 1596 } else {
1591 if (!constructor->IsConstructor()) { 1597 if (!constructor->IsConstructor()) {
1592 THROW_NEW_ERROR(isolate, 1598 THROW_NEW_ERROR(isolate,
1593 NewTypeError(MessageTemplate::kSpeciesNotConstructor), 1599 NewTypeError(MessageTemplate::kSpeciesNotConstructor),
1594 Object); 1600 Object);
1595 } 1601 }
1596 return constructor; 1602 return constructor;
1597 } 1603 }
1598 } 1604 }
1599 1605
(...skipping 2537 matching lines...) Expand 10 before | Expand all | Expand 10 after
4137 MAYBE_RETURN_NULL(SetProperty(&it, value, language_mode, store_mode)); 4143 MAYBE_RETURN_NULL(SetProperty(&it, value, language_mode, store_mode));
4138 return value; 4144 return value;
4139 } 4145 }
4140 4146
4141 4147
4142 Maybe<bool> Object::SetPropertyInternal(LookupIterator* it, 4148 Maybe<bool> Object::SetPropertyInternal(LookupIterator* it,
4143 Handle<Object> value, 4149 Handle<Object> value,
4144 LanguageMode language_mode, 4150 LanguageMode language_mode,
4145 StoreFromKeyed store_mode, 4151 StoreFromKeyed store_mode,
4146 bool* found) { 4152 bool* found) {
4153 it->UpdateProtector();
4147 ShouldThrow should_throw = 4154 ShouldThrow should_throw =
4148 is_sloppy(language_mode) ? DONT_THROW : THROW_ON_ERROR; 4155 is_sloppy(language_mode) ? DONT_THROW : THROW_ON_ERROR;
4149 4156
4150 // Make sure that the top context does not change when doing callbacks or 4157 // Make sure that the top context does not change when doing callbacks or
4151 // interceptor calls. 4158 // interceptor calls.
4152 AssertNoContextChange ncc(it->isolate()); 4159 AssertNoContextChange ncc(it->isolate());
4153 4160
4154 *found = true; 4161 *found = true;
4155 4162
4156 bool done = false; 4163 bool done = false;
(...skipping 1111 matching lines...) Expand 10 before | Expand all | Expand 10 after
5268 AccessorInfoHandling handling) { 5275 AccessorInfoHandling handling) {
5269 MAYBE_RETURN_NULL(DefineOwnPropertyIgnoreAttributes( 5276 MAYBE_RETURN_NULL(DefineOwnPropertyIgnoreAttributes(
5270 it, value, attributes, THROW_ON_ERROR, handling)); 5277 it, value, attributes, THROW_ON_ERROR, handling));
5271 return value; 5278 return value;
5272 } 5279 }
5273 5280
5274 5281
5275 Maybe<bool> JSObject::DefineOwnPropertyIgnoreAttributes( 5282 Maybe<bool> JSObject::DefineOwnPropertyIgnoreAttributes(
5276 LookupIterator* it, Handle<Object> value, PropertyAttributes attributes, 5283 LookupIterator* it, Handle<Object> value, PropertyAttributes attributes,
5277 ShouldThrow should_throw, AccessorInfoHandling handling) { 5284 ShouldThrow should_throw, AccessorInfoHandling handling) {
5285 it->UpdateProtector();
5278 Handle<JSObject> object = Handle<JSObject>::cast(it->GetReceiver()); 5286 Handle<JSObject> object = Handle<JSObject>::cast(it->GetReceiver());
5279 bool is_observed = object->map()->is_observed() && 5287 bool is_observed = object->map()->is_observed() &&
5280 (it->IsElement() || !it->name()->IsPrivate()); 5288 (it->IsElement() || !it->name()->IsPrivate());
5281 5289
5282 for (; it->IsFound(); it->Next()) { 5290 for (; it->IsFound(); it->Next()) {
5283 switch (it->state()) { 5291 switch (it->state()) {
5284 case LookupIterator::JSPROXY: 5292 case LookupIterator::JSPROXY:
5285 case LookupIterator::NOT_FOUND: 5293 case LookupIterator::NOT_FOUND:
5286 case LookupIterator::TRANSITION: 5294 case LookupIterator::TRANSITION:
5287 UNREACHABLE(); 5295 UNREACHABLE();
(...skipping 10406 matching lines...) Expand 10 before | Expand all | Expand 10 after
15694 // 14. Return true. 15702 // 14. Return true.
15695 return Just(true); 15703 return Just(true);
15696 } 15704 }
15697 15705
15698 15706
15699 Maybe<bool> JSObject::SetPrototype(Handle<JSObject> object, 15707 Maybe<bool> JSObject::SetPrototype(Handle<JSObject> object,
15700 Handle<Object> value, bool from_javascript, 15708 Handle<Object> value, bool from_javascript,
15701 ShouldThrow should_throw) { 15709 ShouldThrow should_throw) {
15702 Isolate* isolate = object->GetIsolate(); 15710 Isolate* isolate = object->GetIsolate();
15703 15711
15712 // Setting the prototype of an Array instance invalidates the species
15713 // protector
15714 // because it could change the constructor property of the instance, which
15715 // could change the @@species constructor.
15716 if (object->IsJSArray() && isolate->IsArraySpeciesLookupChainIntact()) {
15717 isolate->CountUsage(
15718 v8::Isolate::UseCounterFeature::kArrayInstanceProtoModified);
15719 isolate->InvalidateArraySpeciesProtector();
15720 }
15721
15704 const bool observed = from_javascript && object->map()->is_observed(); 15722 const bool observed = from_javascript && object->map()->is_observed();
15705 Handle<Object> old_value; 15723 Handle<Object> old_value;
15706 if (observed) { 15724 if (observed) {
15707 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, old_value, 15725 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, old_value,
15708 JSReceiver::GetPrototype(isolate, object), 15726 JSReceiver::GetPrototype(isolate, object),
15709 Nothing<bool>()); 15727 Nothing<bool>());
15710 } 15728 }
15711 15729
15712 Maybe<bool> result = 15730 Maybe<bool> result =
15713 SetPrototypeUnobserved(object, value, from_javascript, should_throw); 15731 SetPrototypeUnobserved(object, value, from_javascript, should_throw);
(...skipping 4164 matching lines...) Expand 10 before | Expand all | Expand 10 after
19878 if (cell->value() != *new_value) { 19896 if (cell->value() != *new_value) {
19879 cell->set_value(*new_value); 19897 cell->set_value(*new_value);
19880 Isolate* isolate = cell->GetIsolate(); 19898 Isolate* isolate = cell->GetIsolate();
19881 cell->dependent_code()->DeoptimizeDependentCodeGroup( 19899 cell->dependent_code()->DeoptimizeDependentCodeGroup(
19882 isolate, DependentCode::kPropertyCellChangedGroup); 19900 isolate, DependentCode::kPropertyCellChangedGroup);
19883 } 19901 }
19884 } 19902 }
19885 19903
19886 } // namespace internal 19904 } // namespace internal
19887 } // namespace v8 19905 } // namespace v8
OLDNEW
« src/lookup.cc ('K') | « src/lookup.cc ('k') | test/mjsunit/harmony/array-species.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698