OLD | NEW |
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 Loading... |
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 ¤t_desc); |
| 7286 if (isolate->has_pending_exception()) return Nothing<bool>(); |
| 7287 if (owned) { |
| 7288 PropertyDescriptor desc = |
| 7289 PropertyDescriptor::IsAccessorDescriptor(¤t_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 |
| 7300 Maybe<bool> JSReceiver::TestIntegrityLevel(Handle<JSReceiver> object, |
| 7301 IntegrityLevel level) { |
| 7302 DCHECK(level == SEALED || level == FROZEN); |
| 7303 Isolate* isolate = object->GetIsolate(); |
| 7304 |
| 7305 Maybe<bool> extensible = JSReceiver::IsExtensible(object); |
| 7306 MAYBE_RETURN(extensible, Nothing<bool>()); |
| 7307 if (extensible.FromJust()) return Just(false); |
| 7308 |
| 7309 Handle<FixedArray> keys; |
| 7310 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 7311 isolate, keys, JSReceiver::OwnPropertyKeys(object), Nothing<bool>()); |
| 7312 |
| 7313 for (int i = 0; i < keys->length(); ++i) { |
| 7314 Handle<Object> key(keys->get(i), isolate); |
| 7315 PropertyDescriptor current_desc; |
| 7316 bool owned = JSReceiver::GetOwnPropertyDescriptor(isolate, object, key, |
| 7317 ¤t_desc); |
| 7318 if (isolate->has_pending_exception()) return Nothing<bool>(); |
| 7319 if (owned) { |
| 7320 if (current_desc.configurable()) return Just(false); |
| 7321 if (level == FROZEN && |
| 7322 PropertyDescriptor::IsDataDescriptor(¤t_desc) && |
| 7323 current_desc.writable()) { |
| 7324 return Just(false); |
| 7325 } |
| 7326 } |
| 7327 } |
| 7328 return Just(true); |
| 7329 } |
| 7330 |
| 7331 |
7236 Maybe<bool> JSReceiver::PreventExtensions(Handle<JSReceiver> object, | 7332 Maybe<bool> JSReceiver::PreventExtensions(Handle<JSReceiver> object, |
7237 ShouldThrow should_throw) { | 7333 ShouldThrow should_throw) { |
7238 if (object->IsJSProxy()) { | 7334 if (object->IsJSProxy()) { |
7239 return JSProxy::PreventExtensions(Handle<JSProxy>::cast(object), | 7335 return JSProxy::PreventExtensions(Handle<JSProxy>::cast(object), |
7240 should_throw); | 7336 should_throw); |
7241 } | 7337 } |
7242 DCHECK(object->IsJSObject()); | 7338 DCHECK(object->IsJSObject()); |
7243 return JSObject::PreventExtensions(Handle<JSObject>::cast(object), | 7339 return JSObject::PreventExtensions(Handle<JSObject>::cast(object), |
7244 should_throw); | 7340 should_throw); |
7245 } | 7341 } |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7548 object->RequireSlowElements(dictionary); | 7644 object->RequireSlowElements(dictionary); |
7549 if (attrs != NONE) { | 7645 if (attrs != NONE) { |
7550 ApplyAttributesToDictionary(dictionary, attrs); | 7646 ApplyAttributesToDictionary(dictionary, attrs); |
7551 } | 7647 } |
7552 } | 7648 } |
7553 | 7649 |
7554 return Just(true); | 7650 return Just(true); |
7555 } | 7651 } |
7556 | 7652 |
7557 | 7653 |
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) { | 7654 void JSObject::SetObserved(Handle<JSObject> object) { |
7573 DCHECK(!object->IsJSGlobalProxy()); | 7655 DCHECK(!object->IsJSGlobalProxy()); |
7574 DCHECK(!object->IsJSGlobalObject()); | 7656 DCHECK(!object->IsJSGlobalObject()); |
7575 Isolate* isolate = object->GetIsolate(); | 7657 Isolate* isolate = object->GetIsolate(); |
7576 Handle<Map> new_map; | 7658 Handle<Map> new_map; |
7577 Handle<Map> old_map(object->map(), isolate); | 7659 Handle<Map> old_map(object->map(), isolate); |
7578 DCHECK(!old_map->is_observed()); | 7660 DCHECK(!old_map->is_observed()); |
7579 Map* transition = TransitionArray::SearchSpecial( | 7661 Map* transition = TransitionArray::SearchSpecial( |
7580 *old_map, isolate->heap()->observed_symbol()); | 7662 *old_map, isolate->heap()->observed_symbol()); |
7581 if (transition != NULL) { | 7663 if (transition != NULL) { |
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8402 Handle<FixedArray> trap_result; | 8484 Handle<FixedArray> trap_result; |
8403 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 8485 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
8404 isolate, trap_result, | 8486 isolate, trap_result, |
8405 CreateListFromArrayLike_StringSymbol(isolate, trap_result_array), false); | 8487 CreateListFromArrayLike_StringSymbol(isolate, trap_result_array), false); |
8406 // 9. Let extensibleTarget be ? IsExtensible(target). | 8488 // 9. Let extensibleTarget be ? IsExtensible(target). |
8407 Maybe<bool> maybe_extensible = JSReceiver::IsExtensible(target); | 8489 Maybe<bool> maybe_extensible = JSReceiver::IsExtensible(target); |
8408 if (maybe_extensible.IsNothing()) return false; | 8490 if (maybe_extensible.IsNothing()) return false; |
8409 bool extensible_target = maybe_extensible.FromJust(); | 8491 bool extensible_target = maybe_extensible.FromJust(); |
8410 // 10. Let targetKeys be ? target.[[OwnPropertyKeys]](). | 8492 // 10. Let targetKeys be ? target.[[OwnPropertyKeys]](). |
8411 Handle<FixedArray> target_keys; | 8493 Handle<FixedArray> target_keys; |
8412 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 8494 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, target_keys, |
8413 isolate, target_keys, | 8495 JSReceiver::OwnPropertyKeys(target), false); |
8414 JSReceiver::GetKeys(target, JSReceiver::OWN_ONLY, ALL_PROPERTIES, | |
8415 CONVERT_TO_STRING), | |
8416 false); | |
8417 // 11. (Assert) | 8496 // 11. (Assert) |
8418 // 12. Let targetConfigurableKeys be an empty List. | 8497 // 12. Let targetConfigurableKeys be an empty List. |
8419 // To save memory, we're re-using target_keys and will modify it in-place. | 8498 // To save memory, we're re-using target_keys and will modify it in-place. |
8420 Handle<FixedArray> target_configurable_keys = target_keys; | 8499 Handle<FixedArray> target_configurable_keys = target_keys; |
8421 // 13. Let targetNonconfigurableKeys be an empty List. | 8500 // 13. Let targetNonconfigurableKeys be an empty List. |
8422 Handle<FixedArray> target_nonconfigurable_keys = | 8501 Handle<FixedArray> target_nonconfigurable_keys = |
8423 isolate->factory()->NewFixedArray(target_keys->length()); | 8502 isolate->factory()->NewFixedArray(target_keys->length()); |
8424 int nonconfigurable_keys_length = 0; | 8503 int nonconfigurable_keys_length = 0; |
8425 // 14. Repeat, for each element key of targetKeys: | 8504 // 14. Repeat, for each element key of targetKeys: |
8426 for (int i = 0; i < target_keys->length(); ++i) { | 8505 for (int i = 0; i < target_keys->length(); ++i) { |
(...skipping 10620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19047 if (cell->value() != *new_value) { | 19126 if (cell->value() != *new_value) { |
19048 cell->set_value(*new_value); | 19127 cell->set_value(*new_value); |
19049 Isolate* isolate = cell->GetIsolate(); | 19128 Isolate* isolate = cell->GetIsolate(); |
19050 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 19129 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
19051 isolate, DependentCode::kPropertyCellChangedGroup); | 19130 isolate, DependentCode::kPropertyCellChangedGroup); |
19052 } | 19131 } |
19053 } | 19132 } |
19054 | 19133 |
19055 } // namespace internal | 19134 } // namespace internal |
19056 } // namespace v8 | 19135 } // namespace v8 |
OLD | NEW |