Commit 92996f02 authored by ager@chromium.org's avatar ager@chromium.org

Cleanup of Isolate::Current() and FACTORY macro usage in execution.cc.

BUG=none
TEST=none

Patch from Peter Varga <pvarga@inf.u-szeged.hu>.

Review URL: http://codereview.chromium.org/6759029

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7464 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c3b761cd
// Copyright 2006-2008 the V8 project authors. All rights reserved. // Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
...@@ -199,6 +199,8 @@ Handle<Object> Execution::TryCall(Handle<JSFunction> func, ...@@ -199,6 +199,8 @@ Handle<Object> Execution::TryCall(Handle<JSFunction> func,
Handle<Object> Execution::GetFunctionDelegate(Handle<Object> object) { Handle<Object> Execution::GetFunctionDelegate(Handle<Object> object) {
ASSERT(!object->IsJSFunction()); ASSERT(!object->IsJSFunction());
Isolate* isolate = Isolate::Current();
Factory* factory = isolate->factory();
// If you return a function from here, it will be called when an // If you return a function from here, it will be called when an
// attempt is made to call the given object as a function. // attempt is made to call the given object as a function.
...@@ -206,7 +208,7 @@ Handle<Object> Execution::GetFunctionDelegate(Handle<Object> object) { ...@@ -206,7 +208,7 @@ Handle<Object> Execution::GetFunctionDelegate(Handle<Object> object) {
// Regular expressions can be called as functions in both Firefox // Regular expressions can be called as functions in both Firefox
// and Safari so we allow it too. // and Safari so we allow it too.
if (object->IsJSRegExp()) { if (object->IsJSRegExp()) {
Handle<String> exec = FACTORY->exec_symbol(); Handle<String> exec = factory->exec_symbol();
// TODO(lrn): Bug 617. We should use the default function here, not the // TODO(lrn): Bug 617. We should use the default function here, not the
// one on the RegExp object. // one on the RegExp object.
Object* exec_function; Object* exec_function;
...@@ -214,7 +216,7 @@ Handle<Object> Execution::GetFunctionDelegate(Handle<Object> object) { ...@@ -214,7 +216,7 @@ Handle<Object> Execution::GetFunctionDelegate(Handle<Object> object) {
// This can lose an exception, but the alternative is to put a failure // This can lose an exception, but the alternative is to put a failure
// object in a handle, which is not GC safe. // object in a handle, which is not GC safe.
if (!maybe_exec_function->ToObject(&exec_function)) { if (!maybe_exec_function->ToObject(&exec_function)) {
return FACTORY->undefined_value(); return factory->undefined_value();
} }
} }
return Handle<Object>(exec_function); return Handle<Object>(exec_function);
...@@ -225,15 +227,16 @@ Handle<Object> Execution::GetFunctionDelegate(Handle<Object> object) { ...@@ -225,15 +227,16 @@ Handle<Object> Execution::GetFunctionDelegate(Handle<Object> object) {
if (object->IsHeapObject() && if (object->IsHeapObject() &&
HeapObject::cast(*object)->map()->has_instance_call_handler()) { HeapObject::cast(*object)->map()->has_instance_call_handler()) {
return Handle<JSFunction>( return Handle<JSFunction>(
Isolate::Current()->global_context()->call_as_function_delegate()); isolate->global_context()->call_as_function_delegate());
} }
return FACTORY->undefined_value(); return factory->undefined_value();
} }
Handle<Object> Execution::GetConstructorDelegate(Handle<Object> object) { Handle<Object> Execution::GetConstructorDelegate(Handle<Object> object) {
ASSERT(!object->IsJSFunction()); ASSERT(!object->IsJSFunction());
Isolate* isolate = Isolate::Current();
// If you return a function from here, it will be called when an // If you return a function from here, it will be called when an
// attempt is made to call the given object as a constructor. // attempt is made to call the given object as a constructor.
...@@ -243,10 +246,10 @@ Handle<Object> Execution::GetConstructorDelegate(Handle<Object> object) { ...@@ -243,10 +246,10 @@ Handle<Object> Execution::GetConstructorDelegate(Handle<Object> object) {
if (object->IsHeapObject() && if (object->IsHeapObject() &&
HeapObject::cast(*object)->map()->has_instance_call_handler()) { HeapObject::cast(*object)->map()->has_instance_call_handler()) {
return Handle<JSFunction>( return Handle<JSFunction>(
Isolate::Current()->global_context()->call_as_constructor_delegate()); isolate->global_context()->call_as_constructor_delegate());
} }
return FACTORY->undefined_value(); return isolate->factory()->undefined_value();
} }
...@@ -467,10 +470,11 @@ void StackGuard::InitThread(const ExecutionAccess& lock) { ...@@ -467,10 +470,11 @@ void StackGuard::InitThread(const ExecutionAccess& lock) {
#define RETURN_NATIVE_CALL(name, argc, argv, has_pending_exception) \ #define RETURN_NATIVE_CALL(name, argc, argv, has_pending_exception) \
do { \ do { \
Isolate* isolate = Isolate::Current(); \
Object** args[argc] = argv; \ Object** args[argc] = argv; \
ASSERT(has_pending_exception != NULL); \ ASSERT(has_pending_exception != NULL); \
return Call(Isolate::Current()->name##_fun(), \ return Call(isolate->name##_fun(), \
Isolate::Current()->js_builtins_object(), argc, args, \ isolate->js_builtins_object(), argc, args, \
has_pending_exception); \ has_pending_exception); \
} while (false) } while (false)
...@@ -549,20 +553,23 @@ Handle<JSRegExp> Execution::NewJSRegExp(Handle<String> pattern, ...@@ -549,20 +553,23 @@ Handle<JSRegExp> Execution::NewJSRegExp(Handle<String> pattern,
Handle<Object> Execution::CharAt(Handle<String> string, uint32_t index) { Handle<Object> Execution::CharAt(Handle<String> string, uint32_t index) {
Isolate* isolate = string->GetIsolate();
Factory* factory = isolate->factory();
int int_index = static_cast<int>(index); int int_index = static_cast<int>(index);
if (int_index < 0 || int_index >= string->length()) { if (int_index < 0 || int_index >= string->length()) {
return FACTORY->undefined_value(); return factory->undefined_value();
} }
Handle<Object> char_at = Handle<Object> char_at =
GetProperty(Isolate::Current()->js_builtins_object(), GetProperty(isolate->js_builtins_object(),
FACTORY->char_at_symbol()); factory->char_at_symbol());
if (!char_at->IsJSFunction()) { if (!char_at->IsJSFunction()) {
return FACTORY->undefined_value(); return factory->undefined_value();
} }
bool caught_exception; bool caught_exception;
Handle<Object> index_object = FACTORY->NewNumberFromInt(int_index); Handle<Object> index_object = factory->NewNumberFromInt(int_index);
Object** index_arg[] = { index_object.location() }; Object** index_arg[] = { index_object.location() };
Handle<Object> result = TryCall(Handle<JSFunction>::cast(char_at), Handle<Object> result = TryCall(Handle<JSFunction>::cast(char_at),
string, string,
...@@ -570,7 +577,7 @@ Handle<Object> Execution::CharAt(Handle<String> string, uint32_t index) { ...@@ -570,7 +577,7 @@ Handle<Object> Execution::CharAt(Handle<String> string, uint32_t index) {
index_arg, index_arg,
&caught_exception); &caught_exception);
if (caught_exception) { if (caught_exception) {
return FACTORY->undefined_value(); return factory->undefined_value();
} }
return result; return result;
} }
...@@ -578,17 +585,18 @@ Handle<Object> Execution::CharAt(Handle<String> string, uint32_t index) { ...@@ -578,17 +585,18 @@ Handle<Object> Execution::CharAt(Handle<String> string, uint32_t index) {
Handle<JSFunction> Execution::InstantiateFunction( Handle<JSFunction> Execution::InstantiateFunction(
Handle<FunctionTemplateInfo> data, bool* exc) { Handle<FunctionTemplateInfo> data, bool* exc) {
Isolate* isolate = data->GetIsolate();
// Fast case: see if the function has already been instantiated // Fast case: see if the function has already been instantiated
int serial_number = Smi::cast(data->serial_number())->value(); int serial_number = Smi::cast(data->serial_number())->value();
Object* elm = Object* elm =
Isolate::Current()->global_context()->function_cache()-> isolate->global_context()->function_cache()->
GetElementNoExceptionThrown(serial_number); GetElementNoExceptionThrown(serial_number);
if (elm->IsJSFunction()) return Handle<JSFunction>(JSFunction::cast(elm)); if (elm->IsJSFunction()) return Handle<JSFunction>(JSFunction::cast(elm));
// The function has not yet been instantiated in this context; do it. // The function has not yet been instantiated in this context; do it.
Object** args[1] = { Handle<Object>::cast(data).location() }; Object** args[1] = { Handle<Object>::cast(data).location() };
Handle<Object> result = Handle<Object> result =
Call(Isolate::Current()->instantiate_fun(), Call(isolate->instantiate_fun(),
Isolate::Current()->js_builtins_object(), 1, args, exc); isolate->js_builtins_object(), 1, args, exc);
if (*exc) return Handle<JSFunction>::null(); if (*exc) return Handle<JSFunction>::null();
return Handle<JSFunction>::cast(result); return Handle<JSFunction>::cast(result);
} }
...@@ -596,12 +604,13 @@ Handle<JSFunction> Execution::InstantiateFunction( ...@@ -596,12 +604,13 @@ Handle<JSFunction> Execution::InstantiateFunction(
Handle<JSObject> Execution::InstantiateObject(Handle<ObjectTemplateInfo> data, Handle<JSObject> Execution::InstantiateObject(Handle<ObjectTemplateInfo> data,
bool* exc) { bool* exc) {
Isolate* isolate = data->GetIsolate();
if (data->property_list()->IsUndefined() && if (data->property_list()->IsUndefined() &&
!data->constructor()->IsUndefined()) { !data->constructor()->IsUndefined()) {
// Initialization to make gcc happy. // Initialization to make gcc happy.
Object* result = NULL; Object* result = NULL;
{ {
HandleScope scope; HandleScope scope(isolate);
Handle<FunctionTemplateInfo> cons_template = Handle<FunctionTemplateInfo> cons_template =
Handle<FunctionTemplateInfo>( Handle<FunctionTemplateInfo>(
FunctionTemplateInfo::cast(data->constructor())); FunctionTemplateInfo::cast(data->constructor()));
...@@ -616,8 +625,8 @@ Handle<JSObject> Execution::InstantiateObject(Handle<ObjectTemplateInfo> data, ...@@ -616,8 +625,8 @@ Handle<JSObject> Execution::InstantiateObject(Handle<ObjectTemplateInfo> data,
} else { } else {
Object** args[1] = { Handle<Object>::cast(data).location() }; Object** args[1] = { Handle<Object>::cast(data).location() };
Handle<Object> result = Handle<Object> result =
Call(Isolate::Current()->instantiate_fun(), Call(isolate->instantiate_fun(),
Isolate::Current()->js_builtins_object(), 1, args, exc); isolate->js_builtins_object(), 1, args, exc);
if (*exc) return Handle<JSObject>::null(); if (*exc) return Handle<JSObject>::null();
return Handle<JSObject>::cast(result); return Handle<JSObject>::cast(result);
} }
...@@ -627,9 +636,10 @@ Handle<JSObject> Execution::InstantiateObject(Handle<ObjectTemplateInfo> data, ...@@ -627,9 +636,10 @@ Handle<JSObject> Execution::InstantiateObject(Handle<ObjectTemplateInfo> data,
void Execution::ConfigureInstance(Handle<Object> instance, void Execution::ConfigureInstance(Handle<Object> instance,
Handle<Object> instance_template, Handle<Object> instance_template,
bool* exc) { bool* exc) {
Isolate* isolate = Isolate::Current();
Object** args[2] = { instance.location(), instance_template.location() }; Object** args[2] = { instance.location(), instance_template.location() };
Execution::Call(Isolate::Current()->configure_instance_fun(), Execution::Call(isolate->configure_instance_fun(),
Isolate::Current()->js_builtins_object(), 2, args, exc); isolate->js_builtins_object(), 2, args, exc);
} }
...@@ -637,6 +647,7 @@ Handle<String> Execution::GetStackTraceLine(Handle<Object> recv, ...@@ -637,6 +647,7 @@ Handle<String> Execution::GetStackTraceLine(Handle<Object> recv,
Handle<JSFunction> fun, Handle<JSFunction> fun,
Handle<Object> pos, Handle<Object> pos,
Handle<Object> is_global) { Handle<Object> is_global) {
Isolate* isolate = fun->GetIsolate();
const int argc = 4; const int argc = 4;
Object** args[argc] = { recv.location(), Object** args[argc] = { recv.location(),
Handle<Object>::cast(fun).location(), Handle<Object>::cast(fun).location(),
...@@ -644,10 +655,13 @@ Handle<String> Execution::GetStackTraceLine(Handle<Object> recv, ...@@ -644,10 +655,13 @@ Handle<String> Execution::GetStackTraceLine(Handle<Object> recv,
is_global.location() }; is_global.location() };
bool caught_exception = false; bool caught_exception = false;
Handle<Object> result = Handle<Object> result =
TryCall(Isolate::Current()->get_stack_trace_line_fun(), TryCall(isolate->get_stack_trace_line_fun(),
Isolate::Current()->js_builtins_object(), argc, args, isolate->js_builtins_object(), argc, args,
&caught_exception); &caught_exception);
if (caught_exception || !result->IsString()) return FACTORY->empty_symbol(); if (caught_exception || !result->IsString()) {
return isolate->factory()->empty_symbol();
}
return Handle<String>::cast(result); return Handle<String>::cast(result);
} }
...@@ -728,10 +742,11 @@ Object* Execution::DebugBreakHelper() { ...@@ -728,10 +742,11 @@ Object* Execution::DebugBreakHelper() {
} }
void Execution::ProcessDebugMesssages(bool debug_command_only) { void Execution::ProcessDebugMesssages(bool debug_command_only) {
Isolate* isolate = Isolate::Current();
// Clear the debug command request flag. // Clear the debug command request flag.
Isolate::Current()->stack_guard()->Continue(DEBUGCOMMAND); isolate->stack_guard()->Continue(DEBUGCOMMAND);
HandleScope scope; HandleScope scope(isolate);
// Enter the debugger. Just continue if we fail to enter the debugger. // Enter the debugger. Just continue if we fail to enter the debugger.
EnterDebugger debugger; EnterDebugger debugger;
if (debugger.FailedToEnter()) { if (debugger.FailedToEnter()) {
...@@ -740,7 +755,7 @@ void Execution::ProcessDebugMesssages(bool debug_command_only) { ...@@ -740,7 +755,7 @@ void Execution::ProcessDebugMesssages(bool debug_command_only) {
// Notify the debug event listeners. Indicate auto continue if the break was // Notify the debug event listeners. Indicate auto continue if the break was
// a debug command break. // a debug command break.
Isolate::Current()->debugger()->OnDebugBreak(FACTORY->undefined_value(), isolate->debugger()->OnDebugBreak(isolate->factory()->undefined_value(),
debug_command_only); debug_command_only);
} }
......
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