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

Side by Side Diff: src/objects.cc

Issue 1489423002: [proxies] Make Object.{freeze,seal} behave correctly for proxies. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add some tests. Created 5 years 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
« no previous file with comments | « src/objects.h ('k') | src/runtime/runtime-classes.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 7215 matching lines...) Expand 10 before | Expand all | Expand 10 after
7226 7226
7227 return context->extension_object()->ReferencesObject(obj); 7227 return context->extension_object()->ReferencesObject(obj);
7228 } 7228 }
7229 } 7229 }
7230 7230
7231 // No references to object. 7231 // No references to object.
7232 return false; 7232 return false;
7233 } 7233 }
7234 7234
7235 7235
7236 Maybe<bool> JSReceiver::SetIntegrityLevel(Handle<JSReceiver> receiver,
7237 IntegrityLevel level,
7238 ShouldThrow should_throw) {
7239 DCHECK(level == SEALED || level == FROZEN);
7240
7241 if (receiver->IsJSObject()) {
7242 Handle<JSObject> object = Handle<JSObject>::cast(receiver);
7243 if (!object->HasSloppyArgumentsElements() &&
7244 !object->map()->is_observed() &&
7245 (!object->map()->is_strong() || level == SEALED)) { // Fast path.
7246 if (level == SEALED) {
7247 return JSObject::PreventExtensionsWithTransition<SEALED>(object,
7248 should_throw);
7249 } else {
7250 return JSObject::PreventExtensionsWithTransition<FROZEN>(object,
7251 should_throw);
7252 }
7253 }
7254 }
7255
7256 Isolate* isolate = receiver->GetIsolate();
7257
7258 MAYBE_RETURN(JSReceiver::PreventExtensions(receiver, should_throw),
7259 Nothing<bool>());
7260
7261 Handle<FixedArray> keys;
7262 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
7263 isolate, keys, JSReceiver::OwnPropertyKeys(receiver), Nothing<bool>());
7264
7265 PropertyDescriptor no_conf;
7266 no_conf.set_configurable(false);
7267
7268 PropertyDescriptor no_conf_no_write;
7269 no_conf_no_write.set_configurable(false);
7270 no_conf_no_write.set_writable(false);
7271
7272 if (level == SEALED) {
7273 for (int i = 0; i < keys->length(); ++i) {
7274 Handle<Object> key(keys->get(i), isolate);
7275 DefineOwnProperty(isolate, receiver, key, &no_conf, THROW_ON_ERROR);
7276 if (isolate->has_pending_exception()) return Nothing<bool>();
7277 }
7278 return Just(true);
7279 }
7280
7281 for (int i = 0; i < keys->length(); ++i) {
7282 Handle<Object> key(keys->get(i), isolate);
7283 PropertyDescriptor current_desc;
7284 bool owned = JSReceiver::GetOwnPropertyDescriptor(isolate, receiver, key,
7285 &current_desc);
7286 if (isolate->has_pending_exception()) return Nothing<bool>();
7287 if (owned) {
7288 PropertyDescriptor desc =
7289 PropertyDescriptor::IsAccessorDescriptor(&current_desc)
7290 ? no_conf
7291 : no_conf_no_write;
7292 DefineOwnProperty(isolate, receiver, key, &desc, THROW_ON_ERROR);
7293 if (isolate->has_pending_exception()) return Nothing<bool>();
7294 }
7295 }
7296 return Just(true);
7297 }
7298
7299
7236 Maybe<bool> JSReceiver::PreventExtensions(Handle<JSReceiver> object, 7300 Maybe<bool> JSReceiver::PreventExtensions(Handle<JSReceiver> object,
7237 ShouldThrow should_throw) { 7301 ShouldThrow should_throw) {
7238 if (object->IsJSProxy()) { 7302 if (object->IsJSProxy()) {
7239 return JSProxy::PreventExtensions(Handle<JSProxy>::cast(object), 7303 return JSProxy::PreventExtensions(Handle<JSProxy>::cast(object),
7240 should_throw); 7304 should_throw);
7241 } 7305 }
7242 DCHECK(object->IsJSObject()); 7306 DCHECK(object->IsJSObject());
7243 return JSObject::PreventExtensions(Handle<JSObject>::cast(object), 7307 return JSObject::PreventExtensions(Handle<JSObject>::cast(object),
7244 should_throw); 7308 should_throw);
7245 } 7309 }
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
7548 object->RequireSlowElements(dictionary); 7612 object->RequireSlowElements(dictionary);
7549 if (attrs != NONE) { 7613 if (attrs != NONE) {
7550 ApplyAttributesToDictionary(dictionary, attrs); 7614 ApplyAttributesToDictionary(dictionary, attrs);
7551 } 7615 }
7552 } 7616 }
7553 7617
7554 return Just(true); 7618 return Just(true);
7555 } 7619 }
7556 7620
7557 7621
7558 MaybeHandle<Object> JSObject::Freeze(Handle<JSObject> object) {
7559 MAYBE_RETURN_NULL(
7560 PreventExtensionsWithTransition<FROZEN>(object, THROW_ON_ERROR));
7561 return object;
7562 }
7563
7564
7565 MaybeHandle<Object> JSObject::Seal(Handle<JSObject> object) {
7566 MAYBE_RETURN_NULL(
7567 PreventExtensionsWithTransition<SEALED>(object, THROW_ON_ERROR));
7568 return object;
7569 }
7570
7571
7572 void JSObject::SetObserved(Handle<JSObject> object) { 7622 void JSObject::SetObserved(Handle<JSObject> object) {
7573 DCHECK(!object->IsJSGlobalProxy()); 7623 DCHECK(!object->IsJSGlobalProxy());
7574 DCHECK(!object->IsJSGlobalObject()); 7624 DCHECK(!object->IsJSGlobalObject());
7575 Isolate* isolate = object->GetIsolate(); 7625 Isolate* isolate = object->GetIsolate();
7576 Handle<Map> new_map; 7626 Handle<Map> new_map;
7577 Handle<Map> old_map(object->map(), isolate); 7627 Handle<Map> old_map(object->map(), isolate);
7578 DCHECK(!old_map->is_observed()); 7628 DCHECK(!old_map->is_observed());
7579 Map* transition = TransitionArray::SearchSpecial( 7629 Map* transition = TransitionArray::SearchSpecial(
7580 *old_map, isolate->heap()->observed_symbol()); 7630 *old_map, isolate->heap()->observed_symbol());
7581 if (transition != NULL) { 7631 if (transition != NULL) {
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
8409 Handle<FixedArray> trap_result; 8459 Handle<FixedArray> trap_result;
8410 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 8460 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
8411 isolate, trap_result, 8461 isolate, trap_result,
8412 CreateListFromArrayLike_StringSymbol(isolate, trap_result_array), false); 8462 CreateListFromArrayLike_StringSymbol(isolate, trap_result_array), false);
8413 // 9. Let extensibleTarget be ? IsExtensible(target). 8463 // 9. Let extensibleTarget be ? IsExtensible(target).
8414 Maybe<bool> maybe_extensible = JSReceiver::IsExtensible(target); 8464 Maybe<bool> maybe_extensible = JSReceiver::IsExtensible(target);
8415 if (maybe_extensible.IsNothing()) return false; 8465 if (maybe_extensible.IsNothing()) return false;
8416 bool extensible_target = maybe_extensible.FromJust(); 8466 bool extensible_target = maybe_extensible.FromJust();
8417 // 10. Let targetKeys be ? target.[[OwnPropertyKeys]](). 8467 // 10. Let targetKeys be ? target.[[OwnPropertyKeys]]().
8418 Handle<FixedArray> target_keys; 8468 Handle<FixedArray> target_keys;
8419 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 8469 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, target_keys,
8420 isolate, target_keys, 8470 JSReceiver::OwnPropertyKeys(target), false);
8421 JSReceiver::GetKeys(target, JSReceiver::OWN_ONLY, ALL_PROPERTIES,
8422 CONVERT_TO_STRING),
8423 false);
8424 // 11. (Assert) 8471 // 11. (Assert)
8425 // 12. Let targetConfigurableKeys be an empty List. 8472 // 12. Let targetConfigurableKeys be an empty List.
8426 // To save memory, we're re-using target_keys and will modify it in-place. 8473 // To save memory, we're re-using target_keys and will modify it in-place.
8427 Handle<FixedArray> target_configurable_keys = target_keys; 8474 Handle<FixedArray> target_configurable_keys = target_keys;
8428 // 13. Let targetNonconfigurableKeys be an empty List. 8475 // 13. Let targetNonconfigurableKeys be an empty List.
8429 Handle<FixedArray> target_nonconfigurable_keys = 8476 Handle<FixedArray> target_nonconfigurable_keys =
8430 isolate->factory()->NewFixedArray(target_keys->length()); 8477 isolate->factory()->NewFixedArray(target_keys->length());
8431 int nonconfigurable_keys_length = 0; 8478 int nonconfigurable_keys_length = 0;
8432 // 14. Repeat, for each element key of targetKeys: 8479 // 14. Repeat, for each element key of targetKeys:
8433 for (int i = 0; i < target_keys->length(); ++i) { 8480 for (int i = 0; i < target_keys->length(); ++i) {
(...skipping 10667 matching lines...) Expand 10 before | Expand all | Expand 10 after
19101 if (cell->value() != *new_value) { 19148 if (cell->value() != *new_value) {
19102 cell->set_value(*new_value); 19149 cell->set_value(*new_value);
19103 Isolate* isolate = cell->GetIsolate(); 19150 Isolate* isolate = cell->GetIsolate();
19104 cell->dependent_code()->DeoptimizeDependentCodeGroup( 19151 cell->dependent_code()->DeoptimizeDependentCodeGroup(
19105 isolate, DependentCode::kPropertyCellChangedGroup); 19152 isolate, DependentCode::kPropertyCellChangedGroup);
19106 } 19153 }
19107 } 19154 }
19108 19155
19109 } // namespace internal 19156 } // namespace internal
19110 } // namespace v8 19157 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/runtime/runtime-classes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698