Handlify function.prototype accessor.

BUG=
R=yangguo@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20833 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
ulan@chromium.org 2014-04-17 09:12:19 +00:00
parent 0c614e2b48
commit 494d014798

View File

@ -773,74 +773,55 @@ Handle<AccessorInfo> Accessors::ScriptEvalFromFunctionNameInfo(
// Accessors::FunctionPrototype // Accessors::FunctionPrototype
// //
static Handle<Object> GetFunctionPrototype(Isolate* isolate,
Handle<Object> Accessors::FunctionGetPrototype(Handle<JSFunction> function) { Handle<Object> receiver) {
CALL_HEAP_FUNCTION(function->GetIsolate(), Handle<JSFunction> function;
Accessors::FunctionGetPrototype(function->GetIsolate(), {
*function, DisallowHeapAllocation no_allocation;
NULL), JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, *receiver);
Object); if (function_raw == NULL) return isolate->factory()->undefined_value();
} while (!function_raw->should_have_prototype()) {
function_raw = FindInstanceOf<JSFunction>(isolate,
function_raw->GetPrototype());
Handle<Object> Accessors::FunctionSetPrototype(Handle<JSFunction> function, // There has to be one because we hit the getter.
Handle<Object> prototype) { ASSERT(function_raw != NULL);
ASSERT(function->should_have_prototype()); }
CALL_HEAP_FUNCTION(function->GetIsolate(), function = Handle<JSFunction>(function_raw, isolate);
Accessors::FunctionSetPrototype(function->GetIsolate(),
*function,
*prototype,
NULL),
Object);
}
MaybeObject* Accessors::FunctionGetPrototype(Isolate* isolate,
Object* object,
void*) {
JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, object);
if (function_raw == NULL) return isolate->heap()->undefined_value();
while (!function_raw->should_have_prototype()) {
function_raw = FindInstanceOf<JSFunction>(isolate,
function_raw->GetPrototype());
// There has to be one because we hit the getter.
ASSERT(function_raw != NULL);
} }
if (!function_raw->has_prototype()) { if (!function->has_prototype()) {
HandleScope scope(isolate);
Handle<JSFunction> function(function_raw);
Handle<Object> proto = isolate->factory()->NewFunctionPrototype(function); Handle<Object> proto = isolate->factory()->NewFunctionPrototype(function);
JSFunction::SetPrototype(function, proto); JSFunction::SetPrototype(function, proto);
function_raw = *function;
} }
return function_raw->prototype(); return Handle<Object>(function->prototype(), isolate);
} }
MaybeObject* Accessors::FunctionSetPrototype(Isolate* isolate, Handle<Object> Accessors::FunctionGetPrototype(Handle<JSFunction> function) {
JSObject* object_raw, return GetFunctionPrototype(function->GetIsolate(), function);
Object* value_raw, }
void*) {
JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, object_raw);
if (function_raw == NULL) return isolate->heap()->undefined_value();
MaybeHandle<Object> SetFunctionPrototype(Isolate* isolate,
Handle<JSObject> receiver,
Handle<Object> value) {
Handle<JSFunction> function;
{
DisallowHeapAllocation no_allocation;
JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, *receiver);
if (function_raw == NULL) return isolate->factory()->undefined_value();
function = Handle<JSFunction>(function_raw, isolate);
}
HandleScope scope(isolate);
Handle<JSFunction> function(function_raw, isolate);
Handle<JSObject> object(object_raw, isolate);
Handle<Object> value(value_raw, isolate);
if (!function->should_have_prototype()) { if (!function->should_have_prototype()) {
// Since we hit this accessor, object will have no prototype property. // Since we hit this accessor, object will have no prototype property.
Handle<Object> result; return JSObject::SetLocalPropertyIgnoreAttributes(
ASSIGN_RETURN_FAILURE_ON_EXCEPTION( receiver, isolate->factory()->prototype_string(), value, NONE);
isolate, result,
JSObject::SetLocalPropertyIgnoreAttributes(
object, isolate->factory()->prototype_string(), value, NONE));
return *result;
} }
Handle<Object> old_value; Handle<Object> old_value;
bool is_observed = *function == *object && function->map()->is_observed(); bool is_observed = *function == *receiver && function->map()->is_observed();
if (is_observed) { if (is_observed) {
if (function->has_prototype()) if (function->has_prototype())
old_value = handle(function->prototype(), isolate); old_value = handle(function->prototype(), isolate);
@ -856,7 +837,39 @@ MaybeObject* Accessors::FunctionSetPrototype(Isolate* isolate,
function, "update", isolate->factory()->prototype_string(), old_value); function, "update", isolate->factory()->prototype_string(), old_value);
} }
return *function; return function;
}
Handle<Object> Accessors::FunctionSetPrototype(Handle<JSFunction> function,
Handle<Object> prototype) {
ASSERT(function->should_have_prototype());
Isolate* isolate = function->GetIsolate();
Handle<Object> result;
SetFunctionPrototype(isolate, function, prototype).ToHandle(&result);
return result;
}
MaybeObject* Accessors::FunctionGetPrototype(Isolate* isolate,
Object* object,
void*) {
HandleScope scope(isolate);
return *GetFunctionPrototype(isolate, Handle<Object>(object, isolate));
}
MaybeObject* Accessors::FunctionSetPrototype(Isolate* isolate,
JSObject* object,
Object* value,
void*) {
Handle<Object> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, result,
SetFunctionPrototype(isolate,
Handle<JSObject>(object, isolate),
Handle<Object>(value, isolate)));
return *result;
} }