From d87c0679dd2f309f98a36daf623586542161f258 Mon Sep 17 00:00:00 2001 From: "mstarzinger@chromium.org" Date: Fri, 20 Sep 2013 12:54:02 +0000 Subject: [PATCH] Hanldify JSObject::PreventExtensions method. R=ulan@chromium.org Review URL: https://codereview.chromium.org/24200005 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16866 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/objects.cc | 51 +++++++++++++++++++++------------------------------ src/objects.h | 1 - src/runtime.cc | 11 ++++++----- 3 files changed, 27 insertions(+), 36 deletions(-) diff --git a/src/objects.cc b/src/objects.cc index f45dd4c..66d847a 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -5322,59 +5322,50 @@ bool JSObject::ReferencesObject(Object* obj) { Handle JSObject::PreventExtensions(Handle object) { - CALL_HEAP_FUNCTION(object->GetIsolate(), object->PreventExtensions(), Object); -} - - -MaybeObject* JSObject::PreventExtensions() { - Isolate* isolate = GetIsolate(); - if (IsAccessCheckNeeded() && - !isolate->MayNamedAccess(this, + Isolate* isolate = object->GetIsolate(); + if (object->IsAccessCheckNeeded() && + !isolate->MayNamedAccess(*object, isolate->heap()->undefined_value(), v8::ACCESS_KEYS)) { - isolate->ReportFailedAccessCheck(this, v8::ACCESS_KEYS); - RETURN_IF_SCHEDULED_EXCEPTION(isolate); - return isolate->heap()->false_value(); + isolate->ReportFailedAccessCheck(*object, v8::ACCESS_KEYS); + RETURN_HANDLE_IF_SCHEDULED_EXCEPTION(isolate, Object); + return isolate->factory()->false_value(); } - if (IsJSGlobalProxy()) { - Object* proto = GetPrototype(); - if (proto->IsNull()) return this; + if (object->IsJSGlobalProxy()) { + Handle proto(object->GetPrototype(), isolate); + if (proto->IsNull()) return object; ASSERT(proto->IsJSGlobalObject()); - return JSObject::cast(proto)->PreventExtensions(); + return PreventExtensions(Handle::cast(proto)); } // It's not possible to seal objects with external array elements - if (HasExternalArrayElements()) { - HandleScope scope(isolate); - Handle object(this, isolate); + if (object->HasExternalArrayElements()) { Handle error = isolate->factory()->NewTypeError( "cant_prevent_ext_external_array_elements", HandleVector(&object, 1)); - return isolate->Throw(*error); + isolate->Throw(*error); + return Handle(); } // If there are fast elements we normalize. - SeededNumberDictionary* dictionary = NULL; - { MaybeObject* maybe = NormalizeElements(); - if (!maybe->To(&dictionary)) return maybe; - } - ASSERT(HasDictionaryElements() || HasDictionaryArgumentsElements()); + Handle dictionary = NormalizeElements(object); + ASSERT(object->HasDictionaryElements() || + object->HasDictionaryArgumentsElements()); + // Make sure that we never go back to fast case. dictionary->set_requires_slow_elements(); // Do a map transition, other objects with this map may still // be extensible. // TODO(adamk): Extend the NormalizedMapCache to handle non-extensible maps. - Map* new_map; - MaybeObject* maybe = map()->Copy(); - if (!maybe->To(&new_map)) return maybe; + Handle new_map = Map::Copy(handle(object->map())); new_map->set_is_extensible(false); - set_map(new_map); - ASSERT(!map()->is_extensible()); - return new_map; + object->set_map(*new_map); + ASSERT(!object->map()->is_extensible()); + return object; } diff --git a/src/objects.h b/src/objects.h index 4c099fd..faddc0a 100644 --- a/src/objects.h +++ b/src/objects.h @@ -2531,7 +2531,6 @@ class JSObject: public JSReceiver { // Disalow further properties to be added to the object. static Handle PreventExtensions(Handle object); - MUST_USE_RESULT MaybeObject* PreventExtensions(); // ES5 Object.freeze static Handle Freeze(Handle object); diff --git a/src/runtime.cc b/src/runtime.cc index 047c8d8..1926eda 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -1825,10 +1825,12 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_GetOwnProperty) { RUNTIME_FUNCTION(MaybeObject*, Runtime_PreventExtensions) { - SealHandleScope shs(isolate); + HandleScope scope(isolate); ASSERT(args.length() == 1); - CONVERT_ARG_CHECKED(JSObject, obj, 0); - return obj->PreventExtensions(); + CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); + Handle result = JSObject::PreventExtensions(obj); + RETURN_IF_EMPTY_HANDLE(isolate, result); + return *result; } @@ -1852,8 +1854,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_RegExpCompile) { CONVERT_ARG_HANDLE_CHECKED(JSRegExp, re, 0); CONVERT_ARG_HANDLE_CHECKED(String, pattern, 1); CONVERT_ARG_HANDLE_CHECKED(String, flags, 2); - Handle result = - RegExpImpl::Compile(re, pattern, flags); + Handle result = RegExpImpl::Compile(re, pattern, flags); RETURN_IF_EMPTY_HANDLE(isolate, result); return *result; } -- 2.7.4