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
This commit is contained in:
ulan@chromium.org 2014-04-16 11:57:23 +00:00
parent e05b58f0b0
commit de5f609da4
3 changed files with 173 additions and 103 deletions

View File

@ -54,8 +54,7 @@ static Handle<AccessorInfo> 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<Object> get = v8::FromCData(isolate, getter);
Handle<Object> set = v8::FromCData(isolate, setter);
info->set_getter(*get);
@ -294,43 +293,40 @@ Handle<AccessorInfo> 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<v8::String> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(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<Object>(res, isolate)));
}
const AccessorDescriptor Accessors::ScriptSource = {
ScriptGetSource,
IllegalSetter,
0
};
//
// Accessors::ScriptName
//
MaybeObject* Accessors::ScriptGetName(Isolate* isolate,
Object* object,
void*) {
Object* script = JSValue::cast(object)->value();
return Script::cast(script)->name();
void Accessors::ScriptColumnOffsetSetter(
v8::Local<v8::String> name,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
UNREACHABLE();
}
const AccessorDescriptor Accessors::ScriptName = {
ScriptGetName,
IllegalSetter,
0
};
Handle<AccessorInfo> Accessors::ScriptColumnOffsetInfo(
Isolate* isolate, PropertyAttributes attributes) {
Handle<String> name(isolate->factory()->InternalizeOneByteString(
STATIC_ASCII_VECTOR("column_offset")));
return MakeAccessor(isolate,
name,
&ScriptColumnOffsetGetter,
&ScriptColumnOffsetSetter,
attributes);
}
//
@ -338,17 +334,106 @@ const AccessorDescriptor Accessors::ScriptName = {
//
MaybeObject* Accessors::ScriptGetId(Isolate* isolate, Object* object, void*) {
Object* script = JSValue::cast(object)->value();
return Script::cast(script)->id();
void Accessors::ScriptIdGetter(
v8::Local<v8::String> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(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<Object>(id, isolate)));
}
const AccessorDescriptor Accessors::ScriptId = {
ScriptGetId,
IllegalSetter,
0
};
void Accessors::ScriptIdSetter(
v8::Local<v8::String> name,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
UNREACHABLE();
}
Handle<AccessorInfo> Accessors::ScriptIdInfo(
Isolate* isolate, PropertyAttributes attributes) {
Handle<String> name(isolate->factory()->InternalizeOneByteString(
STATIC_ASCII_VECTOR("id")));
return MakeAccessor(isolate,
name,
&ScriptIdGetter,
&ScriptIdSetter,
attributes);
}
//
// Accessors::ScriptName
//
void Accessors::ScriptNameGetter(
v8::Local<v8::String> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(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<Object>(source, isolate)));
}
void Accessors::ScriptNameSetter(
v8::Local<v8::String> name,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
UNREACHABLE();
}
Handle<AccessorInfo> Accessors::ScriptNameInfo(
Isolate* isolate, PropertyAttributes attributes) {
return MakeAccessor(isolate,
isolate->factory()->name_string(),
&ScriptNameGetter,
&ScriptNameSetter,
attributes);
}
//
// Accessors::ScriptSource
//
void Accessors::ScriptSourceGetter(
v8::Local<v8::String> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(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<Object>(source, isolate)));
}
void Accessors::ScriptSourceSetter(
v8::Local<v8::String> name,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
UNREACHABLE();
}
Handle<AccessorInfo> Accessors::ScriptSourceInfo(
Isolate* isolate, PropertyAttributes attributes) {
return MakeAccessor(isolate,
isolate->factory()->source_string(),
&ScriptSourceGetter,
&ScriptSourceSetter,
attributes);
}
//
@ -356,39 +441,36 @@ const AccessorDescriptor Accessors::ScriptId = {
//
MaybeObject* Accessors::ScriptGetLineOffset(Isolate* isolate,
Object* object,
void*) {
Object* script = JSValue::cast(object)->value();
return Script::cast(script)->line_offset();
void Accessors::ScriptLineOffsetGetter(
v8::Local<v8::String> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(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<Object>(res, isolate)));
}
const AccessorDescriptor Accessors::ScriptLineOffset = {
ScriptGetLineOffset,
IllegalSetter,
0
};
//
// Accessors::ScriptColumnOffset
//
MaybeObject* Accessors::ScriptGetColumnOffset(Isolate* isolate,
Object* object,
void*) {
Object* script = JSValue::cast(object)->value();
return Script::cast(script)->column_offset();
void Accessors::ScriptLineOffsetSetter(
v8::Local<v8::String> name,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
UNREACHABLE();
}
const AccessorDescriptor Accessors::ScriptColumnOffset = {
ScriptGetColumnOffset,
IllegalSetter,
0
};
Handle<AccessorInfo> Accessors::ScriptLineOffsetInfo(
Isolate* isolate, PropertyAttributes attributes) {
Handle<String> name(isolate->factory()->InternalizeOneByteString(
STATIC_ASCII_VECTOR("line_offset")));
return MakeAccessor(isolate,
name,
&ScriptLineOffsetGetter,
&ScriptLineOffsetSetter,
attributes);
}
//

View File

@ -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,

View File

@ -1682,22 +1682,6 @@ bool Genesis::InstallNatives() {
Handle<Map> script_map = Handle<Map>(script_fun->initial_map());
Map::EnsureDescriptorSlack(script_map, 13);
Handle<Foreign> script_source(
factory()->NewForeign(&Accessors::ScriptSource));
Handle<Foreign> script_name(factory()->NewForeign(&Accessors::ScriptName));
Handle<String> id_string(factory()->InternalizeOneByteString(
STATIC_ASCII_VECTOR("id")));
Handle<Foreign> script_id(factory()->NewForeign(&Accessors::ScriptId));
Handle<String> line_offset_string(
factory()->InternalizeOneByteString(
STATIC_ASCII_VECTOR("line_offset")));
Handle<Foreign> script_line_offset(
factory()->NewForeign(&Accessors::ScriptLineOffset));
Handle<String> column_offset_string(
factory()->InternalizeOneByteString(
STATIC_ASCII_VECTOR("column_offset")));
Handle<Foreign> script_column_offset(
factory()->NewForeign(&Accessors::ScriptColumnOffset));
Handle<String> type_string(factory()->InternalizeOneByteString(
STATIC_ASCII_VECTOR("type")));
Handle<Foreign> script_type(factory()->NewForeign(&Accessors::ScriptType));
@ -1733,30 +1717,44 @@ bool Genesis::InstallNatives() {
PropertyAttributes attribs =
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
Handle<AccessorInfo> script_column =
Accessors::ScriptColumnOffsetInfo(isolate(), attribs);
{
CallbacksDescriptor d(
factory()->source_string(), script_source, attribs);
CallbacksDescriptor d(Handle<Name>(Name::cast(script_column->name())),
script_column, attribs);
script_map->AppendDescriptor(&d);
}
Handle<AccessorInfo> script_id =
Accessors::ScriptIdInfo(isolate(), attribs);
{
CallbacksDescriptor d(factory()->name_string(), script_name, attribs);
CallbacksDescriptor d(Handle<Name>(Name::cast(script_id->name())),
script_id, attribs);
script_map->AppendDescriptor(&d);
}
Handle<AccessorInfo> script_name =
Accessors::ScriptNameInfo(isolate(), attribs);
{
CallbacksDescriptor d(id_string, script_id, attribs);
CallbacksDescriptor d(Handle<Name>(Name::cast(script_name->name())),
script_name, attribs);
script_map->AppendDescriptor(&d);
}
Handle<AccessorInfo> script_line =
Accessors::ScriptLineOffsetInfo(isolate(), attribs);
{
CallbacksDescriptor d(line_offset_string, script_line_offset, attribs);
CallbacksDescriptor d(Handle<Name>(Name::cast(script_line->name())),
script_line, attribs);
script_map->AppendDescriptor(&d);
}
Handle<AccessorInfo> script_source =
Accessors::ScriptSourceInfo(isolate(), attribs);
{
CallbacksDescriptor d(
column_offset_string, script_column_offset, attribs);
CallbacksDescriptor d(Handle<Name>(Name::cast(script_source->name())),
script_source, attribs);
script_map->AppendDescriptor(&d);
}