Index: src/JsValue.cpp |
=================================================================== |
--- a/src/JsValue.cpp |
+++ b/src/JsValue.cpp |
@@ -24,27 +24,27 @@ |
using namespace AdblockPlus; |
-AdblockPlus::JsValue::JsValue(AdblockPlus::JsEnginePtr jsEngine, |
+template <> JSVALUEV8::JsValueTemplate(AdblockPlus::JsEnginePtr jsEngine, |
v8::Handle<v8::Value> value) |
: jsEngine(jsEngine), |
value(new v8::Global<v8::Value>(jsEngine->GetIsolate(), value)) |
{ |
} |
-AdblockPlus::JsValue::JsValue(AdblockPlus::JsValue&& src) |
+template <> JSVALUEV8::JsValueTemplate(JSVALUEV8&& src) |
: jsEngine(src.jsEngine), |
value(std::move(src.value)) |
{ |
} |
-AdblockPlus::JsValue::JsValue(const JsValue& src) |
+template <> JSVALUEV8::JsValueTemplate(const JSVALUEV8& src) |
: jsEngine(src.jsEngine) |
{ |
const JsContext context(*src.jsEngine); |
value.reset(new v8::Global<v8::Value>(src.jsEngine->GetIsolate(), *src.value)); |
} |
-AdblockPlus::JsValue::~JsValue() |
+template <> JSVALUEV8::~JsValueTemplate() |
{ |
if (value) |
{ |
@@ -53,7 +53,7 @@ |
} |
} |
-JsValue& AdblockPlus::JsValue::operator=(const JsValue& src) |
+template <> JSVALUEV8& JSVALUEV8::operator=(const JSVALUEV8& src) |
{ |
const JsContext context(*src.jsEngine); |
jsEngine = src.jsEngine; |
@@ -62,7 +62,7 @@ |
return *this; |
} |
-JsValue& AdblockPlus::JsValue::operator=(JsValue&& src) |
+template <> JSVALUEV8& AdblockPlus::JSVALUEV8::operator=(JSVALUEV8&& src) |
{ |
jsEngine = std::move(src.jsEngine); |
value = std::move(src.value); |
@@ -70,82 +70,82 @@ |
return *this; |
} |
-bool AdblockPlus::JsValue::IsUndefined() const |
+template <> bool AdblockPlus::JSVALUEV8::IsUndefined() const |
{ |
const JsContext context(*jsEngine); |
return UnwrapValue()->IsUndefined(); |
} |
-bool AdblockPlus::JsValue::IsNull() const |
+template <> bool AdblockPlus::JSVALUEV8::IsNull() const |
{ |
const JsContext context(*jsEngine); |
return UnwrapValue()->IsNull(); |
} |
-bool AdblockPlus::JsValue::IsString() const |
+template <> bool AdblockPlus::JSVALUEV8::IsString() const |
{ |
const JsContext context(*jsEngine); |
v8::Local<v8::Value> value = UnwrapValue(); |
return value->IsString() || value->IsStringObject(); |
} |
-bool AdblockPlus::JsValue::IsNumber() const |
+template <> bool AdblockPlus::JSVALUEV8::IsNumber() const |
{ |
const JsContext context(*jsEngine); |
v8::Local<v8::Value> value = UnwrapValue(); |
return value->IsNumber() || value->IsNumberObject(); |
} |
-bool AdblockPlus::JsValue::IsBool() const |
+template <> bool AdblockPlus::JSVALUEV8::IsBool() const |
{ |
const JsContext context(*jsEngine); |
v8::Local<v8::Value> value = UnwrapValue(); |
return value->IsBoolean() || value->IsBooleanObject(); |
} |
-bool AdblockPlus::JsValue::IsObject() const |
+template <> bool AdblockPlus::JSVALUEV8::IsObject() const |
{ |
const JsContext context(*jsEngine); |
return UnwrapValue()->IsObject(); |
} |
-bool AdblockPlus::JsValue::IsArray() const |
+template <> bool AdblockPlus::JSVALUEV8::IsArray() const |
{ |
const JsContext context(*jsEngine); |
return UnwrapValue()->IsArray(); |
} |
-bool AdblockPlus::JsValue::IsFunction() const |
+template <> bool AdblockPlus::JSVALUEV8::IsFunction() const |
{ |
const JsContext context(*jsEngine); |
return UnwrapValue()->IsFunction(); |
} |
-std::string AdblockPlus::JsValue::AsString() const |
+template <> std::string AdblockPlus::JSVALUEV8::AsString() const |
{ |
const JsContext context(*jsEngine); |
return Utils::FromV8String(UnwrapValue()); |
} |
-StringBuffer AdblockPlus::JsValue::AsStringBuffer() const |
+template <> StringBuffer AdblockPlus::JSVALUEV8::AsStringBuffer() const |
{ |
const JsContext context(*jsEngine); |
return Utils::StringBufferFromV8String(UnwrapValue()); |
} |
-int64_t AdblockPlus::JsValue::AsInt() const |
+template <> int64_t AdblockPlus::JSVALUEV8::AsInt() const |
{ |
const JsContext context(*jsEngine); |
return UnwrapValue()->IntegerValue(); |
} |
-bool AdblockPlus::JsValue::AsBool() const |
+template <> bool AdblockPlus::JSVALUEV8::AsBool() const |
{ |
const JsContext context(*jsEngine); |
return UnwrapValue()->BooleanValue(); |
} |
-AdblockPlus::JsValueList AdblockPlus::JsValue::AsList() const |
+template <> AdblockPlus::JsValueList AdblockPlus::JSVALUEV8::AsList() const |
{ |
if (!IsArray()) |
throw std::runtime_error("Cannot convert a non-array to list"); |
@@ -162,7 +162,7 @@ |
return result; |
} |
-std::vector<std::string> AdblockPlus::JsValue::GetOwnPropertyNames() const |
+template <> std::vector<std::string> AdblockPlus::JSVALUEV8::GetOwnPropertyNames() const |
{ |
if (!IsObject()) |
throw std::runtime_error("Attempting to get propert list for a non-object"); |
@@ -177,7 +177,7 @@ |
} |
-AdblockPlus::JsValue AdblockPlus::JsValue::GetProperty(const std::string& name) const |
+template <> AdblockPlus::JsValue AdblockPlus::JSVALUEV8::GetProperty(const std::string& name) const |
{ |
if (!IsObject()) |
throw std::runtime_error("Attempting to get property of a non-object"); |
@@ -188,7 +188,7 @@ |
return JsValue(jsEngine, obj->Get(property)); |
} |
-void AdblockPlus::JsValue::SetProperty(const std::string& name, v8::Handle<v8::Value> val) |
+template <> void AdblockPlus::JSVALUEV8::SetProperty(const std::string& name, v8::Handle<v8::Value> val) |
{ |
if (!IsObject()) |
throw std::runtime_error("Attempting to set property on a non-object"); |
@@ -198,42 +198,42 @@ |
obj->Set(property, val); |
} |
-v8::Local<v8::Value> AdblockPlus::JsValue::UnwrapValue() const |
+template <> JsEngineNamespaceImpl::LocalValue AdblockPlus::JSVALUEV8::UnwrapValue() const |
{ |
return v8::Local<v8::Value>::New(jsEngine->GetIsolate(), *value); |
} |
-void AdblockPlus::JsValue::SetProperty(const std::string& name, const std::string& val) |
+template <> void AdblockPlus::JSVALUEV8::SetProperty(const std::string& name, const std::string& val) |
{ |
const JsContext context(*jsEngine); |
SetProperty(name, Utils::ToV8String(jsEngine->GetIsolate(), val)); |
} |
-void AdblockPlus::JsValue::SetStringBufferProperty(const std::string& name, const StringBuffer& val) |
+template <> void AdblockPlus::JSVALUEV8::SetStringBufferProperty(const std::string& name, const StringBuffer& val) |
{ |
const JsContext context(*jsEngine); |
SetProperty(name, Utils::StringBufferToV8String(jsEngine->GetIsolate(), val)); |
} |
-void AdblockPlus::JsValue::SetProperty(const std::string& name, int64_t val) |
+template <> void AdblockPlus::JSVALUEV8::SetProperty(const std::string& name, int64_t val) |
{ |
const JsContext context(*jsEngine); |
SetProperty(name, v8::Number::New(jsEngine->GetIsolate(), val)); |
} |
-void AdblockPlus::JsValue::SetProperty(const std::string& name, const JsValue& val) |
+template <> void AdblockPlus::JSVALUEV8::SetProperty(const std::string& name, const JsValue& val) |
{ |
const JsContext context(*jsEngine); |
SetProperty(name, val.UnwrapValue()); |
} |
-void AdblockPlus::JsValue::SetProperty(const std::string& name, bool val) |
+template <> void AdblockPlus::JSVALUEV8::SetProperty(const std::string& name, bool val) |
{ |
const JsContext context(*jsEngine); |
SetProperty(name, v8::Boolean::New(jsEngine->GetIsolate(), val)); |
} |
-std::string AdblockPlus::JsValue::GetClass() const |
+template <> std::string AdblockPlus::JSVALUEV8::GetClass() const |
{ |
if (!IsObject()) |
throw std::runtime_error("Cannot get constructor of a non-object"); |
@@ -243,17 +243,17 @@ |
return Utils::FromV8String(obj->GetConstructorName()); |
} |
-JsValue JsValue::Call(const JsValueList& params) const |
+template <> JsValue JSVALUEV8::Call(const JsValueList& params) const |
{ |
const JsContext context(*jsEngine); |
std::vector<v8::Handle<v8::Value>> argv; |
for (const auto& param : params) |
argv.push_back(param.UnwrapValue()); |
- return Call(argv, context.GetV8Context()->Global()); |
+ return Call(argv, context.GetJSEngineContext()->Global()); |
} |
-JsValue JsValue::Call(const JsValueList& params, const JsValue& thisValue) const |
+template <> JsValue JSVALUEV8::Call(const JsValueList& params, const JsValue& thisValue) const |
{ |
const JsContext context(*jsEngine); |
v8::Local<v8::Object> thisObj = v8::Local<v8::Object>::Cast(thisValue.UnwrapValue()); |
@@ -265,17 +265,17 @@ |
return Call(argv, thisObj); |
} |
-JsValue JsValue::Call(const JsValue& arg) const |
+template <> JsValue JSVALUEV8::Call(const JsValue& arg) const |
{ |
const JsContext context(*jsEngine); |
std::vector<v8::Handle<v8::Value>> argv; |
argv.push_back(arg.UnwrapValue()); |
- return Call(argv, context.GetV8Context()->Global()); |
+ return Call(argv, context.GetJSEngineContext()->Global()); |
} |
-JsValue JsValue::Call(std::vector<v8::Handle<v8::Value>>& args, v8::Local<v8::Object> thisObj) const |
+template <> JsValue JSVALUEV8::Call(std::vector<v8::Handle<v8::Value>>& args, v8::Local<v8::Object> thisObj) const |
{ |
if (!IsFunction()) |
throw std::runtime_error("Attempting to call a non-function"); |