Commit 33dabf08 authored by dcarney@chromium.org's avatar dcarney@chromium.org

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
parent e792ae1f
......@@ -102,8 +102,8 @@ void ReportException(v8::Isolate* isolate, v8::TryCatch* handler);
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);
......@@ -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<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());
......@@ -408,17 +408,17 @@ v8::Handle<v8::Value> 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<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() {
......
......@@ -102,18 +102,21 @@ class JsHttpRequestProcessor : public HttpRequestProcessor {
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.
......@@ -137,13 +140,12 @@ class JsHttpRequestProcessor : public HttpRequestProcessor {
// -------------------------
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();
}
......@@ -350,8 +352,8 @@ string ObjectToString(Local<Value> value) {
}
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());
......@@ -362,17 +364,18 @@ Handle<Value> JsHttpRequestProcessor::MapGet(Local<String> name,
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());
......@@ -384,7 +387,7 @@ Handle<Value> JsHttpRequestProcessor::MapSet(Local<String> 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<Object> 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());
......@@ -460,31 +463,37 @@ Handle<Value> JsHttpRequestProcessor::GetPath(Local<String> name,
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())));
}
......
......@@ -53,11 +53,11 @@ bool ExecuteString(v8::Isolate* isolate,
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);
......@@ -116,7 +116,7 @@ v8::Handle<v8::Context> 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<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());
......@@ -131,70 +131,73 @@ v8::Handle<v8::Value> 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<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()));
}
......
......@@ -793,9 +793,9 @@ const AccessorDescriptor Accessors::FunctionCaller = {
// 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());
......@@ -807,16 +807,16 @@ static v8::Handle<v8::Value> ModuleGetExport(
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());
......
......@@ -1214,7 +1214,7 @@ static void FunctionTemplateSetCallHandler(FunctionTemplate* function_template,
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();
......@@ -1262,9 +1262,11 @@ static i::Handle<i::AccessorInfo> MakeAccessorInfo(
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));
......@@ -1367,16 +1369,19 @@ static void SetNamedInstancePropertyHandler(
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);
......@@ -1412,18 +1417,19 @@ static void SetIndexedInstancePropertyHandler(
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);
......@@ -1449,7 +1455,7 @@ static void SetInstanceCallAsFunctionHandler(
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();
......
......@@ -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<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)
......
......@@ -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<v8::Value>& 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<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;
......@@ -474,16 +477,18 @@ Handle<Value> 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<Value> 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<Value> accumulator = GetStdout(stdout_fds[kReadFD],
start_time,
......@@ -507,7 +512,8 @@ Handle<Value> 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<Value> Shell::System(const Arguments& args) {
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;
}
}
......@@ -598,79 +609,85 @@ static bool mkdirp(char* directory, mode_t mask) {
}
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();
}
......
This diff is collapsed.
......@@ -300,45 +300,46 @@ class Shell : public i::AllStatic {
#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:
//
......@@ -365,14 +366,14 @@ class Shell : public i::AllStatic {
// 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);
......@@ -412,9 +413,10 @@ class Shell : public i::AllStatic {
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);
......
......@@ -72,26 +72,29 @@ v8::Handle<v8::FunctionTemplate> ExternalizeStringExtension::GetNativeFunction(
}
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()];
......@@ -115,21 +118,22 @@ v8::Handle<v8::Value> ExternalizeStringExtension::Externalize(
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);
}
......
......@@ -38,8 +38,8 @@ class ExternalizeStringExtension : public v8::Extension {
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;
......
......@@ -38,13 +38,12 @@ v8::Handle<v8::FunctionTemplate> GCExtension::GetNativeFunction(
}
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();
}
......
......@@ -38,7 +38,7 @@ class GCExtension : public v8::Extension {
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();
};
......
......@@ -58,8 +58,8 @@ static void AddNumber(v8::Local<v8::Object> object,
}
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();
......@@ -141,7 +141,7 @@ v8::Handle<v8::Value> StatisticsExtension::GetCounters(
"lo_space_commited_bytes");
AddNumber(result, heap->amount_of_external_allocated_memory(),
"amount_of_external_allocated_memory");
return result;
args.GetReturnValue().Set(result);
}
......
......@@ -38,7 +38,7 @@ class StatisticsExtension : public v8::Extension {
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;
......
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