Commit ec613e22 authored by ulan@chromium.org's avatar ulan@chromium.org

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
parent e493dc9c
...@@ -797,13 +797,7 @@ static Handle<Object> GetFunctionPrototype(Isolate* isolate, ...@@ -797,13 +797,7 @@ static Handle<Object> GetFunctionPrototype(Isolate* isolate,
} }
Handle<Object> Accessors::FunctionGetPrototype(Handle<JSFunction> function) { static Handle<Object> SetFunctionPrototype(Isolate* isolate,
return GetFunctionPrototype(function->GetIsolate(), function);
}
MaybeHandle<Object> SetFunctionPrototype(Isolate* isolate,
Handle<JSObject> receiver, Handle<JSObject> receiver,
Handle<Object> value) { Handle<Object> value) {
Handle<JSFunction> function; Handle<JSFunction> function;
...@@ -816,8 +810,10 @@ MaybeHandle<Object> SetFunctionPrototype(Isolate* isolate, ...@@ -816,8 +810,10 @@ MaybeHandle<Object> SetFunctionPrototype(Isolate* 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.
return JSObject::SetLocalPropertyIgnoreAttributes( MaybeHandle<Object> maybe_result =
JSObject::SetLocalPropertyIgnoreAttributes(
receiver, isolate->factory()->prototype_string(), value, NONE); receiver, isolate->factory()->prototype_string(), value, NONE);
return maybe_result.ToHandleChecked();
} }
Handle<Object> old_value; Handle<Object> old_value;
...@@ -841,43 +837,51 @@ MaybeHandle<Object> SetFunctionPrototype(Isolate* isolate, ...@@ -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> Accessors::FunctionSetPrototype(Handle<JSFunction> function,
Handle<Object> prototype) { Handle<Object> prototype) {
ASSERT(function->should_have_prototype()); ASSERT(function->should_have_prototype());
Isolate* isolate = function->GetIsolate(); Isolate* isolate = function->GetIsolate();
Handle<Object> result; return SetFunctionPrototype(isolate, function, prototype);
SetFunctionPrototype(isolate, function, prototype).ToHandle(&result);
return result;
} }
Object* Accessors::FunctionGetPrototype(Isolate* isolate, void Accessors::FunctionPrototypeGetter(
Object* object, v8::Local<v8::String> name,
void*) { const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
HandleScope scope(isolate); 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, void Accessors::FunctionPrototypeSetter(
JSObject* object, v8::Local<v8::String> name,
Object* value, v8::Local<v8::Value> val,
void*) { const v8::PropertyCallbackInfo<void>& info) {
Handle<Object> result; i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
ASSIGN_RETURN_FAILURE_ON_EXCEPTION( HandleScope scope(isolate);
isolate, result, Handle<JSObject> object = Utils::OpenHandle(*info.This());
SetFunctionPrototype(isolate, Handle<Object> value = Utils::OpenHandle(*val);
Handle<JSObject>(object, isolate),
Handle<Object>(value, isolate))); SetFunctionPrototype(isolate, object, value);
return *result;
} }
const AccessorDescriptor Accessors::FunctionPrototype = { Handle<AccessorInfo> Accessors::FunctionPrototypeInfo(
FunctionGetPrototype, Isolate* isolate, PropertyAttributes attributes) {
FunctionSetPrototype, return MakeAccessor(isolate,
0 isolate->factory()->prototype_string(),
}; &FunctionPrototypeGetter,
&FunctionPrototypeSetter,
attributes);
}
// //
......
...@@ -37,7 +37,6 @@ namespace internal { ...@@ -37,7 +37,6 @@ namespace internal {
// The list of accessor descriptors. This is a second-order macro // The list of accessor descriptors. This is a second-order macro
// taking a macro to be applied to all accessor descriptor names. // taking a macro to be applied to all accessor descriptor names.
#define ACCESSOR_DESCRIPTOR_LIST(V) \ #define ACCESSOR_DESCRIPTOR_LIST(V) \
V(FunctionPrototype) \
V(FunctionLength) \ V(FunctionLength) \
V(FunctionName) \ V(FunctionName) \
V(FunctionArguments) \ V(FunctionArguments) \
...@@ -45,6 +44,7 @@ namespace internal { ...@@ -45,6 +44,7 @@ namespace internal {
V(ArrayLength) V(ArrayLength)
#define ACCESSOR_INFO_LIST(V) \ #define ACCESSOR_INFO_LIST(V) \
V(FunctionPrototype) \
V(ScriptColumnOffset) \ V(ScriptColumnOffset) \
V(ScriptCompilationType) \ V(ScriptCompilationType) \
V(ScriptContextData) \ V(ScriptContextData) \
......
...@@ -392,10 +392,6 @@ void Genesis::SetFunctionInstanceDescriptor( ...@@ -392,10 +392,6 @@ void Genesis::SetFunctionInstanceDescriptor(
Handle<Foreign> name(factory()->NewForeign(&Accessors::FunctionName)); Handle<Foreign> name(factory()->NewForeign(&Accessors::FunctionName));
Handle<Foreign> args(factory()->NewForeign(&Accessors::FunctionArguments)); Handle<Foreign> args(factory()->NewForeign(&Accessors::FunctionArguments));
Handle<Foreign> caller(factory()->NewForeign(&Accessors::FunctionCaller)); 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>( PropertyAttributes attribs = static_cast<PropertyAttributes>(
DONT_ENUM | DONT_DELETE | READ_ONLY); DONT_ENUM | DONT_DELETE | READ_ONLY);
...@@ -416,11 +412,13 @@ void Genesis::SetFunctionInstanceDescriptor( ...@@ -416,11 +412,13 @@ void Genesis::SetFunctionInstanceDescriptor(
map->AppendDescriptor(&d); map->AppendDescriptor(&d);
} }
if (prototypeMode != DONT_ADD_PROTOTYPE) { if (prototypeMode != DONT_ADD_PROTOTYPE) {
// Add prototype.
if (prototypeMode == ADD_WRITEABLE_PROTOTYPE) { if (prototypeMode == ADD_WRITEABLE_PROTOTYPE) {
attribs = static_cast<PropertyAttributes>(attribs & ~READ_ONLY); 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); map->AppendDescriptor(&d);
} }
} }
...@@ -523,10 +521,6 @@ void Genesis::SetStrictFunctionInstanceDescriptor( ...@@ -523,10 +521,6 @@ void Genesis::SetStrictFunctionInstanceDescriptor(
Handle<Foreign> name(factory()->NewForeign(&Accessors::FunctionName)); Handle<Foreign> name(factory()->NewForeign(&Accessors::FunctionName));
Handle<AccessorPair> arguments(factory()->NewAccessorPair()); Handle<AccessorPair> arguments(factory()->NewAccessorPair());
Handle<AccessorPair> caller(factory()->NewAccessorPair()); Handle<AccessorPair> caller(factory()->NewAccessorPair());
Handle<Foreign> prototype;
if (prototypeMode != DONT_ADD_PROTOTYPE) {
prototype = factory()->NewForeign(&Accessors::FunctionPrototype);
}
PropertyAttributes rw_attribs = PropertyAttributes rw_attribs =
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE);
PropertyAttributes ro_attribs = PropertyAttributes ro_attribs =
...@@ -553,7 +547,10 @@ void Genesis::SetStrictFunctionInstanceDescriptor( ...@@ -553,7 +547,10 @@ void Genesis::SetStrictFunctionInstanceDescriptor(
// Add prototype. // Add prototype.
PropertyAttributes attribs = PropertyAttributes attribs =
prototypeMode == ADD_WRITEABLE_PROTOTYPE ? rw_attribs : ro_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); map->AppendDescriptor(&d);
} }
} }
......
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