Fixes for v8 3.19.18 (0x031918)
This commit is contained in:
parent
013fb3d22d
commit
3d63f9113b
2 changed files with 63 additions and 53 deletions
|
|
@ -214,12 +214,18 @@ void SWIGV8_SetPrivateData(v8::Handle<v8::Object> obj, void* ptr, swig_type_info
|
||||||
} else {
|
} else {
|
||||||
cdata->handle.MakeWeak(cdata, SWIGV8_Proxy_DefaultDtor);
|
cdata->handle.MakeWeak(cdata, SWIGV8_Proxy_DefaultDtor);
|
||||||
}
|
}
|
||||||
#else
|
#elif (SWIG_V8_VERSION < 0x031918)
|
||||||
if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) {
|
if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) {
|
||||||
cdata->handle.MakeWeak(v8::Isolate::GetCurrent(), cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor);
|
cdata->handle.MakeWeak(v8::Isolate::GetCurrent(), cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor);
|
||||||
} else {
|
} else {
|
||||||
cdata->handle.MakeWeak(v8::Isolate::GetCurrent(), cdata, SWIGV8_Proxy_DefaultDtor);
|
cdata->handle.MakeWeak(v8::Isolate::GetCurrent(), cdata, SWIGV8_Proxy_DefaultDtor);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) {
|
||||||
|
cdata->handle.MakeWeak(cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor);
|
||||||
|
} else {
|
||||||
|
cdata->handle.MakeWeak(cdata, SWIGV8_Proxy_DefaultDtor);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (SWIG_V8_VERSION < 0x031710)
|
#if (SWIG_V8_VERSION < 0x031710)
|
||||||
|
|
@ -463,8 +469,10 @@ v8::Handle<v8::Value> SWIGV8_NewPackedObj(void *data, size_t size, swig_type_inf
|
||||||
|
|
||||||
#if (SWIG_V8_VERSION < 0x031710)
|
#if (SWIG_V8_VERSION < 0x031710)
|
||||||
cdata->handle.MakeWeak(cdata, _wrap_SwigV8PackedData_delete);
|
cdata->handle.MakeWeak(cdata, _wrap_SwigV8PackedData_delete);
|
||||||
#else
|
#elif (SWIG_V8_VERSION < 0x031918)
|
||||||
cdata->handle.MakeWeak(v8::Isolate::GetCurrent(), cdata, _wrap_SwigV8PackedData_delete);
|
cdata->handle.MakeWeak(v8::Isolate::GetCurrent(), cdata, _wrap_SwigV8PackedData_delete);
|
||||||
|
#else
|
||||||
|
cdata->handle.MakeWeak(cdata, _wrap_SwigV8PackedData_delete);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (SWIG_V8_VERSION < 0x031710)
|
#if (SWIG_V8_VERSION < 0x031710)
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,11 @@ private:
|
||||||
|
|
||||||
v8::Handle<v8::Value> Import(const std::string& moduleName);
|
v8::Handle<v8::Value> Import(const std::string& moduleName);
|
||||||
|
|
||||||
|
#if (V8_VERSION < 0x031900)
|
||||||
v8::Persistent<v8::Context> CreateShellContext();
|
v8::Persistent<v8::Context> CreateShellContext();
|
||||||
|
#else
|
||||||
|
v8::Local<v8::Context> CreateShellContext();
|
||||||
|
#endif
|
||||||
|
|
||||||
void ReportException(v8::TryCatch* handler);
|
void ReportException(v8::TryCatch* handler);
|
||||||
|
|
||||||
|
|
@ -49,11 +53,6 @@ private:
|
||||||
|
|
||||||
static const char* ToCString(const v8::String::Utf8Value& value);
|
static const char* ToCString(const v8::String::Utf8Value& value);
|
||||||
|
|
||||||
virtual bool _ExecuteScript(const std::string& source, const std::string& scriptPath);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
v8::Persistent<v8::Context> context;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
|
|
@ -68,47 +67,25 @@ V8Shell::V8Shell(){}
|
||||||
V8Shell::~V8Shell() {}
|
V8Shell::~V8Shell() {}
|
||||||
|
|
||||||
bool V8Shell::RunScript(const std::string& scriptPath) {
|
bool V8Shell::RunScript(const std::string& scriptPath) {
|
||||||
|
std::string source = ReadFile(scriptPath);
|
||||||
|
|
||||||
if (!context.IsEmpty()) {
|
v8::HandleScope scope;
|
||||||
#if (V8_VERSION < 0x031710)
|
|
||||||
context.Dispose();
|
#if (V8_VERSION < 0x031900)
|
||||||
#elif (V8_VERSION < 0x031900)
|
v8::Persistent<v8::Context> context = CreateShellContext();
|
||||||
context.Dispose(v8::Isolate::GetCurrent());
|
|
||||||
#else
|
#else
|
||||||
context.Dispose();
|
v8::Local<v8::Context> context = CreateShellContext();
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
std::string source = ReadFile(scriptPath);
|
|
||||||
|
|
||||||
context = CreateShellContext();
|
|
||||||
if (context.IsEmpty()) {
|
if (context.IsEmpty()) {
|
||||||
printf("Could not create context.\n");
|
printf("Could not create context.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
context->Enter();
|
|
||||||
|
|
||||||
bool success = _ExecuteScript(source, scriptPath);
|
context->Enter();
|
||||||
|
|
||||||
context->Exit();
|
|
||||||
|
|
||||||
#if (V8_VERSION < 0x031710)
|
|
||||||
context.Dispose();
|
|
||||||
#elif (V8_VERSION < 0x031900)
|
|
||||||
context.Dispose(v8::Isolate::GetCurrent());
|
|
||||||
#else
|
|
||||||
context.Dispose();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
v8::V8::Dispose();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool V8Shell::_ExecuteScript(const std::string& source, const std::string& scriptPath) {
|
|
||||||
v8::HandleScope scope;
|
|
||||||
|
|
||||||
// Store a pointer to this shell for later use
|
// Store a pointer to this shell for later use
|
||||||
|
|
||||||
v8::Handle<v8::Object> global = context->Global();
|
v8::Handle<v8::Object> global = context->Global();
|
||||||
v8::Local<v8::External> __shell__ = v8::External::New((void*) (long) this);
|
v8::Local<v8::External> __shell__ = v8::External::New((void*) (long) this);
|
||||||
global->SetHiddenValue(v8::String::New("__shell__"), __shell__);
|
global->SetHiddenValue(v8::String::New("__shell__"), __shell__);
|
||||||
|
|
@ -116,26 +93,34 @@ bool V8Shell::_ExecuteScript(const std::string& source, const std::string& scrip
|
||||||
// Node.js compatibility: make `print` available as `console.log()`
|
// Node.js compatibility: make `print` available as `console.log()`
|
||||||
ExecuteScript("var console = {}; console.log = print;", "<console>");
|
ExecuteScript("var console = {}; console.log = print;", "<console>");
|
||||||
|
|
||||||
if(!ExecuteScript(source, scriptPath)) {
|
bool success = ExecuteScript(source, scriptPath);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
// Cleanup
|
||||||
}
|
|
||||||
|
|
||||||
bool V8Shell::RunShell() {
|
context->Exit();
|
||||||
|
|
||||||
if (!context.IsEmpty()) {
|
|
||||||
#if (V8_VERSION < 0x031710)
|
#if (V8_VERSION < 0x031710)
|
||||||
context.Dispose();
|
context.Dispose();
|
||||||
#elif (V8_VERSION < 0x031900)
|
#elif (V8_VERSION < 0x031900)
|
||||||
context.Dispose(v8::Isolate::GetCurrent());
|
context.Dispose(v8::Isolate::GetCurrent());
|
||||||
#else
|
#else
|
||||||
context.Dispose();
|
// context.Dispose();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// v8::V8::Dispose();
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool V8Shell::RunShell() {
|
||||||
|
v8::HandleScope scope;
|
||||||
|
|
||||||
|
#if (V8_VERSION < 0x031900)
|
||||||
|
v8::Persistent<v8::Context> context = CreateShellContext();
|
||||||
|
#else
|
||||||
|
v8::Local<v8::Context> context = CreateShellContext();
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
context = CreateShellContext();
|
|
||||||
if (context.IsEmpty()) {
|
if (context.IsEmpty()) {
|
||||||
printf("Could not create context.\n");
|
printf("Could not create context.\n");
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -158,15 +143,19 @@ bool V8Shell::RunShell() {
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
|
||||||
context->Exit();
|
context->Exit();
|
||||||
|
|
||||||
#if (V8_VERSION < 0x031710)
|
#if (V8_VERSION < 0x031710)
|
||||||
context.Dispose();
|
context.Dispose();
|
||||||
#elif (V8_VERSION < 0x031900)
|
#elif (V8_VERSION < 0x031900)
|
||||||
context.Dispose(v8::Isolate::GetCurrent());
|
context.Dispose(v8::Isolate::GetCurrent());
|
||||||
#else
|
#else
|
||||||
context.Dispose();
|
// context.Dispose();
|
||||||
#endif
|
#endif
|
||||||
v8::V8::Dispose();
|
|
||||||
|
// v8::V8::Dispose();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -203,7 +192,11 @@ bool V8Shell::DisposeEngine() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (V8_VERSION < 0x031900)
|
||||||
v8::Persistent<v8::Context> V8Shell::CreateShellContext() {
|
v8::Persistent<v8::Context> V8Shell::CreateShellContext() {
|
||||||
|
#else
|
||||||
|
v8::Local<v8::Context> V8Shell::CreateShellContext() {
|
||||||
|
#endif
|
||||||
v8::HandleScope scope;
|
v8::HandleScope scope;
|
||||||
|
|
||||||
// Create a template for the global object.
|
// Create a template for the global object.
|
||||||
|
|
@ -215,9 +208,18 @@ v8::Persistent<v8::Context> V8Shell::CreateShellContext() {
|
||||||
global->Set(v8::String::New("require"), v8::FunctionTemplate::New(V8Shell::Require));
|
global->Set(v8::String::New("require"), v8::FunctionTemplate::New(V8Shell::Require));
|
||||||
global->Set(v8::String::New("version"), v8::FunctionTemplate::New(V8Shell::Version));
|
global->Set(v8::String::New("version"), v8::FunctionTemplate::New(V8Shell::Version));
|
||||||
|
|
||||||
v8::Persistent<v8::Context> _context = v8::Context::New(NULL, global);
|
|
||||||
|
|
||||||
return _context;
|
#if (V8_VERSION < 0x031900)
|
||||||
|
v8::Persistent<v8::Context> context = v8::Context::New(NULL, global);
|
||||||
|
return context;
|
||||||
|
#else
|
||||||
|
// v8::Local<v8::Context> context_ = v8::Context::New(v8::Isolate::GetCurrent(), NULL, global);
|
||||||
|
// v8::Persistent<v8::Context> context;
|
||||||
|
// context.Reset(v8::Isolate::GetCurrent(), context_);
|
||||||
|
v8::Local<v8::Context> context = v8::Context::New(v8::Isolate::GetCurrent(), NULL, global);
|
||||||
|
return scope.Close(context);
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Handle<v8::Value> V8Shell::Import(const std::string& module_path)
|
v8::Handle<v8::Value> V8Shell::Import(const std::string& module_path)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue