From de5f609da43db3050605921fceac0021c648b33d Mon Sep 17 00:00:00 2001 From: "ulan@chromium.org" Date: Wed, 16 Apr 2014 11:57:23 +0000 Subject: [PATCH] Handlify and convert Script accesssors to new API-style accessors. BUG= R=yangguo@chromium.org Review URL: https://codereview.chromium.org/239223003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20799 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/accessors.cc | 192 +++++++++++++++++++++++++++++++++++++--------------- src/accessors.h | 20 ++---- src/bootstrapper.cc | 44 ++++++------ 3 files changed, 163 insertions(+), 93 deletions(-) diff --git a/src/accessors.cc b/src/accessors.cc index 18121ab..189393b 100644 --- a/src/accessors.cc +++ b/src/accessors.cc @@ -54,8 +54,7 @@ static Handle MakeAccessor(Isolate* isolate, info->set_all_can_read(true); info->set_all_can_write(true); info->set_prohibits_overwriting(false); - info->set_name(*factory->length_string()); - info->set_property_attributes(attributes); + info->set_name(*name); Handle get = v8::FromCData(isolate, getter); Handle set = v8::FromCData(isolate, setter); info->set_getter(*get); @@ -294,101 +293,184 @@ Handle Accessors::StringLengthInfo( // -// Accessors::ScriptSource +// Accessors::ScriptColumnOffset // -MaybeObject* Accessors::ScriptGetSource(Isolate* isolate, - Object* object, - void*) { - Object* script = JSValue::cast(object)->value(); - return Script::cast(script)->source(); +void Accessors::ScriptColumnOffsetGetter( + v8::Local name, + const v8::PropertyCallbackInfo& info) { + i::Isolate* isolate = reinterpret_cast(info.GetIsolate()); + DisallowHeapAllocation no_allocation; + HandleScope scope(isolate); + Object* object = *Utils::OpenHandle(*info.This()); + Object* res = Script::cast(JSValue::cast(object)->value())->column_offset(); + info.GetReturnValue().Set(Utils::ToLocal(Handle(res, isolate))); } -const AccessorDescriptor Accessors::ScriptSource = { - ScriptGetSource, - IllegalSetter, - 0 -}; +void Accessors::ScriptColumnOffsetSetter( + v8::Local name, + v8::Local value, + const v8::PropertyCallbackInfo& info) { + UNREACHABLE(); +} + + +Handle Accessors::ScriptColumnOffsetInfo( + Isolate* isolate, PropertyAttributes attributes) { + Handle name(isolate->factory()->InternalizeOneByteString( + STATIC_ASCII_VECTOR("column_offset"))); + return MakeAccessor(isolate, + name, + &ScriptColumnOffsetGetter, + &ScriptColumnOffsetSetter, + attributes); +} // -// Accessors::ScriptName +// Accessors::ScriptId // -MaybeObject* Accessors::ScriptGetName(Isolate* isolate, - Object* object, - void*) { - Object* script = JSValue::cast(object)->value(); - return Script::cast(script)->name(); +void Accessors::ScriptIdGetter( + v8::Local name, + const v8::PropertyCallbackInfo& info) { + i::Isolate* isolate = reinterpret_cast(info.GetIsolate()); + DisallowHeapAllocation no_allocation; + HandleScope scope(isolate); + Object* object = *Utils::OpenHandle(*info.This()); + Object* id = Script::cast(JSValue::cast(object)->value())->id(); + info.GetReturnValue().Set(Utils::ToLocal(Handle(id, isolate))); } -const AccessorDescriptor Accessors::ScriptName = { - ScriptGetName, - IllegalSetter, - 0 -}; +void Accessors::ScriptIdSetter( + v8::Local name, + v8::Local value, + const v8::PropertyCallbackInfo& info) { + UNREACHABLE(); +} + + +Handle Accessors::ScriptIdInfo( + Isolate* isolate, PropertyAttributes attributes) { + Handle name(isolate->factory()->InternalizeOneByteString( + STATIC_ASCII_VECTOR("id"))); + return MakeAccessor(isolate, + name, + &ScriptIdGetter, + &ScriptIdSetter, + attributes); +} // -// Accessors::ScriptId +// Accessors::ScriptName // -MaybeObject* Accessors::ScriptGetId(Isolate* isolate, Object* object, void*) { - Object* script = JSValue::cast(object)->value(); - return Script::cast(script)->id(); +void Accessors::ScriptNameGetter( + v8::Local name, + const v8::PropertyCallbackInfo& info) { + i::Isolate* isolate = reinterpret_cast(info.GetIsolate()); + DisallowHeapAllocation no_allocation; + HandleScope scope(isolate); + Object* object = *Utils::OpenHandle(*info.This()); + Object* source = Script::cast(JSValue::cast(object)->value())->name(); + info.GetReturnValue().Set(Utils::ToLocal(Handle(source, isolate))); } -const AccessorDescriptor Accessors::ScriptId = { - ScriptGetId, - IllegalSetter, - 0 -}; +void Accessors::ScriptNameSetter( + v8::Local name, + v8::Local value, + const v8::PropertyCallbackInfo& info) { + UNREACHABLE(); +} + + +Handle Accessors::ScriptNameInfo( + Isolate* isolate, PropertyAttributes attributes) { + return MakeAccessor(isolate, + isolate->factory()->name_string(), + &ScriptNameGetter, + &ScriptNameSetter, + attributes); +} // -// Accessors::ScriptLineOffset +// Accessors::ScriptSource // -MaybeObject* Accessors::ScriptGetLineOffset(Isolate* isolate, - Object* object, - void*) { - Object* script = JSValue::cast(object)->value(); - return Script::cast(script)->line_offset(); +void Accessors::ScriptSourceGetter( + v8::Local name, + const v8::PropertyCallbackInfo& info) { + i::Isolate* isolate = reinterpret_cast(info.GetIsolate()); + DisallowHeapAllocation no_allocation; + HandleScope scope(isolate); + Object* object = *Utils::OpenHandle(*info.This()); + Object* source = Script::cast(JSValue::cast(object)->value())->source(); + info.GetReturnValue().Set(Utils::ToLocal(Handle(source, isolate))); } -const AccessorDescriptor Accessors::ScriptLineOffset = { - ScriptGetLineOffset, - IllegalSetter, - 0 -}; +void Accessors::ScriptSourceSetter( + v8::Local name, + v8::Local value, + const v8::PropertyCallbackInfo& info) { + UNREACHABLE(); +} + + +Handle Accessors::ScriptSourceInfo( + Isolate* isolate, PropertyAttributes attributes) { + return MakeAccessor(isolate, + isolate->factory()->source_string(), + &ScriptSourceGetter, + &ScriptSourceSetter, + attributes); +} // -// Accessors::ScriptColumnOffset +// Accessors::ScriptLineOffset // -MaybeObject* Accessors::ScriptGetColumnOffset(Isolate* isolate, - Object* object, - void*) { - Object* script = JSValue::cast(object)->value(); - return Script::cast(script)->column_offset(); +void Accessors::ScriptLineOffsetGetter( + v8::Local name, + const v8::PropertyCallbackInfo& info) { + i::Isolate* isolate = reinterpret_cast(info.GetIsolate()); + DisallowHeapAllocation no_allocation; + HandleScope scope(isolate); + Object* object = *Utils::OpenHandle(*info.This()); + Object* res = Script::cast(JSValue::cast(object)->value())->line_offset(); + info.GetReturnValue().Set(Utils::ToLocal(Handle(res, isolate))); } -const AccessorDescriptor Accessors::ScriptColumnOffset = { - ScriptGetColumnOffset, - IllegalSetter, - 0 -}; +void Accessors::ScriptLineOffsetSetter( + v8::Local name, + v8::Local value, + const v8::PropertyCallbackInfo& info) { + UNREACHABLE(); +} + + +Handle Accessors::ScriptLineOffsetInfo( + Isolate* isolate, PropertyAttributes attributes) { + Handle name(isolate->factory()->InternalizeOneByteString( + STATIC_ASCII_VECTOR("line_offset"))); + return MakeAccessor(isolate, + name, + &ScriptLineOffsetGetter, + &ScriptLineOffsetSetter, + attributes); +} // diff --git a/src/accessors.h b/src/accessors.h index db506ce..2ad46eb 100644 --- a/src/accessors.h +++ b/src/accessors.h @@ -43,11 +43,6 @@ namespace internal { V(FunctionArguments) \ V(FunctionCaller) \ V(ArrayLength) \ - V(ScriptSource) \ - V(ScriptName) \ - V(ScriptId) \ - V(ScriptLineOffset) \ - V(ScriptColumnOffset) \ V(ScriptType) \ V(ScriptCompilationType) \ V(ScriptLineEnds) \ @@ -57,6 +52,11 @@ namespace internal { V(ScriptEvalFromFunctionName) #define ACCESSOR_INFO_LIST(V) \ + V(ScriptColumnOffset) \ + V(ScriptId) \ + V(ScriptLineOffset) \ + V(ScriptName) \ + V(ScriptSource) \ V(StringLength) \ // Accessors contains all predefined proxy accessors. @@ -137,16 +137,6 @@ class Accessors : public AllStatic { Object*, void*); static MaybeObject* ArrayGetLength(Isolate* isolate, Object* object, void*); - static MaybeObject* StringGetLength(Isolate* isolate, Object* object, void*); - static MaybeObject* ScriptGetName(Isolate* isolate, Object* object, void*); - static MaybeObject* ScriptGetId(Isolate* isolate, Object* object, void*); - static MaybeObject* ScriptGetSource(Isolate* isolate, Object* object, void*); - static MaybeObject* ScriptGetLineOffset(Isolate* isolate, - Object* object, - void*); - static MaybeObject* ScriptGetColumnOffset(Isolate* isolate, - Object* object, - void*); static MaybeObject* ScriptGetType(Isolate* isolate, Object* object, void*); static MaybeObject* ScriptGetCompilationType(Isolate* isolate, Object* object, diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index 45f55f8..8f72623 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -1682,22 +1682,6 @@ bool Genesis::InstallNatives() { Handle script_map = Handle(script_fun->initial_map()); Map::EnsureDescriptorSlack(script_map, 13); - Handle script_source( - factory()->NewForeign(&Accessors::ScriptSource)); - Handle script_name(factory()->NewForeign(&Accessors::ScriptName)); - Handle id_string(factory()->InternalizeOneByteString( - STATIC_ASCII_VECTOR("id"))); - Handle script_id(factory()->NewForeign(&Accessors::ScriptId)); - Handle line_offset_string( - factory()->InternalizeOneByteString( - STATIC_ASCII_VECTOR("line_offset"))); - Handle script_line_offset( - factory()->NewForeign(&Accessors::ScriptLineOffset)); - Handle column_offset_string( - factory()->InternalizeOneByteString( - STATIC_ASCII_VECTOR("column_offset"))); - Handle script_column_offset( - factory()->NewForeign(&Accessors::ScriptColumnOffset)); Handle type_string(factory()->InternalizeOneByteString( STATIC_ASCII_VECTOR("type"))); Handle script_type(factory()->NewForeign(&Accessors::ScriptType)); @@ -1733,30 +1717,44 @@ bool Genesis::InstallNatives() { PropertyAttributes attribs = static_cast(DONT_ENUM | DONT_DELETE | READ_ONLY); + Handle script_column = + Accessors::ScriptColumnOffsetInfo(isolate(), attribs); { - CallbacksDescriptor d( - factory()->source_string(), script_source, attribs); + CallbacksDescriptor d(Handle(Name::cast(script_column->name())), + script_column, attribs); script_map->AppendDescriptor(&d); } + Handle script_id = + Accessors::ScriptIdInfo(isolate(), attribs); { - CallbacksDescriptor d(factory()->name_string(), script_name, attribs); + CallbacksDescriptor d(Handle(Name::cast(script_id->name())), + script_id, attribs); script_map->AppendDescriptor(&d); } + + Handle script_name = + Accessors::ScriptNameInfo(isolate(), attribs); { - CallbacksDescriptor d(id_string, script_id, attribs); + CallbacksDescriptor d(Handle(Name::cast(script_name->name())), + script_name, attribs); script_map->AppendDescriptor(&d); } + Handle script_line = + Accessors::ScriptLineOffsetInfo(isolate(), attribs); { - CallbacksDescriptor d(line_offset_string, script_line_offset, attribs); + CallbacksDescriptor d(Handle(Name::cast(script_line->name())), + script_line, attribs); script_map->AppendDescriptor(&d); } + Handle script_source = + Accessors::ScriptSourceInfo(isolate(), attribs); { - CallbacksDescriptor d( - column_offset_string, script_column_offset, attribs); + CallbacksDescriptor d(Handle(Name::cast(script_source->name())), + script_source, attribs); script_map->AppendDescriptor(&d); } -- 2.7.4