Commit ebadb68f authored by jochen's avatar jochen Committed by Commit bot

Remove usage of to-be-deprecated APIs from samples

BUG=v8:4134
R=vogelheim@chromium.org
LOG=n

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

Cr-Commit-Position: refs/heads/master@{#29452}
parent 0ecd9e1b
...@@ -47,13 +47,15 @@ int main(int argc, char* argv[]) { ...@@ -47,13 +47,15 @@ int main(int argc, char* argv[]) {
Context::Scope context_scope(context); Context::Scope context_scope(context);
// Create a string containing the JavaScript source code. // Create a string containing the JavaScript source code.
Local<String> source = String::NewFromUtf8(isolate, "'Hello' + ', World!'"); Local<String> source =
String::NewFromUtf8(isolate, "'Hello' + ', World!'",
NewStringType::kNormal).ToLocalChecked();
// Compile the source code. // Compile the source code.
Local<Script> script = Script::Compile(source); Local<Script> script = Script::Compile(context, source).ToLocalChecked();
// Run the script to get the result. // Run the script to get the result.
Local<Value> result = script->Run(); Local<Value> result = script->Run(context).ToLocalChecked();
// Convert the result to an UTF8 string and print it. // Convert the result to an UTF8 string and print it.
String::Utf8Value utf8(result); String::Utf8Value utf8(result);
......
...@@ -93,8 +93,8 @@ class JsHttpRequestProcessor : public HttpRequestProcessor { ...@@ -93,8 +93,8 @@ class JsHttpRequestProcessor : public HttpRequestProcessor {
public: public:
// Creates a new processor that processes requests by invoking the // Creates a new processor that processes requests by invoking the
// Process function of the JavaScript script given as an argument. // Process function of the JavaScript script given as an argument.
JsHttpRequestProcessor(Isolate* isolate, Handle<String> script) JsHttpRequestProcessor(Isolate* isolate, Local<String> script)
: isolate_(isolate), script_(script) { } : isolate_(isolate), script_(script) {}
virtual ~JsHttpRequestProcessor(); virtual ~JsHttpRequestProcessor();
virtual bool Initialize(map<string, string>* opts, virtual bool Initialize(map<string, string>* opts,
...@@ -104,7 +104,7 @@ class JsHttpRequestProcessor : public HttpRequestProcessor { ...@@ -104,7 +104,7 @@ class JsHttpRequestProcessor : public HttpRequestProcessor {
private: private:
// Execute the script associated with this processor and extract the // Execute the script associated with this processor and extract the
// Process function. Returns true if this succeeded, otherwise false. // Process function. Returns true if this succeeded, otherwise false.
bool ExecuteScript(Handle<String> script); bool ExecuteScript(Local<String> script);
// Wrap the options and output map in a JavaScript objects and // Wrap the options and output map in a JavaScript objects and
// install it in the global namespace as 'options' and 'output'. // install it in the global namespace as 'options' and 'output'.
...@@ -112,8 +112,8 @@ class JsHttpRequestProcessor : public HttpRequestProcessor { ...@@ -112,8 +112,8 @@ class JsHttpRequestProcessor : public HttpRequestProcessor {
// Constructs the template that describes the JavaScript wrapper // Constructs the template that describes the JavaScript wrapper
// type for requests. // type for requests.
static Handle<ObjectTemplate> MakeRequestTemplate(Isolate* isolate); static Local<ObjectTemplate> MakeRequestTemplate(Isolate* isolate);
static Handle<ObjectTemplate> MakeMapTemplate(Isolate* isolate); static Local<ObjectTemplate> MakeMapTemplate(Isolate* isolate);
// Callbacks that access the individual fields of request objects. // Callbacks that access the individual fields of request objects.
static void GetPath(Local<String> name, static void GetPath(Local<String> name,
...@@ -132,19 +132,19 @@ class JsHttpRequestProcessor : public HttpRequestProcessor { ...@@ -132,19 +132,19 @@ class JsHttpRequestProcessor : public HttpRequestProcessor {
// Utility methods for wrapping C++ objects as JavaScript objects, // Utility methods for wrapping C++ objects as JavaScript objects,
// and going back again. // and going back again.
Handle<Object> WrapMap(map<string, string>* obj); Local<Object> WrapMap(map<string, string>* obj);
static map<string, string>* UnwrapMap(Handle<Object> obj); static map<string, string>* UnwrapMap(Local<Object> obj);
Handle<Object> WrapRequest(HttpRequest* obj); Local<Object> WrapRequest(HttpRequest* obj);
static HttpRequest* UnwrapRequest(Handle<Object> obj); static HttpRequest* UnwrapRequest(Local<Object> obj);
Isolate* GetIsolate() { return isolate_; } Isolate* GetIsolate() { return isolate_; }
Isolate* isolate_; Isolate* isolate_;
Handle<String> script_; Local<String> script_;
Persistent<Context> context_; Global<Context> context_;
Persistent<Function> process_; Global<Function> process_;
static Persistent<ObjectTemplate> request_template_; static Global<ObjectTemplate> request_template_;
static Persistent<ObjectTemplate> map_template_; static Global<ObjectTemplate> map_template_;
}; };
...@@ -156,7 +156,7 @@ class JsHttpRequestProcessor : public HttpRequestProcessor { ...@@ -156,7 +156,7 @@ class JsHttpRequestProcessor : public HttpRequestProcessor {
static void LogCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { static void LogCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() < 1) return; if (args.Length() < 1) return;
HandleScope scope(args.GetIsolate()); HandleScope scope(args.GetIsolate());
Handle<Value> arg = args[0]; Local<Value> arg = args[0];
String::Utf8Value value(arg); String::Utf8Value value(arg);
HttpRequestProcessor::Log(*value); HttpRequestProcessor::Log(*value);
} }
...@@ -170,8 +170,9 @@ bool JsHttpRequestProcessor::Initialize(map<string, string>* opts, ...@@ -170,8 +170,9 @@ bool JsHttpRequestProcessor::Initialize(map<string, string>* opts,
// Create a template for the global object where we set the // Create a template for the global object where we set the
// built-in global functions. // built-in global functions.
Handle<ObjectTemplate> global = ObjectTemplate::New(GetIsolate()); Local<ObjectTemplate> global = ObjectTemplate::New(GetIsolate());
global->Set(String::NewFromUtf8(GetIsolate(), "log"), global->Set(String::NewFromUtf8(GetIsolate(), "log", NewStringType::kNormal)
.ToLocalChecked(),
FunctionTemplate::New(GetIsolate(), LogCallback)); FunctionTemplate::New(GetIsolate(), LogCallback));
// Each processor gets its own context so different processors don't // Each processor gets its own context so different processors don't
...@@ -179,7 +180,7 @@ bool JsHttpRequestProcessor::Initialize(map<string, string>* opts, ...@@ -179,7 +180,7 @@ bool JsHttpRequestProcessor::Initialize(map<string, string>* opts,
// is what we need for the reference to remain after we return from // is what we need for the reference to remain after we return from
// this method. That persistent handle has to be disposed in the // this method. That persistent handle has to be disposed in the
// destructor. // destructor.
v8::Handle<v8::Context> context = Context::New(GetIsolate(), NULL, global); v8::Local<v8::Context> context = Context::New(GetIsolate(), NULL, global);
context_.Reset(GetIsolate(), context); context_.Reset(GetIsolate(), context);
// Enter the new context so all the following operations take place // Enter the new context so all the following operations take place
...@@ -196,17 +197,21 @@ bool JsHttpRequestProcessor::Initialize(map<string, string>* opts, ...@@ -196,17 +197,21 @@ bool JsHttpRequestProcessor::Initialize(map<string, string>* opts,
// The script compiled and ran correctly. Now we fetch out the // The script compiled and ran correctly. Now we fetch out the
// Process function from the global object. // Process function from the global object.
Handle<String> process_name = String::NewFromUtf8(GetIsolate(), "Process"); Local<String> process_name =
Handle<Value> process_val = context->Global()->Get(process_name); String::NewFromUtf8(GetIsolate(), "Process", NewStringType::kNormal)
.ToLocalChecked();
Local<Value> process_val;
// If there is no Process function, or if it is not a function, // If there is no Process function, or if it is not a function,
// bail out // bail out
if (!process_val->IsFunction()) return false; if (!context->Global()->Get(context, process_name).ToLocal(&process_val) ||
!process_val->IsFunction()) {
return false;
}
// It is a function; cast it to a Function // It is a function; cast it to a Function
Handle<Function> process_fun = Handle<Function>::Cast(process_val); Local<Function> process_fun = Local<Function>::Cast(process_val);
// Store the function in a Persistent handle, since we also want // Store the function in a Global handle, since we also want
// that to remain after this call returns // that to remain after this call returns
process_.Reset(GetIsolate(), process_fun); process_.Reset(GetIsolate(), process_fun);
...@@ -215,16 +220,18 @@ bool JsHttpRequestProcessor::Initialize(map<string, string>* opts, ...@@ -215,16 +220,18 @@ bool JsHttpRequestProcessor::Initialize(map<string, string>* opts,
} }
bool JsHttpRequestProcessor::ExecuteScript(Handle<String> script) { bool JsHttpRequestProcessor::ExecuteScript(Local<String> script) {
HandleScope handle_scope(GetIsolate()); HandleScope handle_scope(GetIsolate());
// We're just about to compile the script; set up an error handler to // We're just about to compile the script; set up an error handler to
// catch any exceptions the script might throw. // catch any exceptions the script might throw.
TryCatch try_catch(GetIsolate()); TryCatch try_catch(GetIsolate());
Local<Context> context(GetIsolate()->GetCurrentContext());
// Compile the script and check for errors. // Compile the script and check for errors.
Handle<Script> compiled_script = Script::Compile(script); Local<Script> compiled_script;
if (compiled_script.IsEmpty()) { if (!Script::Compile(context, script).ToLocal(&compiled_script)) {
String::Utf8Value error(try_catch.Exception()); String::Utf8Value error(try_catch.Exception());
Log(*error); Log(*error);
// The script failed to compile; bail out. // The script failed to compile; bail out.
...@@ -232,8 +239,8 @@ bool JsHttpRequestProcessor::ExecuteScript(Handle<String> script) { ...@@ -232,8 +239,8 @@ bool JsHttpRequestProcessor::ExecuteScript(Handle<String> script) {
} }
// Run the script! // Run the script!
Handle<Value> result = compiled_script->Run(); Local<Value> result;
if (result.IsEmpty()) { if (!compiled_script->Run(context).ToLocal(&result)) {
// The TryCatch above is still in effect and will have caught the error. // The TryCatch above is still in effect and will have caught the error.
String::Utf8Value error(try_catch.Exception()); String::Utf8Value error(try_catch.Exception());
Log(*error); Log(*error);
...@@ -249,18 +256,26 @@ bool JsHttpRequestProcessor::InstallMaps(map<string, string>* opts, ...@@ -249,18 +256,26 @@ bool JsHttpRequestProcessor::InstallMaps(map<string, string>* opts,
HandleScope handle_scope(GetIsolate()); HandleScope handle_scope(GetIsolate());
// Wrap the map object in a JavaScript wrapper // Wrap the map object in a JavaScript wrapper
Handle<Object> opts_obj = WrapMap(opts); Local<Object> opts_obj = WrapMap(opts);
v8::Local<v8::Context> context = v8::Local<v8::Context> context =
v8::Local<v8::Context>::New(GetIsolate(), context_); v8::Local<v8::Context>::New(GetIsolate(), context_);
// Set the options object as a property on the global object. // Set the options object as a property on the global object.
context->Global()->Set(String::NewFromUtf8(GetIsolate(), "options"), context->Global()
opts_obj); ->Set(context,
String::NewFromUtf8(GetIsolate(), "options", NewStringType::kNormal)
Handle<Object> output_obj = WrapMap(output); .ToLocalChecked(),
context->Global()->Set(String::NewFromUtf8(GetIsolate(), "output"), opts_obj)
output_obj); .FromJust();
Local<Object> output_obj = WrapMap(output);
context->Global()
->Set(context,
String::NewFromUtf8(GetIsolate(), "output", NewStringType::kNormal)
.ToLocalChecked(),
output_obj)
.FromJust();
return true; return true;
} }
...@@ -278,7 +293,7 @@ bool JsHttpRequestProcessor::Process(HttpRequest* request) { ...@@ -278,7 +293,7 @@ bool JsHttpRequestProcessor::Process(HttpRequest* request) {
Context::Scope context_scope(context); Context::Scope context_scope(context);
// Wrap the C++ request object in a JavaScript wrapper // Wrap the C++ request object in a JavaScript wrapper
Handle<Object> request_obj = WrapRequest(request); Local<Object> request_obj = WrapRequest(request);
// Set up an exception handler before calling the Process function // Set up an exception handler before calling the Process function
TryCatch try_catch(GetIsolate()); TryCatch try_catch(GetIsolate());
...@@ -286,11 +301,11 @@ bool JsHttpRequestProcessor::Process(HttpRequest* request) { ...@@ -286,11 +301,11 @@ bool JsHttpRequestProcessor::Process(HttpRequest* request) {
// Invoke the process function, giving the global object as 'this' // Invoke the process function, giving the global object as 'this'
// and one argument, the request. // and one argument, the request.
const int argc = 1; const int argc = 1;
Handle<Value> argv[argc] = { request_obj }; Local<Value> argv[argc] = {request_obj};
v8::Local<v8::Function> process = v8::Local<v8::Function> process =
v8::Local<v8::Function>::New(GetIsolate(), process_); v8::Local<v8::Function>::New(GetIsolate(), process_);
Handle<Value> result = process->Call(context->Global(), argc, argv); Local<Value> result;
if (result.IsEmpty()) { if (!process->Call(context, context->Global(), argc, argv).ToLocal(&result)) {
String::Utf8Value error(try_catch.Exception()); String::Utf8Value error(try_catch.Exception());
Log(*error); Log(*error);
return false; return false;
...@@ -309,8 +324,8 @@ JsHttpRequestProcessor::~JsHttpRequestProcessor() { ...@@ -309,8 +324,8 @@ JsHttpRequestProcessor::~JsHttpRequestProcessor() {
} }
Persistent<ObjectTemplate> JsHttpRequestProcessor::request_template_; Global<ObjectTemplate> JsHttpRequestProcessor::request_template_;
Persistent<ObjectTemplate> JsHttpRequestProcessor::map_template_; Global<ObjectTemplate> JsHttpRequestProcessor::map_template_;
// ----------------------------------- // -----------------------------------
...@@ -319,25 +334,26 @@ Persistent<ObjectTemplate> JsHttpRequestProcessor::map_template_; ...@@ -319,25 +334,26 @@ Persistent<ObjectTemplate> JsHttpRequestProcessor::map_template_;
// Utility function that wraps a C++ http request object in a // Utility function that wraps a C++ http request object in a
// JavaScript object. // JavaScript object.
Handle<Object> JsHttpRequestProcessor::WrapMap(map<string, string>* obj) { Local<Object> JsHttpRequestProcessor::WrapMap(map<string, string>* obj) {
// Handle scope for temporary handles. // Local scope for temporary handles.
EscapableHandleScope handle_scope(GetIsolate()); EscapableHandleScope handle_scope(GetIsolate());
// Fetch the template for creating JavaScript map wrappers. // Fetch the template for creating JavaScript map wrappers.
// It only has to be created once, which we do on demand. // It only has to be created once, which we do on demand.
if (map_template_.IsEmpty()) { if (map_template_.IsEmpty()) {
Handle<ObjectTemplate> raw_template = MakeMapTemplate(GetIsolate()); Local<ObjectTemplate> raw_template = MakeMapTemplate(GetIsolate());
map_template_.Reset(GetIsolate(), raw_template); map_template_.Reset(GetIsolate(), raw_template);
} }
Handle<ObjectTemplate> templ = Local<ObjectTemplate> templ =
Local<ObjectTemplate>::New(GetIsolate(), map_template_); Local<ObjectTemplate>::New(GetIsolate(), map_template_);
// Create an empty map wrapper. // Create an empty map wrapper.
Local<Object> result = templ->NewInstance(); Local<Object> result =
templ->NewInstance(GetIsolate()->GetCurrentContext()).ToLocalChecked();
// Wrap the raw C++ pointer in an External so it can be referenced // Wrap the raw C++ pointer in an External so it can be referenced
// from within JavaScript. // from within JavaScript.
Handle<External> map_ptr = External::New(GetIsolate(), obj); Local<External> map_ptr = External::New(GetIsolate(), obj);
// Store the map pointer in the JavaScript wrapper. // Store the map pointer in the JavaScript wrapper.
result->SetInternalField(0, map_ptr); result->SetInternalField(0, map_ptr);
...@@ -352,8 +368,8 @@ Handle<Object> JsHttpRequestProcessor::WrapMap(map<string, string>* obj) { ...@@ -352,8 +368,8 @@ Handle<Object> JsHttpRequestProcessor::WrapMap(map<string, string>* obj) {
// Utility function that extracts the C++ map pointer from a wrapper // Utility function that extracts the C++ map pointer from a wrapper
// object. // object.
map<string, string>* JsHttpRequestProcessor::UnwrapMap(Handle<Object> obj) { map<string, string>* JsHttpRequestProcessor::UnwrapMap(Local<Object> obj) {
Handle<External> field = Handle<External>::Cast(obj->GetInternalField(0)); Local<External> field = Local<External>::Cast(obj->GetInternalField(0));
void* ptr = field->Value(); void* ptr = field->Value();
return static_cast<map<string, string>*>(ptr); return static_cast<map<string, string>*>(ptr);
} }
...@@ -385,9 +401,10 @@ void JsHttpRequestProcessor::MapGet(Local<Name> name, ...@@ -385,9 +401,10 @@ void JsHttpRequestProcessor::MapGet(Local<Name> name,
// Otherwise fetch the value and wrap it in a JavaScript string // Otherwise fetch the value and wrap it in a JavaScript string
const string& value = (*iter).second; const string& value = (*iter).second;
info.GetReturnValue().Set(String::NewFromUtf8( info.GetReturnValue().Set(
info.GetIsolate(), value.c_str(), String::kNormalString, String::NewFromUtf8(info.GetIsolate(), value.c_str(),
static_cast<int>(value.length()))); NewStringType::kNormal,
static_cast<int>(value.length())).ToLocalChecked());
} }
...@@ -410,7 +427,7 @@ void JsHttpRequestProcessor::MapSet(Local<Name> name, Local<Value> value_obj, ...@@ -410,7 +427,7 @@ void JsHttpRequestProcessor::MapSet(Local<Name> name, Local<Value> value_obj,
} }
Handle<ObjectTemplate> JsHttpRequestProcessor::MakeMapTemplate( Local<ObjectTemplate> JsHttpRequestProcessor::MakeMapTemplate(
Isolate* isolate) { Isolate* isolate) {
EscapableHandleScope handle_scope(isolate); EscapableHandleScope handle_scope(isolate);
...@@ -431,25 +448,26 @@ Handle<ObjectTemplate> JsHttpRequestProcessor::MakeMapTemplate( ...@@ -431,25 +448,26 @@ Handle<ObjectTemplate> JsHttpRequestProcessor::MakeMapTemplate(
* Utility function that wraps a C++ http request object in a * Utility function that wraps a C++ http request object in a
* JavaScript object. * JavaScript object.
*/ */
Handle<Object> JsHttpRequestProcessor::WrapRequest(HttpRequest* request) { Local<Object> JsHttpRequestProcessor::WrapRequest(HttpRequest* request) {
// Handle scope for temporary handles. // Local scope for temporary handles.
EscapableHandleScope handle_scope(GetIsolate()); EscapableHandleScope handle_scope(GetIsolate());
// Fetch the template for creating JavaScript http request wrappers. // Fetch the template for creating JavaScript http request wrappers.
// It only has to be created once, which we do on demand. // It only has to be created once, which we do on demand.
if (request_template_.IsEmpty()) { if (request_template_.IsEmpty()) {
Handle<ObjectTemplate> raw_template = MakeRequestTemplate(GetIsolate()); Local<ObjectTemplate> raw_template = MakeRequestTemplate(GetIsolate());
request_template_.Reset(GetIsolate(), raw_template); request_template_.Reset(GetIsolate(), raw_template);
} }
Handle<ObjectTemplate> templ = Local<ObjectTemplate> templ =
Local<ObjectTemplate>::New(GetIsolate(), request_template_); Local<ObjectTemplate>::New(GetIsolate(), request_template_);
// Create an empty http request wrapper. // Create an empty http request wrapper.
Local<Object> result = templ->NewInstance(); Local<Object> result =
templ->NewInstance(GetIsolate()->GetCurrentContext()).ToLocalChecked();
// Wrap the raw C++ pointer in an External so it can be referenced // Wrap the raw C++ pointer in an External so it can be referenced
// from within JavaScript. // from within JavaScript.
Handle<External> request_ptr = External::New(GetIsolate(), request); Local<External> request_ptr = External::New(GetIsolate(), request);
// Store the request pointer in the JavaScript wrapper. // Store the request pointer in the JavaScript wrapper.
result->SetInternalField(0, request_ptr); result->SetInternalField(0, request_ptr);
...@@ -466,8 +484,8 @@ Handle<Object> JsHttpRequestProcessor::WrapRequest(HttpRequest* request) { ...@@ -466,8 +484,8 @@ Handle<Object> JsHttpRequestProcessor::WrapRequest(HttpRequest* request) {
* Utility function that extracts the C++ http request object from a * Utility function that extracts the C++ http request object from a
* wrapper object. * wrapper object.
*/ */
HttpRequest* JsHttpRequestProcessor::UnwrapRequest(Handle<Object> obj) { HttpRequest* JsHttpRequestProcessor::UnwrapRequest(Local<Object> obj) {
Handle<External> field = Handle<External>::Cast(obj->GetInternalField(0)); Local<External> field = Local<External>::Cast(obj->GetInternalField(0));
void* ptr = field->Value(); void* ptr = field->Value();
return static_cast<HttpRequest*>(ptr); return static_cast<HttpRequest*>(ptr);
} }
...@@ -482,9 +500,10 @@ void JsHttpRequestProcessor::GetPath(Local<String> name, ...@@ -482,9 +500,10 @@ void JsHttpRequestProcessor::GetPath(Local<String> name,
const string& path = request->Path(); const string& path = request->Path();
// Wrap the result in a JavaScript string and return it. // Wrap the result in a JavaScript string and return it.
info.GetReturnValue().Set(String::NewFromUtf8( info.GetReturnValue().Set(
info.GetIsolate(), path.c_str(), String::kNormalString, String::NewFromUtf8(info.GetIsolate(), path.c_str(),
static_cast<int>(path.length()))); NewStringType::kNormal,
static_cast<int>(path.length())).ToLocalChecked());
} }
...@@ -493,9 +512,10 @@ void JsHttpRequestProcessor::GetReferrer( ...@@ -493,9 +512,10 @@ void JsHttpRequestProcessor::GetReferrer(
const PropertyCallbackInfo<Value>& info) { const PropertyCallbackInfo<Value>& info) {
HttpRequest* request = UnwrapRequest(info.Holder()); HttpRequest* request = UnwrapRequest(info.Holder());
const string& path = request->Referrer(); const string& path = request->Referrer();
info.GetReturnValue().Set(String::NewFromUtf8( info.GetReturnValue().Set(
info.GetIsolate(), path.c_str(), String::kNormalString, String::NewFromUtf8(info.GetIsolate(), path.c_str(),
static_cast<int>(path.length()))); NewStringType::kNormal,
static_cast<int>(path.length())).ToLocalChecked());
} }
...@@ -503,9 +523,10 @@ void JsHttpRequestProcessor::GetHost(Local<String> name, ...@@ -503,9 +523,10 @@ void JsHttpRequestProcessor::GetHost(Local<String> name,
const PropertyCallbackInfo<Value>& info) { const PropertyCallbackInfo<Value>& info) {
HttpRequest* request = UnwrapRequest(info.Holder()); HttpRequest* request = UnwrapRequest(info.Holder());
const string& path = request->Host(); const string& path = request->Host();
info.GetReturnValue().Set(String::NewFromUtf8( info.GetReturnValue().Set(
info.GetIsolate(), path.c_str(), String::kNormalString, String::NewFromUtf8(info.GetIsolate(), path.c_str(),
static_cast<int>(path.length()))); NewStringType::kNormal,
static_cast<int>(path.length())).ToLocalChecked());
} }
...@@ -514,13 +535,14 @@ void JsHttpRequestProcessor::GetUserAgent( ...@@ -514,13 +535,14 @@ void JsHttpRequestProcessor::GetUserAgent(
const PropertyCallbackInfo<Value>& info) { const PropertyCallbackInfo<Value>& info) {
HttpRequest* request = UnwrapRequest(info.Holder()); HttpRequest* request = UnwrapRequest(info.Holder());
const string& path = request->UserAgent(); const string& path = request->UserAgent();
info.GetReturnValue().Set(String::NewFromUtf8( info.GetReturnValue().Set(
info.GetIsolate(), path.c_str(), String::kNormalString, String::NewFromUtf8(info.GetIsolate(), path.c_str(),
static_cast<int>(path.length()))); NewStringType::kNormal,
static_cast<int>(path.length())).ToLocalChecked());
} }
Handle<ObjectTemplate> JsHttpRequestProcessor::MakeRequestTemplate( Local<ObjectTemplate> JsHttpRequestProcessor::MakeRequestTemplate(
Isolate* isolate) { Isolate* isolate) {
EscapableHandleScope handle_scope(isolate); EscapableHandleScope handle_scope(isolate);
...@@ -529,16 +551,20 @@ Handle<ObjectTemplate> JsHttpRequestProcessor::MakeRequestTemplate( ...@@ -529,16 +551,20 @@ Handle<ObjectTemplate> JsHttpRequestProcessor::MakeRequestTemplate(
// Add accessors for each of the fields of the request. // Add accessors for each of the fields of the request.
result->SetAccessor( result->SetAccessor(
String::NewFromUtf8(isolate, "path", String::kInternalizedString), String::NewFromUtf8(isolate, "path", NewStringType::kInternalized)
.ToLocalChecked(),
GetPath); GetPath);
result->SetAccessor( result->SetAccessor(
String::NewFromUtf8(isolate, "referrer", String::kInternalizedString), String::NewFromUtf8(isolate, "referrer", NewStringType::kInternalized)
.ToLocalChecked(),
GetReferrer); GetReferrer);
result->SetAccessor( result->SetAccessor(
String::NewFromUtf8(isolate, "host", String::kInternalizedString), String::NewFromUtf8(isolate, "host", NewStringType::kInternalized)
.ToLocalChecked(),
GetHost); GetHost);
result->SetAccessor( result->SetAccessor(
String::NewFromUtf8(isolate, "userAgent", String::kInternalizedString), String::NewFromUtf8(isolate, "userAgent", NewStringType::kInternalized)
.ToLocalChecked(),
GetUserAgent); GetUserAgent);
// Again, return the result through the current handle scope. // Again, return the result through the current handle scope.
...@@ -604,9 +630,9 @@ void ParseOptions(int argc, ...@@ -604,9 +630,9 @@ void ParseOptions(int argc,
// Reads a file into a v8 string. // Reads a file into a v8 string.
Handle<String> ReadFile(Isolate* isolate, const string& name) { MaybeLocal<String> ReadFile(Isolate* isolate, const string& name) {
FILE* file = fopen(name.c_str(), "rb"); FILE* file = fopen(name.c_str(), "rb");
if (file == NULL) return Handle<String>(); if (file == NULL) return MaybeLocal<String>();
fseek(file, 0, SEEK_END); fseek(file, 0, SEEK_END);
size_t size = ftell(file); size_t size = ftell(file);
...@@ -618,12 +644,12 @@ Handle<String> ReadFile(Isolate* isolate, const string& name) { ...@@ -618,12 +644,12 @@ Handle<String> ReadFile(Isolate* isolate, const string& name) {
i += fread(&chars[i], 1, size - i, file); i += fread(&chars[i], 1, size - i, file);
if (ferror(file)) { if (ferror(file)) {
fclose(file); fclose(file);
return Handle<String>(); return MaybeLocal<String>();
} }
} }
fclose(file); fclose(file);
Handle<String> result = String::NewFromUtf8( MaybeLocal<String> result = String::NewFromUtf8(
isolate, chars, String::kNormalString, static_cast<int>(size)); isolate, chars, NewStringType::kNormal, static_cast<int>(size));
delete[] chars; delete[] chars;
return result; return result;
} }
...@@ -676,8 +702,8 @@ int main(int argc, char* argv[]) { ...@@ -676,8 +702,8 @@ int main(int argc, char* argv[]) {
Isolate* isolate = Isolate::New(create_params); Isolate* isolate = Isolate::New(create_params);
Isolate::Scope isolate_scope(isolate); Isolate::Scope isolate_scope(isolate);
HandleScope scope(isolate); HandleScope scope(isolate);
Handle<String> source = ReadFile(isolate, file); Local<String> source;
if (source.IsEmpty()) { if (!ReadFile(isolate, file).ToLocal(&source)) {
fprintf(stderr, "Error reading '%s'.\n", file.c_str()); fprintf(stderr, "Error reading '%s'.\n", file.c_str());
return 1; return 1;
} }
......
...@@ -40,6 +40,10 @@ ...@@ -40,6 +40,10 @@
'include_dirs': [ 'include_dirs': [
'..', '..',
], ],
'defines': [
# TODO(jochen): Remove again after this is globally turned on.
'V8_IMMINENT_DEPRECATION_WARNINGS',
],
'conditions': [ 'conditions': [
['v8_enable_i18n_support==1', { ['v8_enable_i18n_support==1', {
'dependencies': [ 'dependencies': [
......
...@@ -44,20 +44,18 @@ ...@@ -44,20 +44,18 @@
*/ */
v8::Handle<v8::Context> CreateShellContext(v8::Isolate* isolate); v8::Local<v8::Context> CreateShellContext(v8::Isolate* isolate);
void RunShell(v8::Handle<v8::Context> context); void RunShell(v8::Local<v8::Context> context);
int RunMain(v8::Isolate* isolate, int argc, char* argv[]); int RunMain(v8::Isolate* isolate, int argc, char* argv[]);
bool ExecuteString(v8::Isolate* isolate, bool ExecuteString(v8::Isolate* isolate, v8::Local<v8::String> source,
v8::Handle<v8::String> source, v8::Local<v8::Value> name, bool print_result,
v8::Handle<v8::Value> name,
bool print_result,
bool report_exceptions); bool report_exceptions);
void Print(const v8::FunctionCallbackInfo<v8::Value>& args); void Print(const v8::FunctionCallbackInfo<v8::Value>& args);
void Read(const v8::FunctionCallbackInfo<v8::Value>& args); void Read(const v8::FunctionCallbackInfo<v8::Value>& args);
void Load(const v8::FunctionCallbackInfo<v8::Value>& args); void Load(const v8::FunctionCallbackInfo<v8::Value>& args);
void Quit(const v8::FunctionCallbackInfo<v8::Value>& args); void Quit(const v8::FunctionCallbackInfo<v8::Value>& args);
void Version(const v8::FunctionCallbackInfo<v8::Value>& args); void Version(const v8::FunctionCallbackInfo<v8::Value>& args);
v8::Handle<v8::String> ReadFile(v8::Isolate* isolate, const char* name); v8::MaybeLocal<v8::String> ReadFile(v8::Isolate* isolate, const char* name);
void ReportException(v8::Isolate* isolate, v8::TryCatch* handler); void ReportException(v8::Isolate* isolate, v8::TryCatch* handler);
...@@ -90,7 +88,7 @@ int main(int argc, char* argv[]) { ...@@ -90,7 +88,7 @@ int main(int argc, char* argv[]) {
{ {
v8::Isolate::Scope isolate_scope(isolate); v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate); v8::HandleScope handle_scope(isolate);
v8::Handle<v8::Context> context = CreateShellContext(isolate); v8::Local<v8::Context> context = CreateShellContext(isolate);
if (context.IsEmpty()) { if (context.IsEmpty()) {
fprintf(stderr, "Error creating context\n"); fprintf(stderr, "Error creating context\n");
return 1; return 1;
...@@ -115,24 +113,31 @@ const char* ToCString(const v8::String::Utf8Value& value) { ...@@ -115,24 +113,31 @@ const char* ToCString(const v8::String::Utf8Value& value) {
// Creates a new execution environment containing the built-in // Creates a new execution environment containing the built-in
// functions. // functions.
v8::Handle<v8::Context> CreateShellContext(v8::Isolate* isolate) { v8::Local<v8::Context> CreateShellContext(v8::Isolate* isolate) {
// Create a template for the global object. // Create a template for the global object.
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate); v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate);
// Bind the global 'print' function to the C++ Print callback. // Bind the global 'print' function to the C++ Print callback.
global->Set(v8::String::NewFromUtf8(isolate, "print"), global->Set(
v8::FunctionTemplate::New(isolate, Print)); v8::String::NewFromUtf8(isolate, "print", v8::NewStringType::kNormal)
.ToLocalChecked(),
v8::FunctionTemplate::New(isolate, Print));
// Bind the global 'read' function to the C++ Read callback. // Bind the global 'read' function to the C++ Read callback.
global->Set(v8::String::NewFromUtf8(isolate, "read"), global->Set(v8::String::NewFromUtf8(
isolate, "read", v8::NewStringType::kNormal).ToLocalChecked(),
v8::FunctionTemplate::New(isolate, Read)); v8::FunctionTemplate::New(isolate, Read));
// Bind the global 'load' function to the C++ Load callback. // Bind the global 'load' function to the C++ Load callback.
global->Set(v8::String::NewFromUtf8(isolate, "load"), global->Set(v8::String::NewFromUtf8(
isolate, "load", v8::NewStringType::kNormal).ToLocalChecked(),
v8::FunctionTemplate::New(isolate, Load)); v8::FunctionTemplate::New(isolate, Load));
// Bind the 'quit' function // Bind the 'quit' function
global->Set(v8::String::NewFromUtf8(isolate, "quit"), global->Set(v8::String::NewFromUtf8(
isolate, "quit", v8::NewStringType::kNormal).ToLocalChecked(),
v8::FunctionTemplate::New(isolate, Quit)); v8::FunctionTemplate::New(isolate, Quit));
// Bind the 'version' function // Bind the 'version' function
global->Set(v8::String::NewFromUtf8(isolate, "version"), global->Set(
v8::FunctionTemplate::New(isolate, Version)); v8::String::NewFromUtf8(isolate, "version", v8::NewStringType::kNormal)
.ToLocalChecked(),
v8::FunctionTemplate::New(isolate, Version));
return v8::Context::New(isolate, NULL, global); return v8::Context::New(isolate, NULL, global);
} }
...@@ -165,19 +170,22 @@ void Print(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -165,19 +170,22 @@ void Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
void Read(const v8::FunctionCallbackInfo<v8::Value>& args) { void Read(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 1) { if (args.Length() != 1) {
args.GetIsolate()->ThrowException( args.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(args.GetIsolate(), "Bad parameters")); v8::String::NewFromUtf8(args.GetIsolate(), "Bad parameters",
v8::NewStringType::kNormal).ToLocalChecked());
return; return;
} }
v8::String::Utf8Value file(args[0]); v8::String::Utf8Value file(args[0]);
if (*file == NULL) { if (*file == NULL) {
args.GetIsolate()->ThrowException( args.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(args.GetIsolate(), "Error loading file")); v8::String::NewFromUtf8(args.GetIsolate(), "Error loading file",
v8::NewStringType::kNormal).ToLocalChecked());
return; return;
} }
v8::Handle<v8::String> source = ReadFile(args.GetIsolate(), *file); v8::Local<v8::String> source;
if (source.IsEmpty()) { if (!ReadFile(args.GetIsolate(), *file).ToLocal(&source)) {
args.GetIsolate()->ThrowException( args.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(args.GetIsolate(), "Error loading file")); v8::String::NewFromUtf8(args.GetIsolate(), "Error loading file",
v8::NewStringType::kNormal).ToLocalChecked());
return; return;
} }
args.GetReturnValue().Set(source); args.GetReturnValue().Set(source);
...@@ -193,22 +201,21 @@ void Load(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -193,22 +201,21 @@ void Load(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::String::Utf8Value file(args[i]); v8::String::Utf8Value file(args[i]);
if (*file == NULL) { if (*file == NULL) {
args.GetIsolate()->ThrowException( args.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(args.GetIsolate(), "Error loading file")); v8::String::NewFromUtf8(args.GetIsolate(), "Error loading file",
v8::NewStringType::kNormal).ToLocalChecked());
return; return;
} }
v8::Handle<v8::String> source = ReadFile(args.GetIsolate(), *file); v8::Local<v8::String> source;
if (source.IsEmpty()) { if (!ReadFile(args.GetIsolate(), *file).ToLocal(&source)) {
args.GetIsolate()->ThrowException( args.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(args.GetIsolate(), "Error loading file")); v8::String::NewFromUtf8(args.GetIsolate(), "Error loading file",
v8::NewStringType::kNormal).ToLocalChecked());
return; return;
} }
if (!ExecuteString(args.GetIsolate(), if (!ExecuteString(args.GetIsolate(), source, args[i], false, false)) {
source,
v8::String::NewFromUtf8(args.GetIsolate(), *file),
false,
false)) {
args.GetIsolate()->ThrowException( args.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(args.GetIsolate(), "Error executing file")); v8::String::NewFromUtf8(args.GetIsolate(), "Error executing file",
v8::NewStringType::kNormal).ToLocalChecked());
return; return;
} }
} }
...@@ -220,7 +227,8 @@ void Load(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -220,7 +227,8 @@ void Load(const v8::FunctionCallbackInfo<v8::Value>& args) {
void Quit(const v8::FunctionCallbackInfo<v8::Value>& args) { void Quit(const v8::FunctionCallbackInfo<v8::Value>& args) {
// If not arguments are given args[0] will yield undefined which // If not arguments are given args[0] will yield undefined which
// converts to the integer value 0. // converts to the integer value 0.
int exit_code = args[0]->Int32Value(); int exit_code =
args[0]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromMaybe(0);
fflush(stdout); fflush(stdout);
fflush(stderr); fflush(stderr);
exit(exit_code); exit(exit_code);
...@@ -229,14 +237,15 @@ void Quit(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -229,14 +237,15 @@ void Quit(const v8::FunctionCallbackInfo<v8::Value>& args) {
void Version(const v8::FunctionCallbackInfo<v8::Value>& args) { void Version(const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetReturnValue().Set( args.GetReturnValue().Set(
v8::String::NewFromUtf8(args.GetIsolate(), v8::V8::GetVersion())); v8::String::NewFromUtf8(args.GetIsolate(), v8::V8::GetVersion(),
v8::NewStringType::kNormal).ToLocalChecked());
} }
// Reads a file into a v8 string. // Reads a file into a v8 string.
v8::Handle<v8::String> ReadFile(v8::Isolate* isolate, const char* name) { v8::MaybeLocal<v8::String> ReadFile(v8::Isolate* isolate, const char* name) {
FILE* file = fopen(name, "rb"); FILE* file = fopen(name, "rb");
if (file == NULL) return v8::Handle<v8::String>(); if (file == NULL) return v8::MaybeLocal<v8::String>();
fseek(file, 0, SEEK_END); fseek(file, 0, SEEK_END);
size_t size = ftell(file); size_t size = ftell(file);
...@@ -248,12 +257,12 @@ v8::Handle<v8::String> ReadFile(v8::Isolate* isolate, const char* name) { ...@@ -248,12 +257,12 @@ v8::Handle<v8::String> ReadFile(v8::Isolate* isolate, const char* name) {
i += fread(&chars[i], 1, size - i, file); i += fread(&chars[i], 1, size - i, file);
if (ferror(file)) { if (ferror(file)) {
fclose(file); fclose(file);
return v8::Handle<v8::String>(); return v8::MaybeLocal<v8::String>();
} }
} }
fclose(file); fclose(file);
v8::Handle<v8::String> result = v8::String::NewFromUtf8( v8::MaybeLocal<v8::String> result = v8::String::NewFromUtf8(
isolate, chars, v8::String::kNormalString, static_cast<int>(size)); isolate, chars, v8::NewStringType::kNormal, static_cast<int>(size));
delete[] chars; delete[] chars;
return result; return result;
} }
...@@ -274,16 +283,23 @@ int RunMain(v8::Isolate* isolate, int argc, char* argv[]) { ...@@ -274,16 +283,23 @@ int RunMain(v8::Isolate* isolate, int argc, char* argv[]) {
"Warning: unknown flag %s.\nTry --help for options\n", str); "Warning: unknown flag %s.\nTry --help for options\n", str);
} else if (strcmp(str, "-e") == 0 && i + 1 < argc) { } else if (strcmp(str, "-e") == 0 && i + 1 < argc) {
// Execute argument given to -e option directly. // Execute argument given to -e option directly.
v8::Handle<v8::String> file_name = v8::Local<v8::String> file_name =
v8::String::NewFromUtf8(isolate, "unnamed"); v8::String::NewFromUtf8(isolate, "unnamed",
v8::Handle<v8::String> source = v8::NewStringType::kNormal).ToLocalChecked();
v8::String::NewFromUtf8(isolate, argv[++i]); v8::Local<v8::String> source;
if (!v8::String::NewFromUtf8(isolate, argv[++i],
v8::NewStringType::kNormal)
.ToLocal(&source)) {
return 1;
}
if (!ExecuteString(isolate, source, file_name, false, true)) return 1; if (!ExecuteString(isolate, source, file_name, false, true)) return 1;
} else { } else {
// Use all other arguments as names of files to load and run. // Use all other arguments as names of files to load and run.
v8::Handle<v8::String> file_name = v8::String::NewFromUtf8(isolate, str); v8::Local<v8::String> file_name =
v8::Handle<v8::String> source = ReadFile(isolate, str); v8::String::NewFromUtf8(isolate, str, v8::NewStringType::kNormal)
if (source.IsEmpty()) { .ToLocalChecked();
v8::Local<v8::String> source;
if (!ReadFile(isolate, str).ToLocal(&source)) {
fprintf(stderr, "Error reading '%s'\n", str); fprintf(stderr, "Error reading '%s'\n", str);
continue; continue;
} }
...@@ -295,47 +311,47 @@ int RunMain(v8::Isolate* isolate, int argc, char* argv[]) { ...@@ -295,47 +311,47 @@ int RunMain(v8::Isolate* isolate, int argc, char* argv[]) {
// The read-eval-execute loop of the shell. // The read-eval-execute loop of the shell.
void RunShell(v8::Handle<v8::Context> context) { void RunShell(v8::Local<v8::Context> context) {
fprintf(stderr, "V8 version %s [sample shell]\n", v8::V8::GetVersion()); fprintf(stderr, "V8 version %s [sample shell]\n", v8::V8::GetVersion());
static const int kBufferSize = 256; static const int kBufferSize = 256;
// Enter the execution environment before evaluating any code. // Enter the execution environment before evaluating any code.
v8::Context::Scope context_scope(context); v8::Context::Scope context_scope(context);
v8::Local<v8::String> name( v8::Local<v8::String> name(
v8::String::NewFromUtf8(context->GetIsolate(), "(shell)")); v8::String::NewFromUtf8(context->GetIsolate(), "(shell)",
v8::NewStringType::kNormal).ToLocalChecked());
while (true) { while (true) {
char buffer[kBufferSize]; char buffer[kBufferSize];
fprintf(stderr, "> "); fprintf(stderr, "> ");
char* str = fgets(buffer, kBufferSize, stdin); char* str = fgets(buffer, kBufferSize, stdin);
if (str == NULL) break; if (str == NULL) break;
v8::HandleScope handle_scope(context->GetIsolate()); v8::HandleScope handle_scope(context->GetIsolate());
ExecuteString(context->GetIsolate(), ExecuteString(
v8::String::NewFromUtf8(context->GetIsolate(), str), context->GetIsolate(),
name, v8::String::NewFromUtf8(context->GetIsolate(), str,
true, v8::NewStringType::kNormal).ToLocalChecked(),
true); name, true, true);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
// Executes a string within the current v8 context. // Executes a string within the current v8 context.
bool ExecuteString(v8::Isolate* isolate, bool ExecuteString(v8::Isolate* isolate, v8::Local<v8::String> source,
v8::Handle<v8::String> source, v8::Local<v8::Value> name, bool print_result,
v8::Handle<v8::Value> name,
bool print_result,
bool report_exceptions) { bool report_exceptions) {
v8::HandleScope handle_scope(isolate); v8::HandleScope handle_scope(isolate);
v8::TryCatch try_catch(isolate); v8::TryCatch try_catch(isolate);
v8::ScriptOrigin origin(name); v8::ScriptOrigin origin(name);
v8::Handle<v8::Script> script = v8::Script::Compile(source, &origin); v8::Local<v8::Context> context(isolate->GetCurrentContext());
if (script.IsEmpty()) { v8::Local<v8::Script> script;
if (!v8::Script::Compile(context, source, &origin).ToLocal(&script)) {
// Print errors that happened during compilation. // Print errors that happened during compilation.
if (report_exceptions) if (report_exceptions)
ReportException(isolate, &try_catch); ReportException(isolate, &try_catch);
return false; return false;
} else { } else {
v8::Handle<v8::Value> result = script->Run(); v8::Local<v8::Value> result;
if (result.IsEmpty()) { if (!script->Run(context).ToLocal(&result)) {
assert(try_catch.HasCaught()); assert(try_catch.HasCaught());
// Print errors that happened during execution. // Print errors that happened during execution.
if (report_exceptions) if (report_exceptions)
...@@ -360,7 +376,7 @@ void ReportException(v8::Isolate* isolate, v8::TryCatch* try_catch) { ...@@ -360,7 +376,7 @@ void ReportException(v8::Isolate* isolate, v8::TryCatch* try_catch) {
v8::HandleScope handle_scope(isolate); v8::HandleScope handle_scope(isolate);
v8::String::Utf8Value exception(try_catch->Exception()); v8::String::Utf8Value exception(try_catch->Exception());
const char* exception_string = ToCString(exception); const char* exception_string = ToCString(exception);
v8::Handle<v8::Message> message = try_catch->Message(); v8::Local<v8::Message> message = try_catch->Message();
if (message.IsEmpty()) { if (message.IsEmpty()) {
// V8 didn't provide any extra information about this error; just // V8 didn't provide any extra information about this error; just
// print the exception. // print the exception.
...@@ -368,24 +384,27 @@ void ReportException(v8::Isolate* isolate, v8::TryCatch* try_catch) { ...@@ -368,24 +384,27 @@ void ReportException(v8::Isolate* isolate, v8::TryCatch* try_catch) {
} else { } else {
// Print (filename):(line number): (message). // Print (filename):(line number): (message).
v8::String::Utf8Value filename(message->GetScriptOrigin().ResourceName()); v8::String::Utf8Value filename(message->GetScriptOrigin().ResourceName());
v8::Local<v8::Context> context(isolate->GetCurrentContext());
const char* filename_string = ToCString(filename); const char* filename_string = ToCString(filename);
int linenum = message->GetLineNumber(); int linenum = message->GetLineNumber(context).FromJust();
fprintf(stderr, "%s:%i: %s\n", filename_string, linenum, exception_string); fprintf(stderr, "%s:%i: %s\n", filename_string, linenum, exception_string);
// Print line of source code. // Print line of source code.
v8::String::Utf8Value sourceline(message->GetSourceLine()); v8::String::Utf8Value sourceline(
message->GetSourceLine(context).ToLocalChecked());
const char* sourceline_string = ToCString(sourceline); const char* sourceline_string = ToCString(sourceline);
fprintf(stderr, "%s\n", sourceline_string); fprintf(stderr, "%s\n", sourceline_string);
// Print wavy underline (GetUnderline is deprecated). // Print wavy underline (GetUnderline is deprecated).
int start = message->GetStartColumn(); int start = message->GetStartColumn(context).FromJust();
for (int i = 0; i < start; i++) { for (int i = 0; i < start; i++) {
fprintf(stderr, " "); fprintf(stderr, " ");
} }
int end = message->GetEndColumn(); int end = message->GetEndColumn(context).FromJust();
for (int i = start; i < end; i++) { for (int i = start; i < end; i++) {
fprintf(stderr, "^"); fprintf(stderr, "^");
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
v8::String::Utf8Value stack_trace(try_catch->StackTrace()); v8::String::Utf8Value stack_trace(
try_catch->StackTrace(context).ToLocalChecked());
if (stack_trace.length() > 0) { if (stack_trace.length() > 0) {
const char* stack_trace_string = ToCString(stack_trace); const char* stack_trace_string = ToCString(stack_trace);
fprintf(stderr, "%s\n", stack_trace_string); fprintf(stderr, "%s\n", stack_trace_string);
......
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