From 33dabf08f9bd99a12743589388434e997defb907 Mon Sep 17 00:00:00 2001 From: "dcarney@chromium.org" Date: Wed, 5 Jun 2013 12:36:33 +0000 Subject: [PATCH] Cutover v8 to use new style callbacks internally R=svenpanne@chromium.org BUG= Review URL: https://codereview.chromium.org/15793007 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14952 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- samples/lineprocessor.cc | 14 +- samples/process.cc | 75 +++++----- samples/shell.cc | 45 +++--- src/accessors.cc | 10 +- src/api.cc | 34 +++-- src/arguments.h | 13 +- src/d8-posix.cc | 97 +++++++------ src/d8.cc | 129 ++++++++++-------- src/d8.h | 94 ++++++------- .../externalize-string-extension.cc | 32 +++-- src/extensions/externalize-string-extension.h | 4 +- src/extensions/gc-extension.cc | 3 +- src/extensions/gc-extension.h | 2 +- src/extensions/statistics-extension.cc | 6 +- src/extensions/statistics-extension.h | 2 +- 15 files changed, 305 insertions(+), 255 deletions(-) diff --git a/samples/lineprocessor.cc b/samples/lineprocessor.cc index 635691ec1..214af057d 100644 --- a/samples/lineprocessor.cc +++ b/samples/lineprocessor.cc @@ -102,8 +102,8 @@ void ReportException(v8::Isolate* isolate, v8::TryCatch* handler); v8::Handle ReadFile(const char* name); v8::Handle ReadLine(); -v8::Handle Print(const v8::Arguments& args); -v8::Handle ReadLine(const v8::Arguments& args); +void Print(const v8::FunctionCallbackInfo& args); +void ReadLine(const v8::FunctionCallbackInfo& args); bool RunCppCycle(v8::Handle script, v8::Local context, bool report_exceptions); @@ -393,7 +393,7 @@ void ReportException(v8::Isolate* isolate, v8::TryCatch* try_catch) { // The callback that is invoked by v8 whenever the JavaScript 'print' // function is called. Prints its arguments on stdout separated by // spaces and ending with a newline. -v8::Handle Print(const v8::Arguments& args) { +void Print(const v8::FunctionCallbackInfo& args) { bool first = true; for (int i = 0; i < args.Length(); i++) { v8::HandleScope handle_scope(args.GetIsolate()); @@ -408,17 +408,17 @@ v8::Handle Print(const v8::Arguments& args) { } printf("\n"); fflush(stdout); - return v8::Undefined(); } // The callback that is invoked by v8 whenever the JavaScript 'read_line' // function is called. Reads a string from standard input and returns. -v8::Handle ReadLine(const v8::Arguments& args) { +void ReadLine(const v8::FunctionCallbackInfo& args) { if (args.Length() > 0) { - return v8::ThrowException(v8::String::New("Unexpected arguments")); + v8::ThrowException(v8::String::New("Unexpected arguments")); + return; } - return ReadLine(); + args.GetReturnValue().Set(ReadLine()); } v8::Handle ReadLine() { diff --git a/samples/process.cc b/samples/process.cc index 1c1e7bec9..97eec14dc 100644 --- a/samples/process.cc +++ b/samples/process.cc @@ -102,18 +102,21 @@ class JsHttpRequestProcessor : public HttpRequestProcessor { static Handle MakeMapTemplate(Isolate* isolate); // Callbacks that access the individual fields of request objects. - static Handle GetPath(Local name, const AccessorInfo& info); - static Handle GetReferrer(Local name, - const AccessorInfo& info); - static Handle GetHost(Local name, const AccessorInfo& info); - static Handle GetUserAgent(Local name, - const AccessorInfo& info); + static void GetPath(Local name, + const PropertyCallbackInfo& info); + static void GetReferrer(Local name, + const PropertyCallbackInfo& info); + static void GetHost(Local name, + const PropertyCallbackInfo& info); + static void GetUserAgent(Local name, + const PropertyCallbackInfo& info); // Callbacks that access maps - static Handle MapGet(Local name, const AccessorInfo& info); - static Handle MapSet(Local name, - Local value, - const AccessorInfo& info); + static void MapGet(Local name, + const PropertyCallbackInfo& info); + static void MapSet(Local name, + Local value, + const PropertyCallbackInfo& info); // Utility methods for wrapping C++ objects as JavaScript objects, // and going back again. @@ -137,13 +140,12 @@ class JsHttpRequestProcessor : public HttpRequestProcessor { // ------------------------- -static Handle LogCallback(const Arguments& args) { - if (args.Length() < 1) return Undefined(); +static void LogCallback(const v8::FunctionCallbackInfo& args) { + if (args.Length() < 1) return; HandleScope scope(args.GetIsolate()); Handle arg = args[0]; String::Utf8Value value(arg); HttpRequestProcessor::Log(*value); - return Undefined(); } @@ -350,8 +352,8 @@ string ObjectToString(Local value) { } -Handle JsHttpRequestProcessor::MapGet(Local name, - const AccessorInfo& info) { +void JsHttpRequestProcessor::MapGet(Local name, + const PropertyCallbackInfo& info) { // Fetch the map wrapped by this object. map* obj = UnwrapMap(info.Holder()); @@ -362,17 +364,18 @@ Handle JsHttpRequestProcessor::MapGet(Local name, map::iterator iter = obj->find(key); // If the key is not present return an empty handle as signal - if (iter == obj->end()) return Handle(); + if (iter == obj->end()) return; // Otherwise fetch the value and wrap it in a JavaScript string const string& value = (*iter).second; - return String::New(value.c_str(), static_cast(value.length())); + info.GetReturnValue().Set( + String::New(value.c_str(), static_cast(value.length()))); } -Handle JsHttpRequestProcessor::MapSet(Local name, - Local value_obj, - const AccessorInfo& info) { +void JsHttpRequestProcessor::MapSet(Local name, + Local value_obj, + const PropertyCallbackInfo& info) { // Fetch the map wrapped by this object. map* obj = UnwrapMap(info.Holder()); @@ -384,7 +387,7 @@ Handle JsHttpRequestProcessor::MapSet(Local name, (*obj)[key] = value; // Return the value; any non-empty handle will work. - return value_obj; + info.GetReturnValue().Set(value_obj); } @@ -451,8 +454,8 @@ HttpRequest* JsHttpRequestProcessor::UnwrapRequest(Handle obj) { } -Handle JsHttpRequestProcessor::GetPath(Local name, - const AccessorInfo& info) { +void JsHttpRequestProcessor::GetPath(Local name, + const PropertyCallbackInfo& info) { // Extract the C++ request object from the JavaScript wrapper. HttpRequest* request = UnwrapRequest(info.Holder()); @@ -460,31 +463,37 @@ Handle JsHttpRequestProcessor::GetPath(Local name, const string& path = request->Path(); // Wrap the result in a JavaScript string and return it. - return String::New(path.c_str(), static_cast(path.length())); + info.GetReturnValue().Set( + String::New(path.c_str(), static_cast(path.length()))); } -Handle JsHttpRequestProcessor::GetReferrer(Local name, - const AccessorInfo& info) { +void JsHttpRequestProcessor::GetReferrer( + Local name, + const PropertyCallbackInfo& info) { HttpRequest* request = UnwrapRequest(info.Holder()); const string& path = request->Referrer(); - return String::New(path.c_str(), static_cast(path.length())); + info.GetReturnValue().Set( + String::New(path.c_str(), static_cast(path.length()))); } -Handle JsHttpRequestProcessor::GetHost(Local name, - const AccessorInfo& info) { +void JsHttpRequestProcessor::GetHost(Local name, + const PropertyCallbackInfo& info) { HttpRequest* request = UnwrapRequest(info.Holder()); const string& path = request->Host(); - return String::New(path.c_str(), static_cast(path.length())); + info.GetReturnValue().Set( + String::New(path.c_str(), static_cast(path.length()))); } -Handle JsHttpRequestProcessor::GetUserAgent(Local name, - const AccessorInfo& info) { +void JsHttpRequestProcessor::GetUserAgent( + Local name, + const PropertyCallbackInfo& info) { HttpRequest* request = UnwrapRequest(info.Holder()); const string& path = request->UserAgent(); - return String::New(path.c_str(), static_cast(path.length())); + info.GetReturnValue().Set( + String::New(path.c_str(), static_cast(path.length()))); } diff --git a/samples/shell.cc b/samples/shell.cc index 430dd966e..a0af931b2 100644 --- a/samples/shell.cc +++ b/samples/shell.cc @@ -53,11 +53,11 @@ bool ExecuteString(v8::Isolate* isolate, v8::Handle name, bool print_result, bool report_exceptions); -v8::Handle Print(const v8::Arguments& args); -v8::Handle Read(const v8::Arguments& args); -v8::Handle Load(const v8::Arguments& args); -v8::Handle Quit(const v8::Arguments& args); -v8::Handle Version(const v8::Arguments& args); +void Print(const v8::FunctionCallbackInfo& args); +void Read(const v8::FunctionCallbackInfo& args); +void Load(const v8::FunctionCallbackInfo& args); +void Quit(const v8::FunctionCallbackInfo& args); +void Version(const v8::FunctionCallbackInfo& args); v8::Handle ReadFile(const char* name); void ReportException(v8::Isolate* isolate, v8::TryCatch* handler); @@ -116,7 +116,7 @@ v8::Handle CreateShellContext(v8::Isolate* isolate) { // The callback that is invoked by v8 whenever the JavaScript 'print' // function is called. Prints its arguments on stdout separated by // spaces and ending with a newline. -v8::Handle Print(const v8::Arguments& args) { +void Print(const v8::FunctionCallbackInfo& args) { bool first = true; for (int i = 0; i < args.Length(); i++) { v8::HandleScope handle_scope(args.GetIsolate()); @@ -131,70 +131,73 @@ v8::Handle Print(const v8::Arguments& args) { } printf("\n"); fflush(stdout); - return v8::Undefined(); } // The callback that is invoked by v8 whenever the JavaScript 'read' // function is called. This function loads the content of the file named in // the argument into a JavaScript string. -v8::Handle Read(const v8::Arguments& args) { +void Read(const v8::FunctionCallbackInfo& args) { if (args.Length() != 1) { - return v8::ThrowException(v8::String::New("Bad parameters")); + v8::ThrowException(v8::String::New("Bad parameters")); + return; } v8::String::Utf8Value file(args[0]); if (*file == NULL) { - return v8::ThrowException(v8::String::New("Error loading file")); + v8::ThrowException(v8::String::New("Error loading file")); + return; } v8::Handle source = ReadFile(*file); if (source.IsEmpty()) { - return v8::ThrowException(v8::String::New("Error loading file")); + v8::ThrowException(v8::String::New("Error loading file")); + return; } - return source; + args.GetReturnValue().Set(source); } // The callback that is invoked by v8 whenever the JavaScript 'load' // function is called. Loads, compiles and executes its argument // JavaScript file. -v8::Handle Load(const v8::Arguments& args) { +void Load(const v8::FunctionCallbackInfo& args) { for (int i = 0; i < args.Length(); i++) { v8::HandleScope handle_scope(args.GetIsolate()); v8::String::Utf8Value file(args[i]); if (*file == NULL) { - return v8::ThrowException(v8::String::New("Error loading file")); + v8::ThrowException(v8::String::New("Error loading file")); + return; } v8::Handle source = ReadFile(*file); if (source.IsEmpty()) { - return v8::ThrowException(v8::String::New("Error loading file")); + v8::ThrowException(v8::String::New("Error loading file")); + return; } if (!ExecuteString(args.GetIsolate(), source, v8::String::New(*file), false, false)) { - return v8::ThrowException(v8::String::New("Error executing file")); + v8::ThrowException(v8::String::New("Error executing file")); + return; } } - return v8::Undefined(); } // The callback that is invoked by v8 whenever the JavaScript 'quit' // function is called. Quits. -v8::Handle Quit(const v8::Arguments& args) { +void Quit(const v8::FunctionCallbackInfo& args) { // If not arguments are given args[0] will yield undefined which // converts to the integer value 0. int exit_code = args[0]->Int32Value(); fflush(stdout); fflush(stderr); exit(exit_code); - return v8::Undefined(); } -v8::Handle Version(const v8::Arguments& args) { - return v8::String::New(v8::V8::GetVersion()); +void Version(const v8::FunctionCallbackInfo& args) { + args.GetReturnValue().Set(v8::String::New(v8::V8::GetVersion())); } diff --git a/src/accessors.cc b/src/accessors.cc index 202a5170d..e441de47e 100644 --- a/src/accessors.cc +++ b/src/accessors.cc @@ -793,9 +793,9 @@ const AccessorDescriptor Accessors::FunctionCaller = { // Accessors::MakeModuleExport // -static v8::Handle ModuleGetExport( +static void ModuleGetExport( v8::Local property, - const v8::AccessorInfo& info) { + const v8::PropertyCallbackInfo& info) { JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder())); Context* context = Context::cast(instance->context()); ASSERT(context->IsModuleContext()); @@ -807,16 +807,16 @@ static v8::Handle ModuleGetExport( isolate->ScheduleThrow( *isolate->factory()->NewReferenceError("not_defined", HandleVector(&name, 1))); - return v8::Handle(); + return; } - return v8::Utils::ToLocal(Handle(value, isolate)); + info.GetReturnValue().Set(v8::Utils::ToLocal(Handle(value, isolate))); } static void ModuleSetExport( v8::Local property, v8::Local value, - const v8::AccessorInfo& info) { + const v8::PropertyCallbackInfo& info) { JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder())); Context* context = Context::cast(instance->context()); ASSERT(context->IsModuleContext()); diff --git a/src/api.cc b/src/api.cc index 5b6b6446a..b2dc2e1e9 100644 --- a/src/api.cc +++ b/src/api.cc @@ -1214,7 +1214,7 @@ static void FunctionTemplateSetCallHandler(FunctionTemplate* function_template, isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); i::Handle obj = i::Handle::cast(struct_obj); - InvocationCallback callback = + FunctionCallback callback = i::CallbackTable::Register(isolate, callback_in); SET_FIELD_WRAPPED(obj, set_callback, callback); if (data.IsEmpty()) data = v8::Undefined(); @@ -1262,9 +1262,11 @@ static i::Handle MakeAccessorInfo( i::Isolate* isolate = Utils::OpenHandle(*name)->GetIsolate(); i::Handle obj = isolate->factory()->NewExecutableAccessorInfo(); - AccessorGetter getter = i::CallbackTable::Register(isolate, getter_in); + AccessorGetterCallback getter = + i::CallbackTable::Register(isolate, getter_in); SET_FIELD_WRAPPED(obj, set_getter, getter); - AccessorSetter setter = i::CallbackTable::Register(isolate, setter_in); + AccessorSetterCallback setter = + i::CallbackTable::Register(isolate, setter_in); SET_FIELD_WRAPPED(obj, set_setter, setter); if (data.IsEmpty()) data = v8::Undefined(); obj->set_data(*Utils::OpenHandle(*data)); @@ -1367,16 +1369,19 @@ static void SetNamedInstancePropertyHandler( i::Handle obj = i::Handle::cast(struct_obj); - NamedPropertyGetter getter = i::CallbackTable::Register(isolate, getter_in); + NamedPropertyGetterCallback getter = + i::CallbackTable::Register(isolate, getter_in); if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter); - NamedPropertySetter setter = i::CallbackTable::Register(isolate, setter_in); + NamedPropertySetterCallback setter = + i::CallbackTable::Register(isolate, setter_in); if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter); - NamedPropertyQuery query = i::CallbackTable::Register(isolate, query_in); + NamedPropertyQueryCallback query = + i::CallbackTable::Register(isolate, query_in); if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query); - NamedPropertyDeleter remover = + NamedPropertyDeleterCallback remover = i::CallbackTable::Register(isolate, remover_in); if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover); - NamedPropertyEnumerator enumerator = + NamedPropertyEnumeratorCallback enumerator = i::CallbackTable::Register(isolate, enumerator_in); if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator); @@ -1412,18 +1417,19 @@ static void SetIndexedInstancePropertyHandler( i::Handle obj = i::Handle::cast(struct_obj); - IndexedPropertyGetter getter = + IndexedPropertyGetterCallback getter = i::CallbackTable::Register(isolate, getter_in); if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter); - IndexedPropertySetter setter = + IndexedPropertySetterCallback setter = i::CallbackTable::Register(isolate, setter_in); if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter); - IndexedPropertyQuery query = i::CallbackTable::Register(isolate, query_in); + IndexedPropertyQueryCallback query = + i::CallbackTable::Register(isolate, query_in); if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query); - IndexedPropertyDeleter remover = + IndexedPropertyDeleterCallback remover = i::CallbackTable::Register(isolate, remover_in); if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover); - IndexedPropertyEnumerator enumerator = + IndexedPropertyEnumeratorCallback enumerator = i::CallbackTable::Register(isolate, enumerator_in); if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator); @@ -1449,7 +1455,7 @@ static void SetInstanceCallAsFunctionHandler( isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); i::Handle obj = i::Handle::cast(struct_obj); - InvocationCallback callback = + FunctionCallback callback = i::CallbackTable::Register(isolate, callback_in); SET_FIELD_WRAPPED(obj, set_callback, callback); if (data.IsEmpty()) data = v8::Undefined(); diff --git a/src/arguments.h b/src/arguments.h index a80b61361..e13ddc9ec 100644 --- a/src/arguments.h +++ b/src/arguments.h @@ -152,8 +152,7 @@ class Arguments BASE_EMBEDDED { // TODO(dcarney): Remove this class when old callbacks are gone. class CallbackTable { public: - // TODO(dcarney): Flip this when it makes sense for performance. - static const bool kStoreVoidFunctions = true; + static const bool kStoreVoidFunctions = false; static inline bool ReturnsVoid(Isolate* isolate, void* function) { CallbackTable* table = isolate->callback_table(); bool contains = @@ -171,13 +170,13 @@ class CallbackTable { } #define WRITE_REGISTER(OldFunction, NewFunction) \ - static OldFunction Register(Isolate* isolate, NewFunction f) { \ - InsertCallback(isolate, FunctionToVoidPtr(f), true); \ - return reinterpret_cast(f); \ + static NewFunction Register(Isolate* isolate, OldFunction f) { \ + InsertCallback(isolate, FunctionToVoidPtr(f), false); \ + return reinterpret_cast(f); \ } \ \ - static OldFunction Register(Isolate* isolate, OldFunction f) { \ - InsertCallback(isolate, FunctionToVoidPtr(f), false); \ + static NewFunction Register(Isolate* isolate, NewFunction f) { \ + InsertCallback(isolate, FunctionToVoidPtr(f), true); \ return f; \ } FOR_EACH_CALLBACK_TABLE_MAPPING(WRITE_REGISTER) diff --git a/src/d8-posix.cc b/src/d8-posix.cc index 1be782a24..424dbbb39 100644 --- a/src/d8-posix.cc +++ b/src/d8-posix.cc @@ -238,7 +238,7 @@ class ExecArgs { // Gets the optional timeouts from the arguments to the system() call. -static bool GetTimeouts(const Arguments& args, +static bool GetTimeouts(const v8::FunctionCallbackInfo& args, int* read_timeout, int* total_timeout) { if (args.Length() > 3) { @@ -448,25 +448,28 @@ static bool WaitForChild(int pid, // Implementation of the system() function (see d8.h for details). -Handle Shell::System(const Arguments& args) { +void Shell::System(const v8::FunctionCallbackInfo& args) { HandleScope scope(args.GetIsolate()); int read_timeout = -1; int total_timeout = -1; - if (!GetTimeouts(args, &read_timeout, &total_timeout)) return v8::Undefined(); + if (!GetTimeouts(args, &read_timeout, &total_timeout)) return; Handle command_args; if (args.Length() > 1) { if (!args[1]->IsArray()) { - return ThrowException(String::New("system: Argument 2 must be an array")); + ThrowException(String::New("system: Argument 2 must be an array")); + return; } command_args = Handle::Cast(args[1]); } else { command_args = Array::New(0); } if (command_args->Length() > ExecArgs::kMaxArgs) { - return ThrowException(String::New("Too many arguments to system()")); + ThrowException(String::New("Too many arguments to system()")); + return; } if (args.Length() < 1) { - return ThrowException(String::New("Too few arguments to system()")); + ThrowException(String::New("Too few arguments to system()")); + return; } struct timeval start_time; @@ -474,16 +477,18 @@ Handle Shell::System(const Arguments& args) { ExecArgs exec_args; if (!exec_args.Init(args[0], command_args)) { - return v8::Undefined(); + return; } int exec_error_fds[2]; int stdout_fds[2]; if (pipe(exec_error_fds) != 0) { - return ThrowException(String::New("pipe syscall failed.")); + ThrowException(String::New("pipe syscall failed.")); + return; } if (pipe(stdout_fds) != 0) { - return ThrowException(String::New("pipe syscall failed.")); + ThrowException(String::New("pipe syscall failed.")); + return; } pid_t pid = fork(); @@ -499,7 +504,7 @@ Handle Shell::System(const Arguments& args) { OpenFDCloser error_read_closer(exec_error_fds[kReadFD]); OpenFDCloser stdout_read_closer(stdout_fds[kReadFD]); - if (!ChildLaunchedOK(exec_error_fds)) return v8::Undefined(); + if (!ChildLaunchedOK(exec_error_fds)) return; Handle accumulator = GetStdout(stdout_fds[kReadFD], start_time, @@ -507,7 +512,8 @@ Handle Shell::System(const Arguments& args) { total_timeout); if (accumulator->IsUndefined()) { kill(pid, SIGINT); // On timeout, kill the subprocess. - return accumulator; + args.GetReturnValue().Set(accumulator); + return; } if (!WaitForChild(pid, @@ -515,42 +521,47 @@ Handle Shell::System(const Arguments& args) { start_time, read_timeout, total_timeout)) { - return v8::Undefined(); + return; } - return scope.Close(accumulator); + args.GetReturnValue().Set(accumulator); } -Handle Shell::ChangeDirectory(const Arguments& args) { +void Shell::ChangeDirectory(const v8::FunctionCallbackInfo& args) { if (args.Length() != 1) { const char* message = "chdir() takes one argument"; - return ThrowException(String::New(message)); + ThrowException(String::New(message)); + return; } String::Utf8Value directory(args[0]); if (*directory == NULL) { const char* message = "os.chdir(): String conversion of argument failed."; - return ThrowException(String::New(message)); + ThrowException(String::New(message)); + return; } if (chdir(*directory) != 0) { - return ThrowException(String::New(strerror(errno))); + ThrowException(String::New(strerror(errno))); + return; } - return v8::Undefined(); } -Handle Shell::SetUMask(const Arguments& args) { +void Shell::SetUMask(const v8::FunctionCallbackInfo& args) { if (args.Length() != 1) { const char* message = "umask() takes one argument"; - return ThrowException(String::New(message)); + ThrowException(String::New(message)); + return; } if (args[0]->IsNumber()) { mode_t mask = args[0]->Int32Value(); int previous = umask(mask); - return Number::New(previous); + args.GetReturnValue().Set(previous); + return; } else { const char* message = "umask() argument must be numeric"; - return ThrowException(String::New(message)); + ThrowException(String::New(message)); + return; } } @@ -598,79 +609,85 @@ static bool mkdirp(char* directory, mode_t mask) { } -Handle Shell::MakeDirectory(const Arguments& args) { +void Shell::MakeDirectory(const v8::FunctionCallbackInfo& args) { mode_t mask = 0777; if (args.Length() == 2) { if (args[1]->IsNumber()) { mask = args[1]->Int32Value(); } else { const char* message = "mkdirp() second argument must be numeric"; - return ThrowException(String::New(message)); + ThrowException(String::New(message)); + return; } } else if (args.Length() != 1) { const char* message = "mkdirp() takes one or two arguments"; - return ThrowException(String::New(message)); + ThrowException(String::New(message)); + return; } String::Utf8Value directory(args[0]); if (*directory == NULL) { const char* message = "os.mkdirp(): String conversion of argument failed."; - return ThrowException(String::New(message)); + ThrowException(String::New(message)); + return; } mkdirp(*directory, mask); - return v8::Undefined(); } -Handle Shell::RemoveDirectory(const Arguments& args) { +void Shell::RemoveDirectory(const v8::FunctionCallbackInfo& args) { if (args.Length() != 1) { const char* message = "rmdir() takes one or two arguments"; - return ThrowException(String::New(message)); + ThrowException(String::New(message)); + return; } String::Utf8Value directory(args[0]); if (*directory == NULL) { const char* message = "os.rmdir(): String conversion of argument failed."; - return ThrowException(String::New(message)); + ThrowException(String::New(message)); + return; } rmdir(*directory); - return v8::Undefined(); } -Handle Shell::SetEnvironment(const Arguments& args) { +void Shell::SetEnvironment(const v8::FunctionCallbackInfo& args) { if (args.Length() != 2) { const char* message = "setenv() takes two arguments"; - return ThrowException(String::New(message)); + ThrowException(String::New(message)); + return; } String::Utf8Value var(args[0]); String::Utf8Value value(args[1]); if (*var == NULL) { const char* message = "os.setenv(): String conversion of variable name failed."; - return ThrowException(String::New(message)); + ThrowException(String::New(message)); + return; } if (*value == NULL) { const char* message = "os.setenv(): String conversion of variable contents failed."; - return ThrowException(String::New(message)); + ThrowException(String::New(message)); + return; } setenv(*var, *value, 1); - return v8::Undefined(); } -Handle Shell::UnsetEnvironment(const Arguments& args) { +void Shell::UnsetEnvironment(const v8::FunctionCallbackInfo& args) { if (args.Length() != 1) { const char* message = "unsetenv() takes one argument"; - return ThrowException(String::New(message)); + ThrowException(String::New(message)); + return; } String::Utf8Value var(args[0]); if (*var == NULL) { const char* message = "os.setenv(): String conversion of variable name failed."; - return ThrowException(String::New(message)); + ThrowException(String::New(message)); + return; } unsetenv(*var); - return v8::Undefined(); } diff --git a/src/d8.cc b/src/d8.cc index e78f56811..57e0c0424 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -287,46 +287,49 @@ int PerIsolateData::RealmFind(Handle context) { // Realm.current() returns the index of the currently active realm. -Handle Shell::RealmCurrent(const Arguments& args) { +void Shell::RealmCurrent(const v8::FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); PerIsolateData* data = PerIsolateData::Get(isolate); int index = data->RealmFind(Context::GetEntered()); - if (index == -1) return Undefined(isolate); - return Number::New(index); + if (index == -1) return; + args.GetReturnValue().Set(index); } // Realm.owner(o) returns the index of the realm that created o. -Handle Shell::RealmOwner(const Arguments& args) { +void Shell::RealmOwner(const v8::FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); PerIsolateData* data = PerIsolateData::Get(isolate); if (args.Length() < 1 || !args[0]->IsObject()) { - return Throw("Invalid argument"); + Throw("Invalid argument"); + return; } int index = data->RealmFind(args[0]->ToObject()->CreationContext()); - if (index == -1) return Undefined(isolate); - return Number::New(index); + if (index == -1) return; + args.GetReturnValue().Set(index); } // Realm.global(i) returns the global object of realm i. // (Note that properties of global objects cannot be read/written cross-realm.) -Handle Shell::RealmGlobal(const Arguments& args) { +void Shell::RealmGlobal(const v8::FunctionCallbackInfo& args) { PerIsolateData* data = PerIsolateData::Get(args.GetIsolate()); if (args.Length() < 1 || !args[0]->IsNumber()) { - return Throw("Invalid argument"); + Throw("Invalid argument"); + return; } int index = args[0]->Uint32Value(); if (index >= data->realm_count_ || data->realms_[index].IsEmpty()) { - return Throw("Invalid realm index"); + Throw("Invalid realm index"); + return; } - return - Local::New(args.GetIsolate(), data->realms_[index])->Global(); + args.GetReturnValue().Set( + Local::New(args.GetIsolate(), data->realms_[index])->Global()); } // Realm.create() creates a new realm and returns its index. -Handle Shell::RealmCreate(const Arguments& args) { +void Shell::RealmCreate(const v8::FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); PerIsolateData* data = PerIsolateData::Get(isolate); Persistent* old_realms = data->realms_; @@ -339,78 +342,82 @@ Handle Shell::RealmCreate(const Arguments& args) { Handle global_template = CreateGlobalTemplate(isolate); data->realms_[index].Reset( isolate, Context::New(isolate, NULL, global_template)); - return Number::New(index); + args.GetReturnValue().Set(index); } // Realm.dispose(i) disposes the reference to the realm i. -Handle Shell::RealmDispose(const Arguments& args) { +void Shell::RealmDispose(const v8::FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); PerIsolateData* data = PerIsolateData::Get(isolate); if (args.Length() < 1 || !args[0]->IsNumber()) { - return Throw("Invalid argument"); + Throw("Invalid argument"); + return; } int index = args[0]->Uint32Value(); if (index >= data->realm_count_ || data->realms_[index].IsEmpty() || index == 0 || index == data->realm_current_ || index == data->realm_switch_) { - return Throw("Invalid realm index"); + Throw("Invalid realm index"); + return; } data->realms_[index].Dispose(isolate); data->realms_[index].Clear(); - return Undefined(isolate); } // Realm.switch(i) switches to the realm i for consecutive interactive inputs. -Handle Shell::RealmSwitch(const Arguments& args) { +void Shell::RealmSwitch(const v8::FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); PerIsolateData* data = PerIsolateData::Get(isolate); if (args.Length() < 1 || !args[0]->IsNumber()) { - return Throw("Invalid argument"); + Throw("Invalid argument"); + return; } int index = args[0]->Uint32Value(); if (index >= data->realm_count_ || data->realms_[index].IsEmpty()) { - return Throw("Invalid realm index"); + Throw("Invalid realm index"); + return; } data->realm_switch_ = index; - return Undefined(isolate); } // Realm.eval(i, s) evaluates s in realm i and returns the result. -Handle Shell::RealmEval(const Arguments& args) { +void Shell::RealmEval(const v8::FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); PerIsolateData* data = PerIsolateData::Get(isolate); if (args.Length() < 2 || !args[0]->IsNumber() || !args[1]->IsString()) { - return Throw("Invalid argument"); + Throw("Invalid argument"); + return; } int index = args[0]->Uint32Value(); if (index >= data->realm_count_ || data->realms_[index].IsEmpty()) { - return Throw("Invalid realm index"); + Throw("Invalid realm index"); + return; } Handle