Commit 2268defb authored by rafaelw@chromium.org's avatar rafaelw@chromium.org

Handlify JSObject::SetObserved

BUG=
R=mstarzinger@chromium.org

Review URL: https://codereview.chromium.org/27070002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17224 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5b9f8f32
......@@ -5581,37 +5581,34 @@ Handle<Object> JSObject::Freeze(Handle<JSObject> object) {
}
MUST_USE_RESULT MaybeObject* JSObject::SetObserved(Isolate* isolate) {
if (map()->is_observed())
return isolate->heap()->undefined_value();
void JSObject::SetObserved(Handle<JSObject> object) {
Isolate* isolate = object->GetIsolate();
Heap* heap = isolate->heap();
if (object->map()->is_observed())
return;
if (!HasExternalArrayElements()) {
if (!object->HasExternalArrayElements()) {
// Go to dictionary mode, so that we don't skip map checks.
MaybeObject* maybe = NormalizeElements();
if (maybe->IsFailure()) return maybe;
ASSERT(!HasFastElements());
NormalizeElements(object);
ASSERT(!object->HasFastElements());
}
LookupResult result(isolate);
map()->LookupTransition(this, heap->observed_symbol(), &result);
object->map()->LookupTransition(*object,
isolate->heap()->observed_symbol(),
&result);
Map* new_map;
Handle<Map> new_map;
if (result.IsTransition()) {
new_map = result.GetTransitionTarget();
new_map = handle(result.GetTransitionTarget());
ASSERT(new_map->is_observed());
} else if (map()->CanHaveMoreTransitions()) {
MaybeObject* maybe_new_map = map()->CopyForObserved();
if (!maybe_new_map->To(&new_map)) return maybe_new_map;
} else if (object->map()->CanHaveMoreTransitions()) {
new_map = Map::CopyForObserved(handle(object->map()));
} else {
MaybeObject* maybe_copy = map()->Copy();
if (!maybe_copy->To(&new_map)) return maybe_copy;
new_map = Map::Copy(handle(object->map()));
new_map->set_is_observed(true);
}
set_map(new_map);
return heap->undefined_value();
object->set_map(*new_map);
}
......@@ -6839,6 +6836,13 @@ MaybeObject* Map::CopyAsElementsKind(ElementsKind kind, TransitionFlag flag) {
}
Handle<Map> Map::CopyForObserved(Handle<Map> map) {
CALL_HEAP_FUNCTION(map->GetIsolate(),
map->CopyForObserved(),
Map);
}
MaybeObject* Map::CopyForObserved() {
ASSERT(!is_observed());
......
......@@ -2541,7 +2541,7 @@ class JSObject: public JSReceiver {
static Handle<Object> Freeze(Handle<JSObject> object);
// Called the first time an object is observed with ES7 Object.observe.
MUST_USE_RESULT MaybeObject* SetObserved(Isolate* isolate);
static void SetObserved(Handle<JSObject> object);
// Copy object.
static Handle<JSObject> Copy(Handle<JSObject> object);
......@@ -5977,6 +5977,8 @@ class Map: public HeapObject {
MUST_USE_RESULT MaybeObject* CopyAsElementsKind(ElementsKind kind,
TransitionFlag flag);
static Handle<Map> CopyForObserved(Handle<Map> map);
MUST_USE_RESULT MaybeObject* CopyForObserved();
static Handle<Map> CopyNormalized(Handle<Map> map,
......
......@@ -14566,22 +14566,23 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_IsObserved) {
RUNTIME_FUNCTION(MaybeObject*, Runtime_SetIsObserved) {
SealHandleScope shs(isolate);
HandleScope scope(isolate);
ASSERT(args.length() == 1);
CONVERT_ARG_CHECKED(JSReceiver, obj, 0);
CONVERT_ARG_HANDLE_CHECKED(JSReceiver, obj, 0);
if (obj->IsJSGlobalProxy()) {
Object* proto = obj->GetPrototype();
if (proto->IsNull()) return isolate->heap()->undefined_value();
ASSERT(proto->IsJSGlobalObject());
obj = JSReceiver::cast(proto);
obj = handle(JSReceiver::cast(proto));
}
if (obj->IsJSProxy())
return isolate->heap()->undefined_value();
ASSERT(!(obj->map()->is_observed() && obj->IsJSObject() &&
JSObject::cast(obj)->HasFastElements()));
Handle<JSObject>::cast(obj)->HasFastElements()));
ASSERT(obj->IsJSObject());
return JSObject::cast(obj)->SetObserved(isolate);
JSObject::SetObserved(Handle<JSObject>::cast(obj));
return isolate->heap()->undefined_value();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment