Commit 3e49c601 authored by ulan@chromium.org's avatar ulan@chromium.org

Handlify and convert the remaining Script accesssors.

BUG=
R=yangguo@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20814 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent dd206283
...@@ -478,19 +478,36 @@ Handle<AccessorInfo> Accessors::ScriptLineOffsetInfo( ...@@ -478,19 +478,36 @@ Handle<AccessorInfo> Accessors::ScriptLineOffsetInfo(
// //
MaybeObject* Accessors::ScriptGetType(Isolate* isolate, void Accessors::ScriptTypeGetter(
Object* object, v8::Local<v8::String> name,
void*) { const v8::PropertyCallbackInfo<v8::Value>& info) {
Object* script = JSValue::cast(object)->value(); i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
return Script::cast(script)->type(); DisallowHeapAllocation no_allocation;
HandleScope scope(isolate);
Object* object = *Utils::OpenHandle(*info.This());
Object* res = Script::cast(JSValue::cast(object)->value())->type();
info.GetReturnValue().Set(Utils::ToLocal(Handle<Object>(res, isolate)));
} }
const AccessorDescriptor Accessors::ScriptType = { void Accessors::ScriptTypeSetter(
ScriptGetType, v8::Local<v8::String> name,
IllegalSetter, v8::Local<v8::Value> value,
0 const v8::PropertyCallbackInfo<void>& info) {
}; UNREACHABLE();
}
Handle<AccessorInfo> Accessors::ScriptTypeInfo(
Isolate* isolate, PropertyAttributes attributes) {
Handle<String> name(isolate->factory()->InternalizeOneByteString(
STATIC_ASCII_VECTOR("type")));
return MakeAccessor(isolate,
name,
&ScriptTypeGetter,
&ScriptTypeSetter,
attributes);
}
// //
...@@ -498,19 +515,37 @@ const AccessorDescriptor Accessors::ScriptType = { ...@@ -498,19 +515,37 @@ const AccessorDescriptor Accessors::ScriptType = {
// //
MaybeObject* Accessors::ScriptGetCompilationType(Isolate* isolate, void Accessors::ScriptCompilationTypeGetter(
Object* object, v8::Local<v8::String> name,
void*) { const v8::PropertyCallbackInfo<v8::Value>& info) {
Object* script = JSValue::cast(object)->value(); i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
return Smi::FromInt(Script::cast(script)->compilation_type()); DisallowHeapAllocation no_allocation;
HandleScope scope(isolate);
Object* object = *Utils::OpenHandle(*info.This());
Object* res = Smi::FromInt(
Script::cast(JSValue::cast(object)->value())->compilation_type());
info.GetReturnValue().Set(Utils::ToLocal(Handle<Object>(res, isolate)));
} }
const AccessorDescriptor Accessors::ScriptCompilationType = { void Accessors::ScriptCompilationTypeSetter(
ScriptGetCompilationType, v8::Local<v8::String> name,
IllegalSetter, v8::Local<v8::Value> value,
0 const v8::PropertyCallbackInfo<void>& info) {
}; UNREACHABLE();
}
Handle<AccessorInfo> Accessors::ScriptCompilationTypeInfo(
Isolate* isolate, PropertyAttributes attributes) {
Handle<String> name(isolate->factory()->InternalizeOneByteString(
STATIC_ASCII_VECTOR("compilation_type")));
return MakeAccessor(isolate,
name,
&ScriptCompilationTypeGetter,
&ScriptCompilationTypeSetter,
attributes);
}
// //
...@@ -518,12 +553,14 @@ const AccessorDescriptor Accessors::ScriptCompilationType = { ...@@ -518,12 +553,14 @@ const AccessorDescriptor Accessors::ScriptCompilationType = {
// //
MaybeObject* Accessors::ScriptGetLineEnds(Isolate* isolate, void Accessors::ScriptLineEndsGetter(
Object* object, v8::Local<v8::String> name,
void*) { const v8::PropertyCallbackInfo<v8::Value>& info) {
JSValue* wrapper = JSValue::cast(object); i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
HandleScope scope(isolate); HandleScope scope(isolate);
Handle<Script> script(Script::cast(wrapper->value()), isolate); Handle<Object> object = Utils::OpenHandle(*info.This());
Handle<Script> script(
Script::cast(Handle<JSValue>::cast(object)->value()), isolate);
Script::InitLineEnds(script); Script::InitLineEnds(script);
ASSERT(script->line_ends()->IsFixedArray()); ASSERT(script->line_ends()->IsFixedArray());
Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends())); Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends()));
...@@ -532,15 +569,28 @@ MaybeObject* Accessors::ScriptGetLineEnds(Isolate* isolate, ...@@ -532,15 +569,28 @@ MaybeObject* Accessors::ScriptGetLineEnds(Isolate* isolate,
line_ends->map() == isolate->heap()->fixed_cow_array_map()); line_ends->map() == isolate->heap()->fixed_cow_array_map());
Handle<JSArray> js_array = Handle<JSArray> js_array =
isolate->factory()->NewJSArrayWithElements(line_ends); isolate->factory()->NewJSArrayWithElements(line_ends);
return *js_array; info.GetReturnValue().Set(Utils::ToLocal(js_array));
} }
const AccessorDescriptor Accessors::ScriptLineEnds = { void Accessors::ScriptLineEndsSetter(
ScriptGetLineEnds, v8::Local<v8::String> name,
IllegalSetter, v8::Local<v8::Value> value,
0 const v8::PropertyCallbackInfo<void>& info) {
}; UNREACHABLE();
}
Handle<AccessorInfo> Accessors::ScriptLineEndsInfo(
Isolate* isolate, PropertyAttributes attributes) {
Handle<String> name(isolate->factory()->InternalizeOneByteString(
STATIC_ASCII_VECTOR("line_ends")));
return MakeAccessor(isolate,
name,
&ScriptLineEndsGetter,
&ScriptLineEndsSetter,
attributes);
}
// //
...@@ -548,19 +598,36 @@ const AccessorDescriptor Accessors::ScriptLineEnds = { ...@@ -548,19 +598,36 @@ const AccessorDescriptor Accessors::ScriptLineEnds = {
// //
MaybeObject* Accessors::ScriptGetContextData(Isolate* isolate, void Accessors::ScriptContextDataGetter(
Object* object, v8::Local<v8::String> name,
void*) { const v8::PropertyCallbackInfo<v8::Value>& info) {
Object* script = JSValue::cast(object)->value(); i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
return Script::cast(script)->context_data(); DisallowHeapAllocation no_allocation;
HandleScope scope(isolate);
Object* object = *Utils::OpenHandle(*info.This());
Object* res = Script::cast(JSValue::cast(object)->value())->context_data();
info.GetReturnValue().Set(Utils::ToLocal(Handle<Object>(res, isolate)));
} }
const AccessorDescriptor Accessors::ScriptContextData = { void Accessors::ScriptContextDataSetter(
ScriptGetContextData, v8::Local<v8::String> name,
IllegalSetter, v8::Local<v8::Value> value,
0 const v8::PropertyCallbackInfo<void>& info) {
}; UNREACHABLE();
}
Handle<AccessorInfo> Accessors::ScriptContextDataInfo(
Isolate* isolate, PropertyAttributes attributes) {
Handle<String> name(isolate->factory()->InternalizeOneByteString(
STATIC_ASCII_VECTOR("context_data")));
return MakeAccessor(isolate,
name,
&ScriptContextDataGetter,
&ScriptContextDataSetter,
attributes);
}
// //
...@@ -568,28 +635,46 @@ const AccessorDescriptor Accessors::ScriptContextData = { ...@@ -568,28 +635,46 @@ const AccessorDescriptor Accessors::ScriptContextData = {
// //
MaybeObject* Accessors::ScriptGetEvalFromScript(Isolate* isolate, void Accessors::ScriptEvalFromScriptGetter(
Object* object, v8::Local<v8::String> name,
void*) { const v8::PropertyCallbackInfo<v8::Value>& info) {
Object* script = JSValue::cast(object)->value(); i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
if (!Script::cast(script)->eval_from_shared()->IsUndefined()) { HandleScope scope(isolate);
Handle<Object> object = Utils::OpenHandle(*info.This());
Handle<Script> script(
Script::cast(Handle<JSValue>::cast(object)->value()), isolate);
Handle<Object> result = isolate->factory()->undefined_value();
if (!script->eval_from_shared()->IsUndefined()) {
Handle<SharedFunctionInfo> eval_from_shared( Handle<SharedFunctionInfo> eval_from_shared(
SharedFunctionInfo::cast(Script::cast(script)->eval_from_shared())); SharedFunctionInfo::cast(script->eval_from_shared()));
if (eval_from_shared->script()->IsScript()) { if (eval_from_shared->script()->IsScript()) {
Handle<Script> eval_from_script(Script::cast(eval_from_shared->script())); Handle<Script> eval_from_script(Script::cast(eval_from_shared->script()));
return *Script::GetWrapper(eval_from_script); result = Script::GetWrapper(eval_from_script);
} }
} }
return isolate->heap()->undefined_value();
info.GetReturnValue().Set(Utils::ToLocal(result));
} }
const AccessorDescriptor Accessors::ScriptEvalFromScript = { void Accessors::ScriptEvalFromScriptSetter(
ScriptGetEvalFromScript, v8::Local<v8::String> name,
IllegalSetter, v8::Local<v8::Value> value,
0 const v8::PropertyCallbackInfo<void>& info) {
}; UNREACHABLE();
}
Handle<AccessorInfo> Accessors::ScriptEvalFromScriptInfo(
Isolate* isolate, PropertyAttributes attributes) {
Handle<String> name(isolate->factory()->InternalizeOneByteString(
STATIC_ASCII_VECTOR("eval_from_script")));
return MakeAccessor(isolate,
name,
&ScriptEvalFromScriptGetter,
&ScriptEvalFromScriptSetter,
attributes);
}
// //
...@@ -597,32 +682,45 @@ const AccessorDescriptor Accessors::ScriptEvalFromScript = { ...@@ -597,32 +682,45 @@ const AccessorDescriptor Accessors::ScriptEvalFromScript = {
// //
MaybeObject* Accessors::ScriptGetEvalFromScriptPosition(Isolate* isolate, void Accessors::ScriptEvalFromScriptPositionGetter(
Object* object, v8::Local<v8::String> name,
void*) { const v8::PropertyCallbackInfo<v8::Value>& info) {
Script* raw_script = Script::cast(JSValue::cast(object)->value()); i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
HandleScope scope(isolate); HandleScope scope(isolate);
Handle<Script> script(raw_script); Handle<Object> object = Utils::OpenHandle(*info.This());
Handle<Script> script(
// If this is not a script compiled through eval there is no eval position. Script::cast(Handle<JSValue>::cast(object)->value()), isolate);
if (script->compilation_type() != Script::COMPILATION_TYPE_EVAL) { Handle<Object> result = isolate->factory()->undefined_value();
return script->GetHeap()->undefined_value(); if (script->compilation_type() == Script::COMPILATION_TYPE_EVAL) {
}
// Get the function from where eval was called and find the source position
// from the instruction offset.
Handle<Code> code(SharedFunctionInfo::cast( Handle<Code> code(SharedFunctionInfo::cast(
script->eval_from_shared())->code()); script->eval_from_shared())->code());
return Smi::FromInt(code->SourcePosition(code->instruction_start() + result = Handle<Object>(
script->eval_from_instructions_offset()->value())); Smi::FromInt(code->SourcePosition(code->instruction_start() +
script->eval_from_instructions_offset()->value())),
isolate);
}
info.GetReturnValue().Set(Utils::ToLocal(result));
} }
const AccessorDescriptor Accessors::ScriptEvalFromScriptPosition = { void Accessors::ScriptEvalFromScriptPositionSetter(
ScriptGetEvalFromScriptPosition, v8::Local<v8::String> name,
IllegalSetter, v8::Local<v8::Value> value,
0 const v8::PropertyCallbackInfo<void>& info) {
}; UNREACHABLE();
}
Handle<AccessorInfo> Accessors::ScriptEvalFromScriptPositionInfo(
Isolate* isolate, PropertyAttributes attributes) {
Handle<String> name(isolate->factory()->InternalizeOneByteString(
STATIC_ASCII_VECTOR("eval_from_script_position")));
return MakeAccessor(isolate,
name,
&ScriptEvalFromScriptPositionGetter,
&ScriptEvalFromScriptPositionSetter,
attributes);
}
// //
...@@ -630,28 +728,45 @@ const AccessorDescriptor Accessors::ScriptEvalFromScriptPosition = { ...@@ -630,28 +728,45 @@ const AccessorDescriptor Accessors::ScriptEvalFromScriptPosition = {
// //
MaybeObject* Accessors::ScriptGetEvalFromFunctionName(Isolate* isolate, void Accessors::ScriptEvalFromFunctionNameGetter(
Object* object, v8::Local<v8::String> name,
void*) { const v8::PropertyCallbackInfo<v8::Value>& info) {
Object* script = JSValue::cast(object)->value(); i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast( HandleScope scope(isolate);
Script::cast(script)->eval_from_shared())); Handle<Object> object = Utils::OpenHandle(*info.This());
Handle<Script> script(
Script::cast(Handle<JSValue>::cast(object)->value()), isolate);
Handle<Object> result;
Handle<SharedFunctionInfo> shared(
SharedFunctionInfo::cast(script->eval_from_shared()));
// Find the name of the function calling eval. // Find the name of the function calling eval.
if (!shared->name()->IsUndefined()) { if (!shared->name()->IsUndefined()) {
return shared->name(); result = Handle<Object>(shared->name(), isolate);
} else { } else {
return shared->inferred_name(); result = Handle<Object>(shared->inferred_name(), isolate);
} }
info.GetReturnValue().Set(Utils::ToLocal(result));
} }
const AccessorDescriptor Accessors::ScriptEvalFromFunctionName = { void Accessors::ScriptEvalFromFunctionNameSetter(
ScriptGetEvalFromFunctionName, v8::Local<v8::String> name,
IllegalSetter, v8::Local<v8::Value> value,
0 const v8::PropertyCallbackInfo<void>& info) {
}; UNREACHABLE();
}
Handle<AccessorInfo> Accessors::ScriptEvalFromFunctionNameInfo(
Isolate* isolate, PropertyAttributes attributes) {
Handle<String> name(isolate->factory()->InternalizeOneByteString(
STATIC_ASCII_VECTOR("eval_from_function_name")));
return MakeAccessor(isolate,
name,
&ScriptEvalFromFunctionNameGetter,
&ScriptEvalFromFunctionNameSetter,
attributes);
}
// //
......
...@@ -42,22 +42,22 @@ namespace internal { ...@@ -42,22 +42,22 @@ namespace internal {
V(FunctionName) \ V(FunctionName) \
V(FunctionArguments) \ V(FunctionArguments) \
V(FunctionCaller) \ V(FunctionCaller) \
V(ArrayLength) \ V(ArrayLength)
V(ScriptType) \
#define ACCESSOR_INFO_LIST(V) \
V(ScriptColumnOffset) \
V(ScriptCompilationType) \ V(ScriptCompilationType) \
V(ScriptLineEnds) \
V(ScriptContextData) \ V(ScriptContextData) \
V(ScriptEvalFromScript) \ V(ScriptEvalFromScript) \
V(ScriptEvalFromScriptPosition) \ V(ScriptEvalFromScriptPosition) \
V(ScriptEvalFromFunctionName) V(ScriptEvalFromFunctionName) \
#define ACCESSOR_INFO_LIST(V) \
V(ScriptColumnOffset) \
V(ScriptId) \ V(ScriptId) \
V(ScriptLineEnds) \
V(ScriptLineOffset) \ V(ScriptLineOffset) \
V(ScriptName) \ V(ScriptName) \
V(ScriptSource) \ V(ScriptSource) \
V(StringLength) \ V(ScriptType) \
V(StringLength)
// Accessors contains all predefined proxy accessors. // Accessors contains all predefined proxy accessors.
...@@ -137,25 +137,6 @@ class Accessors : public AllStatic { ...@@ -137,25 +137,6 @@ class Accessors : public AllStatic {
Object*, Object*,
void*); void*);
static MaybeObject* ArrayGetLength(Isolate* isolate, Object* object, void*); static MaybeObject* ArrayGetLength(Isolate* isolate, Object* object, void*);
static MaybeObject* ScriptGetType(Isolate* isolate, Object* object, void*);
static MaybeObject* ScriptGetCompilationType(Isolate* isolate,
Object* object,
void*);
static MaybeObject* ScriptGetLineEnds(Isolate* isolate,
Object* object,
void*);
static MaybeObject* ScriptGetContextData(Isolate* isolate,
Object* object,
void*);
static MaybeObject* ScriptGetEvalFromScript(Isolate* isolate,
Object* object,
void*);
static MaybeObject* ScriptGetEvalFromScriptPosition(Isolate* isolate,
Object* object,
void*);
static MaybeObject* ScriptGetEvalFromFunctionName(Isolate* isolate,
Object* object,
void*);
// Helper functions. // Helper functions.
static Handle<Object> FlattenNumber(Isolate* isolate, Handle<Object> value); static Handle<Object> FlattenNumber(Isolate* isolate, Handle<Object> value);
......
...@@ -1682,38 +1682,6 @@ bool Genesis::InstallNatives() { ...@@ -1682,38 +1682,6 @@ bool Genesis::InstallNatives() {
Handle<Map> script_map = Handle<Map>(script_fun->initial_map()); Handle<Map> script_map = Handle<Map>(script_fun->initial_map());
Map::EnsureDescriptorSlack(script_map, 13); Map::EnsureDescriptorSlack(script_map, 13);
Handle<String> type_string(factory()->InternalizeOneByteString(
STATIC_ASCII_VECTOR("type")));
Handle<Foreign> script_type(factory()->NewForeign(&Accessors::ScriptType));
Handle<String> compilation_type_string(
factory()->InternalizeOneByteString(
STATIC_ASCII_VECTOR("compilation_type")));
Handle<Foreign> script_compilation_type(
factory()->NewForeign(&Accessors::ScriptCompilationType));
Handle<String> line_ends_string(factory()->InternalizeOneByteString(
STATIC_ASCII_VECTOR("line_ends")));
Handle<Foreign> script_line_ends(
factory()->NewForeign(&Accessors::ScriptLineEnds));
Handle<String> context_data_string(
factory()->InternalizeOneByteString(
STATIC_ASCII_VECTOR("context_data")));
Handle<Foreign> script_context_data(
factory()->NewForeign(&Accessors::ScriptContextData));
Handle<String> eval_from_script_string(
factory()->InternalizeOneByteString(
STATIC_ASCII_VECTOR("eval_from_script")));
Handle<Foreign> script_eval_from_script(
factory()->NewForeign(&Accessors::ScriptEvalFromScript));
Handle<String> eval_from_script_position_string(
factory()->InternalizeOneByteString(
STATIC_ASCII_VECTOR("eval_from_script_position")));
Handle<Foreign> script_eval_from_script_position(
factory()->NewForeign(&Accessors::ScriptEvalFromScriptPosition));
Handle<String> eval_from_function_name_string(
factory()->InternalizeOneByteString(
STATIC_ASCII_VECTOR("eval_from_function_name")));
Handle<Foreign> script_eval_from_function_name(
factory()->NewForeign(&Accessors::ScriptEvalFromFunctionName));
PropertyAttributes attribs = PropertyAttributes attribs =
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
...@@ -1758,47 +1726,64 @@ bool Genesis::InstallNatives() { ...@@ -1758,47 +1726,64 @@ bool Genesis::InstallNatives() {
script_map->AppendDescriptor(&d); script_map->AppendDescriptor(&d);
} }
Handle<AccessorInfo> script_type =
Accessors::ScriptTypeInfo(isolate(), attribs);
{ {
CallbacksDescriptor d(type_string, script_type, attribs); CallbacksDescriptor d(Handle<Name>(Name::cast(script_type->name())),
script_type, attribs);
script_map->AppendDescriptor(&d); script_map->AppendDescriptor(&d);
} }
Handle<AccessorInfo> script_compilation_type =
Accessors::ScriptCompilationTypeInfo(isolate(), attribs);
{ {
CallbacksDescriptor d( CallbacksDescriptor d(
compilation_type_string, script_compilation_type, attribs); Handle<Name>(Name::cast(script_compilation_type->name())),
script_compilation_type, attribs);
script_map->AppendDescriptor(&d); script_map->AppendDescriptor(&d);
} }
Handle<AccessorInfo> script_line_ends =
Accessors::ScriptLineEndsInfo(isolate(), attribs);
{ {
CallbacksDescriptor d(line_ends_string, script_line_ends, attribs); CallbacksDescriptor d(Handle<Name>(Name::cast(script_line_ends->name())),
script_line_ends, attribs);
script_map->AppendDescriptor(&d); script_map->AppendDescriptor(&d);
} }
Handle<AccessorInfo> script_context_data =
Accessors::ScriptContextDataInfo(isolate(), attribs);
{ {
CallbacksDescriptor d( CallbacksDescriptor d(
context_data_string, script_context_data, attribs); Handle<Name>(Name::cast(script_context_data->name())),
script_context_data, attribs);
script_map->AppendDescriptor(&d); script_map->AppendDescriptor(&d);
} }
Handle<AccessorInfo> script_eval_from_script =
Accessors::ScriptEvalFromScriptInfo(isolate(), attribs);
{ {
CallbacksDescriptor d( CallbacksDescriptor d(
eval_from_script_string, script_eval_from_script, attribs); Handle<Name>(Name::cast(script_eval_from_script->name())),
script_eval_from_script, attribs);
script_map->AppendDescriptor(&d); script_map->AppendDescriptor(&d);
} }
Handle<AccessorInfo> script_eval_from_script_position =
Accessors::ScriptEvalFromScriptPositionInfo(isolate(), attribs);
{ {
CallbacksDescriptor d( CallbacksDescriptor d(
eval_from_script_position_string, Handle<Name>(Name::cast(script_eval_from_script_position->name())),
script_eval_from_script_position, script_eval_from_script_position, attribs);
attribs);
script_map->AppendDescriptor(&d); script_map->AppendDescriptor(&d);
} }
Handle<AccessorInfo> script_eval_from_function_name =
Accessors::ScriptEvalFromFunctionNameInfo(isolate(), attribs);
{ {
CallbacksDescriptor d( CallbacksDescriptor d(
eval_from_function_name_string, Handle<Name>(Name::cast(script_eval_from_function_name->name())),
script_eval_from_function_name, script_eval_from_function_name, attribs);
attribs);
script_map->AppendDescriptor(&d); script_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