Index: src/JsEngine.cpp |
=================================================================== |
--- a/src/JsEngine.cpp |
+++ b/src/JsEngine.cpp |
@@ -1,28 +1,16 @@ |
#include <AdblockPlus.h> |
#include <sstream> |
#include "GlobalJsObject.h" |
#include "Utils.h" |
namespace |
{ |
- v8::Handle<v8::Context> CreateContext( |
- v8::Isolate* isolate, |
- const AdblockPlus::AppInfo& appInfo, |
- AdblockPlus::JsEngine& jsEngine) |
- { |
- const v8::Locker locker(isolate); |
- const v8::HandleScope handleScope; |
- const v8::Handle<v8::ObjectTemplate> global = |
- AdblockPlus::GlobalJsObject::Create(appInfo, jsEngine); |
- return v8::Context::New(0, global); |
- } |
- |
v8::Handle<v8::Script> CompileScript(const std::string& source, const std::string& filename) |
{ |
const v8::Handle<v8::String> v8Source = v8::String::New(source.c_str()); |
if (filename.length()) |
{ |
const v8::Handle<v8::String> v8Filename = v8::String::New(filename.c_str()); |
return v8::Script::Compile(v8Source, v8Filename); |
} |
@@ -58,19 +46,24 @@ AdblockPlus::JsError::JsError(const v8:: |
{ |
} |
AdblockPlus::JsEngine::JsEngine(const AppInfo& appInfo, |
FileSystem* const fileSystem, |
WebRequest* const webRequest, |
ErrorCallback* const errorCallback) |
: fileSystem(*fileSystem), webRequest(*webRequest), |
- errorCallback(*errorCallback), isolate(v8::Isolate::GetCurrent()), |
- context(CreateContext(isolate, appInfo, *this)) |
+ errorCallback(*errorCallback), isolate(v8::Isolate::GetCurrent()) |
{ |
+ const v8::Locker locker(isolate); |
+ const v8::HandleScope handleScope; |
+ |
+ context = v8::Context::New(); |
+ AdblockPlus::GlobalJsObject::Setup(*this, appInfo, |
+ JsValuePtr(new JsValue(*this, context->Global()))); |
} |
AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& source, |
const std::string& filename) |
{ |
const Context context(*this); |
const v8::TryCatch tryCatch; |
const v8::Handle<v8::Script> script = CompileScript(source, filename); |
@@ -112,16 +105,26 @@ AdblockPlus::JsValuePtr AdblockPlus::JsE |
} |
AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewObject() |
{ |
const Context context(*this); |
return JsValuePtr(new JsValue(*this, v8::Object::New())); |
} |
+AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewCallback( |
+ v8::InvocationCallback callback) |
+{ |
+ const Context context(*this); |
+ |
+ v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(callback, |
+ v8::External::New(this)); |
+ return JsValuePtr(new JsValue(*this, templ->GetFunction())); |
+} |
+ |
AdblockPlus::JsEngine& AdblockPlus::JsEngine::FromArguments(const v8::Arguments& arguments) |
{ |
const v8::Local<const v8::External> external = |
v8::Local<const v8::External>::Cast(arguments.Data()); |
return *static_cast<JsEngine* const>(external->Value()); |
} |
AdblockPlus::JsValueList AdblockPlus::JsEngine::ConvertArguments(const v8::Arguments& arguments) |