Convert function.prototype to API-style accessor.

R=yangguo@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20926 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
ulan@chromium.org 2014-04-24 08:35:53 +00:00
parent e493dc9ca9
commit ec613e229d
3 changed files with 48 additions and 47 deletions

View File

@ -797,16 +797,10 @@ static Handle<Object> GetFunctionPrototype(Isolate* isolate,
}
Handle<Object> Accessors::FunctionGetPrototype(Handle<JSFunction> function) {
return GetFunctionPrototype(function->GetIsolate(), function);
}
MaybeHandle<Object> SetFunctionPrototype(Isolate* isolate,
Handle<JSObject> receiver,
Handle<Object> value) {
Handle<JSFunction> function;
static Handle<Object> SetFunctionPrototype(Isolate* isolate,
Handle<JSObject> receiver,
Handle<Object> value) {
Handle<JSFunction> function;
{
DisallowHeapAllocation no_allocation;
JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, *receiver);
@ -816,8 +810,10 @@ MaybeHandle<Object> SetFunctionPrototype(Isolate* isolate,
if (!function->should_have_prototype()) {
// Since we hit this accessor, object will have no prototype property.
return JSObject::SetLocalPropertyIgnoreAttributes(
receiver, isolate->factory()->prototype_string(), value, NONE);
MaybeHandle<Object> maybe_result =
JSObject::SetLocalPropertyIgnoreAttributes(
receiver, isolate->factory()->prototype_string(), value, NONE);
return maybe_result.ToHandleChecked();
}
Handle<Object> old_value;
@ -841,43 +837,51 @@ MaybeHandle<Object> SetFunctionPrototype(Isolate* isolate,
}
Handle<Object> Accessors::FunctionGetPrototype(Handle<JSFunction> function) {
return GetFunctionPrototype(function->GetIsolate(), 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;
return SetFunctionPrototype(isolate, function, prototype);
}
Object* Accessors::FunctionGetPrototype(Isolate* isolate,
Object* object,
void*) {
void Accessors::FunctionPrototypeGetter(
v8::Local<v8::String> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
HandleScope scope(isolate);
return *GetFunctionPrototype(isolate, Handle<Object>(object, isolate));
Handle<Object> object = Utils::OpenHandle(*info.This());
Handle<Object> result = GetFunctionPrototype(isolate, object);
info.GetReturnValue().Set(Utils::ToLocal(result));
}
Object* 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;
void Accessors::FunctionPrototypeSetter(
v8::Local<v8::String> name,
v8::Local<v8::Value> val,
const v8::PropertyCallbackInfo<void>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
HandleScope scope(isolate);
Handle<JSObject> object = Utils::OpenHandle(*info.This());
Handle<Object> value = Utils::OpenHandle(*val);
SetFunctionPrototype(isolate, object, value);
}
const AccessorDescriptor Accessors::FunctionPrototype = {
FunctionGetPrototype,
FunctionSetPrototype,
0
};
Handle<AccessorInfo> Accessors::FunctionPrototypeInfo(
Isolate* isolate, PropertyAttributes attributes) {
return MakeAccessor(isolate,
isolate->factory()->prototype_string(),
&FunctionPrototypeGetter,
&FunctionPrototypeSetter,
attributes);
}
//

View File

@ -37,7 +37,6 @@ namespace internal {
// The list of accessor descriptors. This is a second-order macro
// taking a macro to be applied to all accessor descriptor names.
#define ACCESSOR_DESCRIPTOR_LIST(V) \
V(FunctionPrototype) \
V(FunctionLength) \
V(FunctionName) \
V(FunctionArguments) \
@ -45,6 +44,7 @@ namespace internal {
V(ArrayLength)
#define ACCESSOR_INFO_LIST(V) \
V(FunctionPrototype) \
V(ScriptColumnOffset) \
V(ScriptCompilationType) \
V(ScriptContextData) \

View File

@ -392,10 +392,6 @@ void Genesis::SetFunctionInstanceDescriptor(
Handle<Foreign> name(factory()->NewForeign(&Accessors::FunctionName));
Handle<Foreign> args(factory()->NewForeign(&Accessors::FunctionArguments));
Handle<Foreign> caller(factory()->NewForeign(&Accessors::FunctionCaller));
Handle<Foreign> prototype;
if (prototypeMode != DONT_ADD_PROTOTYPE) {
prototype = factory()->NewForeign(&Accessors::FunctionPrototype);
}
PropertyAttributes attribs = static_cast<PropertyAttributes>(
DONT_ENUM | DONT_DELETE | READ_ONLY);
@ -416,11 +412,13 @@ void Genesis::SetFunctionInstanceDescriptor(
map->AppendDescriptor(&d);
}
if (prototypeMode != DONT_ADD_PROTOTYPE) {
// Add prototype.
if (prototypeMode == ADD_WRITEABLE_PROTOTYPE) {
attribs = static_cast<PropertyAttributes>(attribs & ~READ_ONLY);
}
CallbacksDescriptor d(factory()->prototype_string(), prototype, attribs);
Handle<AccessorInfo> prototype =
Accessors::FunctionPrototypeInfo(isolate(), attribs);
CallbacksDescriptor d(Handle<Name>(Name::cast(prototype->name())),
prototype, attribs);
map->AppendDescriptor(&d);
}
}
@ -523,10 +521,6 @@ void Genesis::SetStrictFunctionInstanceDescriptor(
Handle<Foreign> name(factory()->NewForeign(&Accessors::FunctionName));
Handle<AccessorPair> arguments(factory()->NewAccessorPair());
Handle<AccessorPair> caller(factory()->NewAccessorPair());
Handle<Foreign> prototype;
if (prototypeMode != DONT_ADD_PROTOTYPE) {
prototype = factory()->NewForeign(&Accessors::FunctionPrototype);
}
PropertyAttributes rw_attribs =
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE);
PropertyAttributes ro_attribs =
@ -553,7 +547,10 @@ void Genesis::SetStrictFunctionInstanceDescriptor(
// Add prototype.
PropertyAttributes attribs =
prototypeMode == ADD_WRITEABLE_PROTOTYPE ? rw_attribs : ro_attribs;
CallbacksDescriptor d(factory()->prototype_string(), prototype, attribs);
Handle<AccessorInfo> prototype =
Accessors::FunctionPrototypeInfo(isolate(), attribs);
CallbacksDescriptor d(Handle<Name>(Name::cast(prototype->name())),
prototype, attribs);
map->AppendDescriptor(&d);
}
}