v8::Handle<v8::String> ReadFile(const char* name);
v8::Handle<v8::String> ReadLine();
-v8::Handle<v8::Value> Print(const v8::Arguments& args);
-v8::Handle<v8::Value> ReadLine(const v8::Arguments& args);
+void Print(const v8::FunctionCallbackInfo<v8::Value>& args);
+void ReadLine(const v8::FunctionCallbackInfo<v8::Value>& args);
bool RunCppCycle(v8::Handle<v8::Script> script,
v8::Local<v8::Context> context,
bool report_exceptions);
// 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<v8::Value> Print(const v8::Arguments& args) {
+void Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
bool first = true;
for (int i = 0; i < args.Length(); i++) {
v8::HandleScope handle_scope(args.GetIsolate());
}
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<v8::Value> ReadLine(const v8::Arguments& args) {
+void ReadLine(const v8::FunctionCallbackInfo<v8::Value>& 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<v8::String> ReadLine() {
static Handle<ObjectTemplate> MakeMapTemplate(Isolate* isolate);
// Callbacks that access the individual fields of request objects.
- static Handle<Value> GetPath(Local<String> name, const AccessorInfo& info);
- static Handle<Value> GetReferrer(Local<String> name,
- const AccessorInfo& info);
- static Handle<Value> GetHost(Local<String> name, const AccessorInfo& info);
- static Handle<Value> GetUserAgent(Local<String> name,
- const AccessorInfo& info);
+ static void GetPath(Local<String> name,
+ const PropertyCallbackInfo<Value>& info);
+ static void GetReferrer(Local<String> name,
+ const PropertyCallbackInfo<Value>& info);
+ static void GetHost(Local<String> name,
+ const PropertyCallbackInfo<Value>& info);
+ static void GetUserAgent(Local<String> name,
+ const PropertyCallbackInfo<Value>& info);
// Callbacks that access maps
- static Handle<Value> MapGet(Local<String> name, const AccessorInfo& info);
- static Handle<Value> MapSet(Local<String> name,
- Local<Value> value,
- const AccessorInfo& info);
+ static void MapGet(Local<String> name,
+ const PropertyCallbackInfo<Value>& info);
+ static void MapSet(Local<String> name,
+ Local<Value> value,
+ const PropertyCallbackInfo<Value>& info);
// Utility methods for wrapping C++ objects as JavaScript objects,
// and going back again.
// -------------------------
-static Handle<Value> LogCallback(const Arguments& args) {
- if (args.Length() < 1) return Undefined();
+static void LogCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
+ if (args.Length() < 1) return;
HandleScope scope(args.GetIsolate());
Handle<Value> arg = args[0];
String::Utf8Value value(arg);
HttpRequestProcessor::Log(*value);
- return Undefined();
}
}
-Handle<Value> JsHttpRequestProcessor::MapGet(Local<String> name,
- const AccessorInfo& info) {
+void JsHttpRequestProcessor::MapGet(Local<String> name,
+ const PropertyCallbackInfo<Value>& info) {
// Fetch the map wrapped by this object.
map<string, string>* obj = UnwrapMap(info.Holder());
map<string, string>::iterator iter = obj->find(key);
// If the key is not present return an empty handle as signal
- if (iter == obj->end()) return Handle<Value>();
+ 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<int>(value.length()));
+ info.GetReturnValue().Set(
+ String::New(value.c_str(), static_cast<int>(value.length())));
}
-Handle<Value> JsHttpRequestProcessor::MapSet(Local<String> name,
- Local<Value> value_obj,
- const AccessorInfo& info) {
+void JsHttpRequestProcessor::MapSet(Local<String> name,
+ Local<Value> value_obj,
+ const PropertyCallbackInfo<Value>& info) {
// Fetch the map wrapped by this object.
map<string, string>* obj = UnwrapMap(info.Holder());
(*obj)[key] = value;
// Return the value; any non-empty handle will work.
- return value_obj;
+ info.GetReturnValue().Set(value_obj);
}
}
-Handle<Value> JsHttpRequestProcessor::GetPath(Local<String> name,
- const AccessorInfo& info) {
+void JsHttpRequestProcessor::GetPath(Local<String> name,
+ const PropertyCallbackInfo<Value>& info) {
// Extract the C++ request object from the JavaScript wrapper.
HttpRequest* request = UnwrapRequest(info.Holder());
const string& path = request->Path();
// Wrap the result in a JavaScript string and return it.
- return String::New(path.c_str(), static_cast<int>(path.length()));
+ info.GetReturnValue().Set(
+ String::New(path.c_str(), static_cast<int>(path.length())));
}
-Handle<Value> JsHttpRequestProcessor::GetReferrer(Local<String> name,
- const AccessorInfo& info) {
+void JsHttpRequestProcessor::GetReferrer(
+ Local<String> name,
+ const PropertyCallbackInfo<Value>& info) {
HttpRequest* request = UnwrapRequest(info.Holder());
const string& path = request->Referrer();
- return String::New(path.c_str(), static_cast<int>(path.length()));
+ info.GetReturnValue().Set(
+ String::New(path.c_str(), static_cast<int>(path.length())));
}
-Handle<Value> JsHttpRequestProcessor::GetHost(Local<String> name,
- const AccessorInfo& info) {
+void JsHttpRequestProcessor::GetHost(Local<String> name,
+ const PropertyCallbackInfo<Value>& info) {
HttpRequest* request = UnwrapRequest(info.Holder());
const string& path = request->Host();
- return String::New(path.c_str(), static_cast<int>(path.length()));
+ info.GetReturnValue().Set(
+ String::New(path.c_str(), static_cast<int>(path.length())));
}
-Handle<Value> JsHttpRequestProcessor::GetUserAgent(Local<String> name,
- const AccessorInfo& info) {
+void JsHttpRequestProcessor::GetUserAgent(
+ Local<String> name,
+ const PropertyCallbackInfo<Value>& info) {
HttpRequest* request = UnwrapRequest(info.Holder());
const string& path = request->UserAgent();
- return String::New(path.c_str(), static_cast<int>(path.length()));
+ info.GetReturnValue().Set(
+ String::New(path.c_str(), static_cast<int>(path.length())));
}
v8::Handle<v8::Value> name,
bool print_result,
bool report_exceptions);
-v8::Handle<v8::Value> Print(const v8::Arguments& args);
-v8::Handle<v8::Value> Read(const v8::Arguments& args);
-v8::Handle<v8::Value> Load(const v8::Arguments& args);
-v8::Handle<v8::Value> Quit(const v8::Arguments& args);
-v8::Handle<v8::Value> Version(const v8::Arguments& args);
+void Print(const v8::FunctionCallbackInfo<v8::Value>& args);
+void Read(const v8::FunctionCallbackInfo<v8::Value>& args);
+void Load(const v8::FunctionCallbackInfo<v8::Value>& args);
+void Quit(const v8::FunctionCallbackInfo<v8::Value>& args);
+void Version(const v8::FunctionCallbackInfo<v8::Value>& args);
v8::Handle<v8::String> ReadFile(const char* name);
void ReportException(v8::Isolate* isolate, v8::TryCatch* handler);
// 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<v8::Value> Print(const v8::Arguments& args) {
+void Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
bool first = true;
for (int i = 0; i < args.Length(); i++) {
v8::HandleScope handle_scope(args.GetIsolate());
}
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<v8::Value> Read(const v8::Arguments& args) {
+void Read(const v8::FunctionCallbackInfo<v8::Value>& 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<v8::String> 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<v8::Value> Load(const v8::Arguments& args) {
+void Load(const v8::FunctionCallbackInfo<v8::Value>& 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<v8::String> 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<v8::Value> Quit(const v8::Arguments& args) {
+void Quit(const v8::FunctionCallbackInfo<v8::Value>& 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<v8::Value> Version(const v8::Arguments& args) {
- return v8::String::New(v8::V8::GetVersion());
+void Version(const v8::FunctionCallbackInfo<v8::Value>& args) {
+ args.GetReturnValue().Set(v8::String::New(v8::V8::GetVersion()));
}
// Accessors::MakeModuleExport
//
-static v8::Handle<v8::Value> ModuleGetExport(
+static void ModuleGetExport(
v8::Local<v8::String> property,
- const v8::AccessorInfo& info) {
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder()));
Context* context = Context::cast(instance->context());
ASSERT(context->IsModuleContext());
isolate->ScheduleThrow(
*isolate->factory()->NewReferenceError("not_defined",
HandleVector(&name, 1)));
- return v8::Handle<v8::Value>();
+ return;
}
- return v8::Utils::ToLocal(Handle<Object>(value, isolate));
+ info.GetReturnValue().Set(v8::Utils::ToLocal(Handle<Object>(value, isolate)));
}
static void ModuleSetExport(
v8::Local<v8::String> property,
v8::Local<v8::Value> value,
- const v8::AccessorInfo& info) {
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder()));
Context* context = Context::cast(instance->context());
ASSERT(context->IsModuleContext());
isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE);
i::Handle<i::CallHandlerInfo> obj =
i::Handle<i::CallHandlerInfo>::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();
i::Isolate* isolate = Utils::OpenHandle(*name)->GetIsolate();
i::Handle<i::ExecutableAccessorInfo> 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));
i::Handle<i::InterceptorInfo> obj =
i::Handle<i::InterceptorInfo>::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);
i::Handle<i::InterceptorInfo> obj =
i::Handle<i::InterceptorInfo>::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);
isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE);
i::Handle<i::CallHandlerInfo> obj =
i::Handle<i::CallHandlerInfo>::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();
// 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 =
}
#define WRITE_REGISTER(OldFunction, NewFunction) \
- static OldFunction Register(Isolate* isolate, NewFunction f) { \
- InsertCallback(isolate, FunctionToVoidPtr(f), true); \
- return reinterpret_cast<OldFunction>(f); \
+ static NewFunction Register(Isolate* isolate, OldFunction f) { \
+ InsertCallback(isolate, FunctionToVoidPtr(f), false); \
+ return reinterpret_cast<NewFunction>(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)
// Gets the optional timeouts from the arguments to the system() call.
-static bool GetTimeouts(const Arguments& args,
+static bool GetTimeouts(const v8::FunctionCallbackInfo<v8::Value>& args,
int* read_timeout,
int* total_timeout) {
if (args.Length() > 3) {
// Implementation of the system() function (see d8.h for details).
-Handle<Value> Shell::System(const Arguments& args) {
+void Shell::System(const v8::FunctionCallbackInfo<v8::Value>& 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<Array> 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<Array>::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;
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();
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<Value> accumulator = GetStdout(stdout_fds[kReadFD],
start_time,
total_timeout);
if (accumulator->IsUndefined()) {
kill(pid, SIGINT); // On timeout, kill the subprocess.
- return accumulator;
+ args.GetReturnValue().Set(accumulator);
+ return;
}
if (!WaitForChild(pid,
start_time,
read_timeout,
total_timeout)) {
- return v8::Undefined();
+ return;
}
- return scope.Close(accumulator);
+ args.GetReturnValue().Set(accumulator);
}
-Handle<Value> Shell::ChangeDirectory(const Arguments& args) {
+void Shell::ChangeDirectory(const v8::FunctionCallbackInfo<v8::Value>& 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<Value> Shell::SetUMask(const Arguments& args) {
+void Shell::SetUMask(const v8::FunctionCallbackInfo<v8::Value>& 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;
}
}
}
-Handle<Value> Shell::MakeDirectory(const Arguments& args) {
+void Shell::MakeDirectory(const v8::FunctionCallbackInfo<v8::Value>& 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<Value> Shell::RemoveDirectory(const Arguments& args) {
+void Shell::RemoveDirectory(const v8::FunctionCallbackInfo<v8::Value>& 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<Value> Shell::SetEnvironment(const Arguments& args) {
+void Shell::SetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& 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<Value> Shell::UnsetEnvironment(const Arguments& args) {
+void Shell::UnsetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& 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();
}
// Realm.current() returns the index of the currently active realm.
-Handle<Value> Shell::RealmCurrent(const Arguments& args) {
+void Shell::RealmCurrent(const v8::FunctionCallbackInfo<v8::Value>& 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<Value> Shell::RealmOwner(const Arguments& args) {
+void Shell::RealmOwner(const v8::FunctionCallbackInfo<v8::Value>& 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<Value> Shell::RealmGlobal(const Arguments& args) {
+void Shell::RealmGlobal(const v8::FunctionCallbackInfo<v8::Value>& 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<Context>::New(args.GetIsolate(), data->realms_[index])->Global();
+ args.GetReturnValue().Set(
+ Local<Context>::New(args.GetIsolate(), data->realms_[index])->Global());
}
// Realm.create() creates a new realm and returns its index.
-Handle<Value> Shell::RealmCreate(const Arguments& args) {
+void Shell::RealmCreate(const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate();
PerIsolateData* data = PerIsolateData::Get(isolate);
Persistent<Context>* old_realms = data->realms_;
Handle<ObjectTemplate> 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<Value> Shell::RealmDispose(const Arguments& args) {
+void Shell::RealmDispose(const v8::FunctionCallbackInfo<v8::Value>& 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<Value> Shell::RealmSwitch(const Arguments& args) {
+void Shell::RealmSwitch(const v8::FunctionCallbackInfo<v8::Value>& 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<Value> Shell::RealmEval(const Arguments& args) {
+void Shell::RealmEval(const v8::FunctionCallbackInfo<v8::Value>& 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<Script> script = Script::New(args[1]->ToString());
- if (script.IsEmpty()) return Undefined(isolate);
+ if (script.IsEmpty()) return;
Local<Context> realm = Local<Context>::New(isolate, data->realms_[index]);
realm->Enter();
Handle<Value> result = script->Run();
realm->Exit();
- return result;
+ args.GetReturnValue().Set(result);
}
// Realm.shared is an accessor for a single shared value across realms.
-Handle<Value> Shell::RealmSharedGet(Local<String> property,
- const AccessorInfo& info) {
+void Shell::RealmSharedGet(Local<String> property,
+ const PropertyCallbackInfo<Value>& info) {
Isolate* isolate = info.GetIsolate();
PerIsolateData* data = PerIsolateData::Get(isolate);
- if (data->realm_shared_.IsEmpty()) return Undefined(isolate);
- return Local<Value>::New(isolate, data->realm_shared_);
+ if (data->realm_shared_.IsEmpty()) return;
+ info.GetReturnValue().Set(data->realm_shared_);
}
void Shell::RealmSharedSet(Local<String> property,
Local<Value> value,
- const AccessorInfo& info) {
+ const PropertyCallbackInfo<void>& info) {
Isolate* isolate = info.GetIsolate();
PerIsolateData* data = PerIsolateData::Get(isolate);
if (!data->realm_shared_.IsEmpty()) data->realm_shared_.Dispose(isolate);
}
-Handle<Value> Shell::Print(const Arguments& args) {
- Handle<Value> val = Write(args);
+void Shell::Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
+ Write(args);
printf("\n");
fflush(stdout);
- return val;
}
-Handle<Value> Shell::Write(const Arguments& args) {
+void Shell::Write(const v8::FunctionCallbackInfo<v8::Value>& args) {
for (int i = 0; i < args.Length(); i++) {
HandleScope handle_scope(args.GetIsolate());
if (i != 0) {
// Explicitly catch potential exceptions in toString().
v8::TryCatch try_catch;
Handle<String> str_obj = args[i]->ToString();
- if (try_catch.HasCaught()) return try_catch.ReThrow();
+ if (try_catch.HasCaught()) {
+ try_catch.ReThrow();
+ return;
+ }
v8::String::Utf8Value str(str_obj);
int n = static_cast<int>(fwrite(*str, sizeof(**str), str.length(), stdout));
Exit(1);
}
}
- return Undefined(args.GetIsolate());
}
-Handle<Value> Shell::EnableProfiler(const Arguments& args) {
+void Shell::EnableProfiler(const v8::FunctionCallbackInfo<v8::Value>& args) {
V8::ResumeProfiler();
- return Undefined(args.GetIsolate());
}
-Handle<Value> Shell::DisableProfiler(const Arguments& args) {
+void Shell::DisableProfiler(const v8::FunctionCallbackInfo<v8::Value>& args) {
V8::PauseProfiler();
- return Undefined(args.GetIsolate());
}
-Handle<Value> Shell::Read(const Arguments& args) {
+void Shell::Read(const v8::FunctionCallbackInfo<v8::Value>& args) {
String::Utf8Value file(args[0]);
if (*file == NULL) {
- return Throw("Error loading file");
+ Throw("Error loading file");
+ return;
}
Handle<String> source = ReadFile(args.GetIsolate(), *file);
if (source.IsEmpty()) {
- return Throw("Error loading file");
+ Throw("Error loading file");
+ return;
}
- return source;
+ args.GetReturnValue().Set(source);
}
}
-Handle<Value> Shell::Load(const Arguments& args) {
+void Shell::Load(const v8::FunctionCallbackInfo<v8::Value>& args) {
for (int i = 0; i < args.Length(); i++) {
HandleScope handle_scope(args.GetIsolate());
String::Utf8Value file(args[i]);
if (*file == NULL) {
- return Throw("Error loading file");
+ Throw("Error loading file");
+ return;
}
Handle<String> source = ReadFile(args.GetIsolate(), *file);
if (source.IsEmpty()) {
- return Throw("Error loading file");
+ Throw("Error loading file");
+ return;
}
if (!ExecuteString(args.GetIsolate(),
source,
String::New(*file),
false,
true)) {
- return Throw("Error executing file");
+ Throw("Error executing file");
+ return;
}
}
- return Undefined(args.GetIsolate());
}
-Handle<Value> Shell::Quit(const Arguments& args) {
+void Shell::Quit(const v8::FunctionCallbackInfo<v8::Value>& args) {
int exit_code = args[0]->Int32Value();
OnExit();
exit(exit_code);
- return Undefined(args.GetIsolate());
}
-Handle<Value> Shell::Version(const Arguments& args) {
- return String::New(V8::GetVersion());
+void Shell::Version(const v8::FunctionCallbackInfo<v8::Value>& args) {
+ args.GetReturnValue().Set(String::New(V8::GetVersion()));
}
object->Dispose(isolate);
}
-Handle<Value> Shell::ReadBuffer(const Arguments& args) {
+void Shell::ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args) {
ASSERT(sizeof(char) == sizeof(uint8_t)); // NOLINT
String::Utf8Value filename(args[0]);
int length;
if (*filename == NULL) {
- return Throw("Error loading file");
+ Throw("Error loading file");
+ return;
}
Isolate* isolate = args.GetIsolate();
uint8_t* data = reinterpret_cast<uint8_t*>(
ReadChars(args.GetIsolate(), *filename, &length));
if (data == NULL) {
- return Throw("Error reading file");
+ Throw("Error reading file");
+ return;
}
Handle<v8::ArrayBuffer> buffer = ArrayBuffer::New(data, length);
v8::Persistent<v8::Value> weak_handle(isolate, buffer);
weak_handle.MarkIndependent();
isolate->AdjustAmountOfExternalAllocatedMemory(length);
- return buffer;
+ args.GetReturnValue().Set(buffer);
}
#endif // ENABLE_DEBUGGER_SUPPORT
#endif // V8_SHARED
- static Handle<Value> RealmCurrent(const Arguments& args);
- static Handle<Value> RealmOwner(const Arguments& args);
- static Handle<Value> RealmGlobal(const Arguments& args);
- static Handle<Value> RealmCreate(const Arguments& args);
- static Handle<Value> RealmDispose(const Arguments& args);
- static Handle<Value> RealmSwitch(const Arguments& args);
- static Handle<Value> RealmEval(const Arguments& args);
- static Handle<Value> RealmSharedGet(Local<String> property,
- const AccessorInfo& info);
+ static void RealmCurrent(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void RealmOwner(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void RealmGlobal(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void RealmCreate(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void RealmDispose(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void RealmSwitch(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void RealmEval(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void RealmSharedGet(Local<String> property,
+ const PropertyCallbackInfo<Value>& info);
static void RealmSharedSet(Local<String> property,
Local<Value> value,
- const AccessorInfo& info);
-
- static Handle<Value> Print(const Arguments& args);
- static Handle<Value> Write(const Arguments& args);
- static Handle<Value> Quit(const Arguments& args);
- static Handle<Value> Version(const Arguments& args);
- static Handle<Value> EnableProfiler(const Arguments& args);
- static Handle<Value> DisableProfiler(const Arguments& args);
- static Handle<Value> Read(const Arguments& args);
- static Handle<Value> ReadBuffer(const Arguments& args);
+ const PropertyCallbackInfo<void>& info);
+
+ static void Print(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void Write(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void Quit(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void Version(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void EnableProfiler(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void DisableProfiler(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void Read(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args);
static Handle<String> ReadFromStdin(Isolate* isolate);
- static Handle<Value> ReadLine(const Arguments& args) {
- return ReadFromStdin(args.GetIsolate());
+ static void ReadLine(const v8::FunctionCallbackInfo<v8::Value>& args) {
+ args.GetReturnValue().Set(ReadFromStdin(args.GetIsolate()));
}
- static Handle<Value> Load(const Arguments& args);
- static Handle<Value> ArrayBuffer(const Arguments& args);
- static Handle<Value> Int8Array(const Arguments& args);
- static Handle<Value> Uint8Array(const Arguments& args);
- static Handle<Value> Int16Array(const Arguments& args);
- static Handle<Value> Uint16Array(const Arguments& args);
- static Handle<Value> Int32Array(const Arguments& args);
- static Handle<Value> Uint32Array(const Arguments& args);
- static Handle<Value> Float32Array(const Arguments& args);
- static Handle<Value> Float64Array(const Arguments& args);
- static Handle<Value> Uint8ClampedArray(const Arguments& args);
- static Handle<Value> ArrayBufferSlice(const Arguments& args);
- static Handle<Value> ArraySubArray(const Arguments& args);
- static Handle<Value> ArraySet(const Arguments& args);
+ static void Load(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void ArrayBuffer(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void Int8Array(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void Uint8Array(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void Int16Array(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void Uint16Array(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void Int32Array(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void Uint32Array(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void Float32Array(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void Float64Array(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void Uint8ClampedArray(
+ const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void ArrayBufferSlice(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void ArraySubArray(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void ArraySet(const v8::FunctionCallbackInfo<v8::Value>& args);
// The OS object on the global object contains methods for performing
// operating system calls:
//
// with the current umask. Intermediate directories are created if necessary.
// An exception is not thrown if the directory already exists. Analogous to
// the "mkdir -p" command.
- static Handle<Value> OSObject(const Arguments& args);
- static Handle<Value> System(const Arguments& args);
- static Handle<Value> ChangeDirectory(const Arguments& args);
- static Handle<Value> SetEnvironment(const Arguments& args);
- static Handle<Value> UnsetEnvironment(const Arguments& args);
- static Handle<Value> SetUMask(const Arguments& args);
- static Handle<Value> MakeDirectory(const Arguments& args);
- static Handle<Value> RemoveDirectory(const Arguments& args);
+ static void OSObject(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void System(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void ChangeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void SetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void UnsetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void MakeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void RemoveDirectory(const v8::FunctionCallbackInfo<v8::Value>& args);
static void AddOSMethods(Handle<ObjectTemplate> os_template);
int32_t byteLength,
int32_t byteOffset,
int32_t element_size);
- static Handle<Value> CreateExternalArray(const Arguments& args,
- ExternalArrayType type,
- int32_t element_size);
+ static void CreateExternalArray(
+ const v8::FunctionCallbackInfo<v8::Value>& args,
+ ExternalArrayType type,
+ int32_t element_size);
static void ExternalArrayWeakCallback(Isolate* isolate,
Persistent<Object>* object,
uint8_t* data);
}
-v8::Handle<v8::Value> ExternalizeStringExtension::Externalize(
- const v8::Arguments& args) {
+void ExternalizeStringExtension::Externalize(
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() < 1 || !args[0]->IsString()) {
- return v8::ThrowException(v8::String::New(
+ v8::ThrowException(v8::String::New(
"First parameter to externalizeString() must be a string."));
+ return;
}
bool force_two_byte = false;
if (args.Length() >= 2) {
if (args[1]->IsBoolean()) {
force_two_byte = args[1]->BooleanValue();
} else {
- return v8::ThrowException(v8::String::New(
- "Second parameter to externalizeString() must be a boolean."));
+ v8::ThrowException(v8::String::New(
+ "Second parameter to externalizeString() must be a boolean."));
+ return;
}
}
bool result = false;
Handle<String> string = Utils::OpenHandle(*args[0].As<v8::String>());
if (string->IsExternalString()) {
- return v8::ThrowException(v8::String::New(
+ v8::ThrowException(v8::String::New(
"externalizeString() can't externalize twice."));
+ return;
}
if (string->IsOneByteRepresentation() && !force_two_byte) {
uint8_t* data = new uint8_t[string->length()];
if (!result) delete resource;
}
if (!result) {
- return v8::ThrowException(v8::String::New("externalizeString() failed."));
+ v8::ThrowException(v8::String::New("externalizeString() failed."));
+ return;
}
- return v8::Undefined();
}
-v8::Handle<v8::Value> ExternalizeStringExtension::IsAscii(
- const v8::Arguments& args) {
+void ExternalizeStringExtension::IsAscii(
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 1 || !args[0]->IsString()) {
- return v8::ThrowException(v8::String::New(
+ v8::ThrowException(v8::String::New(
"isAsciiString() requires a single string argument."));
+ return;
}
- return
- Utils::OpenHandle(*args[0].As<v8::String>())->IsOneByteRepresentation() ?
- v8::True() : v8::False();
+ bool is_one_byte =
+ Utils::OpenHandle(*args[0].As<v8::String>())->IsOneByteRepresentation();
+ args.GetReturnValue().Set(is_one_byte);
}
ExternalizeStringExtension() : v8::Extension("v8/externalize", kSource) {}
virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
v8::Handle<v8::String> name);
- static v8::Handle<v8::Value> Externalize(const v8::Arguments& args);
- static v8::Handle<v8::Value> IsAscii(const v8::Arguments& args);
+ static void Externalize(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void IsAscii(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Register();
private:
static const char* const kSource;
}
-v8::Handle<v8::Value> GCExtension::GC(const v8::Arguments& args) {
+void GCExtension::GC(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args[0]->BooleanValue()) {
HEAP->CollectGarbage(NEW_SPACE, "gc extension");
} else {
HEAP->CollectAllGarbage(Heap::kNoGCFlags, "gc extension");
}
- return v8::Undefined();
}
explicit GCExtension(const char* source) : v8::Extension("v8/gc", source) {}
virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
v8::Handle<v8::String> name);
- static v8::Handle<v8::Value> GC(const v8::Arguments& args);
+ static void GC(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Register();
};
}
-v8::Handle<v8::Value> StatisticsExtension::GetCounters(
- const v8::Arguments& args) {
+void StatisticsExtension::GetCounters(
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = Isolate::Current();
Heap* heap = isolate->heap();
"lo_space_commited_bytes");
AddNumber(result, heap->amount_of_external_allocated_memory(),
"amount_of_external_allocated_memory");
- return result;
+ args.GetReturnValue().Set(result);
}
StatisticsExtension() : v8::Extension("v8/statistics", kSource) {}
virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
v8::Handle<v8::String> name);
- static v8::Handle<v8::Value> GetCounters(const v8::Arguments& args);
+ static void GetCounters(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Register();
private:
static const char* const kSource;