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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.h ('k') | src/runtime/runtime-classes.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 3904e6794d1da4817c514c44f101ff0ea6e5778d..66ff70ff8d5516dc67de3ccd70c1c865752c897a 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -7233,6 +7233,70 @@ 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::PreventExtensions(Handle<JSReceiver> object,
ShouldThrow should_throw) {
if (object->IsJSProxy()) {
@@ -7555,20 +7619,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());
@@ -8416,11 +8466,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-classes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698