Commit d603dc5c authored by neis's avatar neis Committed by Commit bot

Move some code from Runtime_SetPrototype to JSObject::SetPrototype.

This is in preparation of implementing Reflect.setPrototypeOf.

R=verwaest@chromium.org
BUG=

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

Cr-Commit-Position: refs/heads/master@{#31432}
parent 79634a3f
......@@ -13881,11 +13881,55 @@ Handle<Map> Map::TransitionToPrototype(Handle<Map> map,
MaybeHandle<Object> JSObject::SetPrototype(Handle<JSObject> object,
Handle<Object> value,
bool from_javascript) {
Isolate* isolate = object->GetIsolate();
const bool observed = from_javascript && object->map()->is_observed();
Handle<Object> old_value;
if (observed) {
old_value = Object::GetPrototypeSkipHiddenPrototypes(isolate, object);
}
Handle<Object> result;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, result, SetPrototypeUnobserved(object, value, from_javascript),
Object);
if (observed) {
Handle<Object> new_value =
Object::GetPrototypeSkipHiddenPrototypes(isolate, object);
if (!new_value->SameValue(*old_value)) {
RETURN_ON_EXCEPTION(isolate,
JSObject::EnqueueChangeRecord(
object, "setPrototype",
isolate->factory()->proto_string(), old_value),
Object);
}
}
return result;
}
MaybeHandle<Object> JSObject::SetPrototypeUnobserved(Handle<JSObject> object,
Handle<Object> value,
bool from_javascript) {
#ifdef DEBUG
int size = object->Size();
#endif
Isolate* isolate = object->GetIsolate();
if (from_javascript) {
if (object->IsAccessCheckNeeded() &&
!isolate->MayAccess(handle(isolate->context()), object)) {
isolate->ReportFailedAccessCheck(object);
RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object);
return isolate->factory()->undefined_value();
}
} else {
DCHECK(!object->IsAccessCheckNeeded());
}
// Strong objects may not have their prototype set via __proto__ or
// setPrototypeOf.
if (from_javascript && object->map()->is_strong()) {
......
......@@ -2521,6 +2521,9 @@ class JSObject: public JSReceiver {
MUST_USE_RESULT static Maybe<bool> PreventExtensionsWithTransition(
Handle<JSObject> object, ShouldThrow should_throw);
MUST_USE_RESULT static MaybeHandle<Object> SetPrototypeUnobserved(
Handle<JSObject> object, Handle<Object> value, bool from_javascript);
DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject);
};
......
......@@ -181,8 +181,6 @@ RUNTIME_FUNCTION(Runtime_InternalSetPrototype) {
DCHECK(args.length() == 2);
CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, prototype, 1);
DCHECK(!obj->IsAccessCheckNeeded());
DCHECK(!obj->map()->is_observed());
Handle<Object> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, result, JSObject::SetPrototype(obj, prototype, false));
......@@ -195,29 +193,6 @@ RUNTIME_FUNCTION(Runtime_SetPrototype) {
DCHECK(args.length() == 2);
CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, prototype, 1);
if (obj->IsAccessCheckNeeded() &&
!isolate->MayAccess(handle(isolate->context()), obj)) {
isolate->ReportFailedAccessCheck(obj);
RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate);
return isolate->heap()->undefined_value();
}
if (obj->map()->is_observed()) {
Handle<Object> old_value =
Object::GetPrototypeSkipHiddenPrototypes(isolate, obj);
Handle<Object> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, result, JSObject::SetPrototype(obj, prototype, true));
Handle<Object> new_value =
Object::GetPrototypeSkipHiddenPrototypes(isolate, obj);
if (!new_value->SameValue(*old_value)) {
RETURN_FAILURE_ON_EXCEPTION(
isolate, JSObject::EnqueueChangeRecord(
obj, "setPrototype", isolate->factory()->proto_string(),
old_value));
}
return *result;
}
Handle<Object> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, result, JSObject::SetPrototype(obj, prototype, true));
......
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