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

Unified Diff: src/objects.cc

Issue 1502983002: [proxies] Make Object.{isFrozen,isSealed} behave correctly for proxies. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index e1cd390d7bc612c9a0cadcc166f79f1cad4a32cd..e916111e1662e37dd66ec7c29e852ae095db34b0 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -7233,6 +7233,102 @@ bool JSObject::ReferencesObject(Object* obj) {
}
+Maybe<bool> JSReceiver::SetIntegrityLevel(Handle<JSReceiver> receiver,
+ IntegrityLevel level,
+ ShouldThrow should_throw) {
+ DCHECK(level == SEALED || level == FROZEN);
+
+ if (receiver->IsJSObject()) {
+ Handle<JSObject> object = Handle<JSObject>::cast(receiver);
+ if (!object->HasSloppyArgumentsElements() &&
+ !object->map()->is_observed() &&
+ (!object->map()->is_strong() || level == SEALED)) { // Fast path.
+ if (level == SEALED) {
+ return JSObject::PreventExtensionsWithTransition<SEALED>(object,
+ should_throw);
+ } else {
+ return JSObject::PreventExtensionsWithTransition<FROZEN>(object,
+ should_throw);
+ }
+ }
+ }
+
+ Isolate* isolate = receiver->GetIsolate();
+
+ MAYBE_RETURN(JSReceiver::PreventExtensions(receiver, should_throw),
+ Nothing<bool>());
+
+ Handle<FixedArray> keys;
+ ASSIGN_RETURN_ON_EXCEPTION_VALUE(
+ isolate, keys, JSReceiver::OwnPropertyKeys(receiver), Nothing<bool>());
+
+ PropertyDescriptor no_conf;
+ no_conf.set_configurable(false);
+
+ PropertyDescriptor no_conf_no_write;
+ no_conf_no_write.set_configurable(false);
+ no_conf_no_write.set_writable(false);
+
+ if (level == SEALED) {
+ for (int i = 0; i < keys->length(); ++i) {
+ Handle<Object> key(keys->get(i), isolate);
+ DefineOwnProperty(isolate, receiver, key, &no_conf, THROW_ON_ERROR);
+ if (isolate->has_pending_exception()) return Nothing<bool>();
+ }
+ return Just(true);
+ }
+
+ for (int i = 0; i < keys->length(); ++i) {
+ Handle<Object> key(keys->get(i), isolate);
+ PropertyDescriptor current_desc;
+ bool owned = JSReceiver::GetOwnPropertyDescriptor(isolate, receiver, key,
+ &current_desc);
+ if (isolate->has_pending_exception()) return Nothing<bool>();
+ if (owned) {
+ PropertyDescriptor desc =
+ PropertyDescriptor::IsAccessorDescriptor(&current_desc)
+ ? no_conf
+ : no_conf_no_write;
+ DefineOwnProperty(isolate, receiver, key, &desc, THROW_ON_ERROR);
+ if (isolate->has_pending_exception()) return Nothing<bool>();
+ }
+ }
+ return Just(true);
+}
+
+
+Maybe<bool> JSReceiver::TestIntegrityLevel(Handle<JSReceiver> object,
+ IntegrityLevel level) {
+ DCHECK(level == SEALED || level == FROZEN);
+ Isolate* isolate = object->GetIsolate();
+
+ Maybe<bool> extensible = JSReceiver::IsExtensible(object);
+ MAYBE_RETURN(extensible, Nothing<bool>());
+ if (extensible.FromJust()) return Just(false);
+
+ Handle<FixedArray> keys;
+ ASSIGN_RETURN_ON_EXCEPTION_VALUE(
+ isolate, keys, JSReceiver::OwnPropertyKeys(object), Nothing<bool>());
+
+ for (int i = 0; i < keys->length(); ++i) {
+ Handle<Object> key(keys->get(i), isolate);
+ PropertyDescriptor current_desc;
+ bool owned = JSReceiver::GetOwnPropertyDescriptor(isolate, object, key,
+ &current_desc);
+ if (isolate->has_pending_exception()) return Nothing<bool>();
+ if (owned) {
+ if (current_desc.configurable()) return Just(false);
+ if (level == FROZEN &&
+ PropertyDescriptor::IsDataDescriptor(&current_desc) &&
+ current_desc.writable()) {
+ return Just(false);
+ }
+ }
+ }
+ return Just(true);
+}
+
+
Maybe<bool> JSReceiver::PreventExtensions(Handle<JSReceiver> object,
ShouldThrow should_throw) {
if (object->IsJSProxy()) {
@@ -7555,20 +7651,6 @@ Maybe<bool> JSObject::PreventExtensionsWithTransition(
}
-MaybeHandle<Object> JSObject::Freeze(Handle<JSObject> object) {
- MAYBE_RETURN_NULL(
- PreventExtensionsWithTransition<FROZEN>(object, THROW_ON_ERROR));
- return object;
-}
-
-
-MaybeHandle<Object> JSObject::Seal(Handle<JSObject> object) {
- MAYBE_RETURN_NULL(
- PreventExtensionsWithTransition<SEALED>(object, THROW_ON_ERROR));
- return object;
-}
-
-
void JSObject::SetObserved(Handle<JSObject> object) {
DCHECK(!object->IsJSGlobalProxy());
DCHECK(!object->IsJSGlobalObject());
@@ -8409,11 +8491,8 @@ bool JSProxy::OwnPropertyKeys(Isolate* isolate, Handle<JSReceiver> receiver,
bool extensible_target = maybe_extensible.FromJust();
// 10. Let targetKeys be ? target.[[OwnPropertyKeys]]().
Handle<FixedArray> target_keys;
- ASSIGN_RETURN_ON_EXCEPTION_VALUE(
- isolate, target_keys,
- JSReceiver::GetKeys(target, JSReceiver::OWN_ONLY, ALL_PROPERTIES,
- CONVERT_TO_STRING),
- false);
+ ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, target_keys,
+ JSReceiver::OwnPropertyKeys(target), false);
// 11. (Assert)
// 12. Let targetConfigurableKeys be an empty List.
// To save memory, we're re-using target_keys and will modify it in-place.
« no previous file with comments | « src/objects.h ('k') | src/runtime/runtime.h » ('j') | test/mjsunit/harmony/proxies-integrity.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698