From: ulan@chromium.org Date: Thu, 24 Apr 2014 08:35:53 +0000 (+0000) Subject: Convert function.prototype to API-style accessor. X-Git-Tag: upstream/4.7.83~9467 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ec613e229d3814bfe7f3810227ffe1af0535e9e4;p=platform%2Fupstream%2Fv8.git 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 --- diff --git a/src/accessors.cc b/src/accessors.cc index 96d3d35..aa09e3b 100644 --- a/src/accessors.cc +++ b/src/accessors.cc @@ -797,16 +797,10 @@ static Handle GetFunctionPrototype(Isolate* isolate, } -Handle Accessors::FunctionGetPrototype(Handle function) { - return GetFunctionPrototype(function->GetIsolate(), function); -} - - - -MaybeHandle SetFunctionPrototype(Isolate* isolate, - Handle receiver, - Handle value) { - Handle function; +static Handle SetFunctionPrototype(Isolate* isolate, + Handle receiver, + Handle value) { + Handle function; { DisallowHeapAllocation no_allocation; JSFunction* function_raw = FindInstanceOf(isolate, *receiver); @@ -816,8 +810,10 @@ MaybeHandle 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 maybe_result = + JSObject::SetLocalPropertyIgnoreAttributes( + receiver, isolate->factory()->prototype_string(), value, NONE); + return maybe_result.ToHandleChecked(); } Handle old_value; @@ -841,43 +837,51 @@ MaybeHandle SetFunctionPrototype(Isolate* isolate, } +Handle Accessors::FunctionGetPrototype(Handle function) { + return GetFunctionPrototype(function->GetIsolate(), function); +} + + Handle Accessors::FunctionSetPrototype(Handle function, Handle prototype) { ASSERT(function->should_have_prototype()); Isolate* isolate = function->GetIsolate(); - Handle 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 name, + const v8::PropertyCallbackInfo& info) { + i::Isolate* isolate = reinterpret_cast(info.GetIsolate()); HandleScope scope(isolate); - return *GetFunctionPrototype(isolate, Handle(object, isolate)); + Handle object = Utils::OpenHandle(*info.This()); + Handle result = GetFunctionPrototype(isolate, object); + info.GetReturnValue().Set(Utils::ToLocal(result)); } -Object* Accessors::FunctionSetPrototype(Isolate* isolate, - JSObject* object, - Object* value, - void*) { - Handle result; - ASSIGN_RETURN_FAILURE_ON_EXCEPTION( - isolate, result, - SetFunctionPrototype(isolate, - Handle(object, isolate), - Handle(value, isolate))); - return *result; +void Accessors::FunctionPrototypeSetter( + v8::Local name, + v8::Local val, + const v8::PropertyCallbackInfo& info) { + i::Isolate* isolate = reinterpret_cast(info.GetIsolate()); + HandleScope scope(isolate); + Handle object = Utils::OpenHandle(*info.This()); + Handle value = Utils::OpenHandle(*val); + + SetFunctionPrototype(isolate, object, value); } -const AccessorDescriptor Accessors::FunctionPrototype = { - FunctionGetPrototype, - FunctionSetPrototype, - 0 -}; +Handle Accessors::FunctionPrototypeInfo( + Isolate* isolate, PropertyAttributes attributes) { + return MakeAccessor(isolate, + isolate->factory()->prototype_string(), + &FunctionPrototypeGetter, + &FunctionPrototypeSetter, + attributes); +} // diff --git a/src/accessors.h b/src/accessors.h index a4452b7..fc9ccf4 100644 --- a/src/accessors.h +++ b/src/accessors.h @@ -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) \ diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index 6c6e6b3..5bfc3b7 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -392,10 +392,6 @@ void Genesis::SetFunctionInstanceDescriptor( Handle name(factory()->NewForeign(&Accessors::FunctionName)); Handle args(factory()->NewForeign(&Accessors::FunctionArguments)); Handle caller(factory()->NewForeign(&Accessors::FunctionCaller)); - Handle prototype; - if (prototypeMode != DONT_ADD_PROTOTYPE) { - prototype = factory()->NewForeign(&Accessors::FunctionPrototype); - } PropertyAttributes attribs = static_cast( 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(attribs & ~READ_ONLY); } - CallbacksDescriptor d(factory()->prototype_string(), prototype, attribs); + Handle prototype = + Accessors::FunctionPrototypeInfo(isolate(), attribs); + CallbacksDescriptor d(Handle(Name::cast(prototype->name())), + prototype, attribs); map->AppendDescriptor(&d); } } @@ -523,10 +521,6 @@ void Genesis::SetStrictFunctionInstanceDescriptor( Handle name(factory()->NewForeign(&Accessors::FunctionName)); Handle arguments(factory()->NewAccessorPair()); Handle caller(factory()->NewAccessorPair()); - Handle prototype; - if (prototypeMode != DONT_ADD_PROTOTYPE) { - prototype = factory()->NewForeign(&Accessors::FunctionPrototype); - } PropertyAttributes rw_attribs = static_cast(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 prototype = + Accessors::FunctionPrototypeInfo(isolate(), attribs); + CallbacksDescriptor d(Handle(Name::cast(prototype->name())), + prototype, attribs); map->AppendDescriptor(&d); } }