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) {
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<Object> proto(object->GetPrototype(), isolate);
if (proto->IsNull()) return object;
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
if (HasExternalArrayElements()) {
HandleScope scope(isolate);
Handle<Object> object(this, isolate);
if (object->HasExternalArrayElements()) {
Handle<Object> error =
isolate->factory()->NewTypeError(
"cant_prevent_ext_external_array_elements",
HandleVector(&object, 1));
return isolate->Throw(*error);
isolate->Throw(*error);
return Handle<Object>();
}
// If there are fast elements we normalize.
SeededNumberDictionary* dictionary = NULL;
{ MaybeObject* maybe = NormalizeElements();
if (!maybe->To<SeededNumberDictionary>(&dictionary)) return maybe;
}
ASSERT(HasDictionaryElements() || HasDictionaryArgumentsElements());
Handle<SeededNumberDictionary> 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<Map> 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;
}

View File

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

View File

@ -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<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(String, pattern, 1);
CONVERT_ARG_HANDLE_CHECKED(String, flags, 2);
Handle<Object> result =
RegExpImpl::Compile(re, pattern, flags);
Handle<Object> result = RegExpImpl::Compile(re, pattern, flags);
RETURN_IF_EMPTY_HANDLE(isolate, result);
return *result;
}