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
This commit is contained in:
mstarzinger@chromium.org 2013-09-20 12:54:02 +00:00
parent 94a0a95b7a
commit d87c0679dd
3 changed files with 27 additions and 36 deletions

View File

@ -5322,59 +5322,50 @@ bool JSObject::ReferencesObject(Object* obj) {
Handle<Object> JSObject::PreventExtensions(Handle<JSObject> object) { Handle<Object> JSObject::PreventExtensions(Handle<JSObject> object) {
CALL_HEAP_FUNCTION(object->GetIsolate(), object->PreventExtensions(), Object); Isolate* isolate = object->GetIsolate();
} if (object->IsAccessCheckNeeded() &&
!isolate->MayNamedAccess(*object,
MaybeObject* JSObject::PreventExtensions() {
Isolate* isolate = GetIsolate();
if (IsAccessCheckNeeded() &&
!isolate->MayNamedAccess(this,
isolate->heap()->undefined_value(), isolate->heap()->undefined_value(),
v8::ACCESS_KEYS)) { v8::ACCESS_KEYS)) {
isolate->ReportFailedAccessCheck(this, v8::ACCESS_KEYS); isolate->ReportFailedAccessCheck(*object, v8::ACCESS_KEYS);
RETURN_IF_SCHEDULED_EXCEPTION(isolate); RETURN_HANDLE_IF_SCHEDULED_EXCEPTION(isolate, Object);
return isolate->heap()->false_value(); return isolate->factory()->false_value();
} }
if (IsJSGlobalProxy()) { if (object->IsJSGlobalProxy()) {
Object* proto = GetPrototype(); Handle<Object> proto(object->GetPrototype(), isolate);
if (proto->IsNull()) return this; if (proto->IsNull()) return object;
ASSERT(proto->IsJSGlobalObject()); ASSERT(proto->IsJSGlobalObject());
return JSObject::cast(proto)->PreventExtensions(); return PreventExtensions(Handle<JSObject>::cast(proto));
} }
// It's not possible to seal objects with external array elements // It's not possible to seal objects with external array elements
if (HasExternalArrayElements()) { if (object->HasExternalArrayElements()) {
HandleScope scope(isolate);
Handle<Object> object(this, isolate);
Handle<Object> error = Handle<Object> error =
isolate->factory()->NewTypeError( isolate->factory()->NewTypeError(
"cant_prevent_ext_external_array_elements", "cant_prevent_ext_external_array_elements",
HandleVector(&object, 1)); HandleVector(&object, 1));
return isolate->Throw(*error); isolate->Throw(*error);
return Handle<Object>();
} }
// If there are fast elements we normalize. // If there are fast elements we normalize.
SeededNumberDictionary* dictionary = NULL; Handle<SeededNumberDictionary> dictionary = NormalizeElements(object);
{ MaybeObject* maybe = NormalizeElements(); ASSERT(object->HasDictionaryElements() ||
if (!maybe->To<SeededNumberDictionary>(&dictionary)) return maybe; object->HasDictionaryArgumentsElements());
}
ASSERT(HasDictionaryElements() || HasDictionaryArgumentsElements());
// Make sure that we never go back to fast case. // Make sure that we never go back to fast case.
dictionary->set_requires_slow_elements(); dictionary->set_requires_slow_elements();
// Do a map transition, other objects with this map may still // Do a map transition, other objects with this map may still
// be extensible. // be extensible.
// TODO(adamk): Extend the NormalizedMapCache to handle non-extensible maps. // TODO(adamk): Extend the NormalizedMapCache to handle non-extensible maps.
Map* new_map; Handle<Map> new_map = Map::Copy(handle(object->map()));
MaybeObject* maybe = map()->Copy();
if (!maybe->To(&new_map)) return maybe;
new_map->set_is_extensible(false); new_map->set_is_extensible(false);
set_map(new_map); object->set_map(*new_map);
ASSERT(!map()->is_extensible()); ASSERT(!object->map()->is_extensible());
return new_map; return object;
} }

View File

@ -2531,7 +2531,6 @@ class JSObject: public JSReceiver {
// Disalow further properties to be added to the object. // Disalow further properties to be added to the object.
static Handle<Object> PreventExtensions(Handle<JSObject> object); static Handle<Object> PreventExtensions(Handle<JSObject> object);
MUST_USE_RESULT MaybeObject* PreventExtensions();
// ES5 Object.freeze // ES5 Object.freeze
static Handle<Object> Freeze(Handle<JSObject> object); static Handle<Object> Freeze(Handle<JSObject> object);

View File

@ -1825,10 +1825,12 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_GetOwnProperty) {
RUNTIME_FUNCTION(MaybeObject*, Runtime_PreventExtensions) { RUNTIME_FUNCTION(MaybeObject*, Runtime_PreventExtensions) {
SealHandleScope shs(isolate); HandleScope scope(isolate);
ASSERT(args.length() == 1); ASSERT(args.length() == 1);
CONVERT_ARG_CHECKED(JSObject, obj, 0); CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0);
return obj->PreventExtensions(); Handle<Object> 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(JSRegExp, re, 0);
CONVERT_ARG_HANDLE_CHECKED(String, pattern, 1); CONVERT_ARG_HANDLE_CHECKED(String, pattern, 1);
CONVERT_ARG_HANDLE_CHECKED(String, flags, 2); CONVERT_ARG_HANDLE_CHECKED(String, flags, 2);
Handle<Object> result = Handle<Object> result = RegExpImpl::Compile(re, pattern, flags);
RegExpImpl::Compile(re, pattern, flags);
RETURN_IF_EMPTY_HANDLE(isolate, result); RETURN_IF_EMPTY_HANDLE(isolate, result);
return *result; return *result;
} }