Index: src/JsValue.cpp |
=================================================================== |
--- a/src/JsValue.cpp |
+++ b/src/JsValue.cpp |
@@ -131,50 +131,60 @@ |
{ |
const JsContext context(*jsEngine); |
return Utils::StringBufferFromV8String(jsEngine->GetIsolate(), UnwrapValue()); |
} |
int64_t AdblockPlus::JsValue::AsInt() const |
{ |
const JsContext context(*jsEngine); |
- return UnwrapValue()->IntegerValue(); |
+ auto currentContext = jsEngine->GetIsolate()->GetCurrentContext(); |
+ auto value = UnwrapValue()->IntegerValue(currentContext); |
+ return value.IsJust() ? value.FromJust() : 0; |
sergei
2018/08/07 13:14:52
What about using of CheckedToValue here?
Returning
hub
2018/08/07 14:36:48
I wanted to avoid throwing an exception. But it se
|
} |
bool AdblockPlus::JsValue::AsBool() const |
{ |
const JsContext context(*jsEngine); |
- return UnwrapValue()->BooleanValue(); |
+ auto currentContext = jsEngine->GetIsolate()->GetCurrentContext(); |
+ auto value = UnwrapValue()->BooleanValue(currentContext); |
+ return value.IsJust() ? value.FromJust() : false; |
} |
AdblockPlus::JsValueList AdblockPlus::JsValue::AsList() const |
{ |
if (!IsArray()) |
throw std::runtime_error("Cannot convert a non-array to list"); |
const JsContext context(*jsEngine); |
+ auto isolate = jsEngine->GetIsolate(); |
+ auto currentContext = isolate->GetCurrentContext(); |
JsValueList result; |
v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(UnwrapValue()); |
uint32_t length = array->Length(); |
for (uint32_t i = 0; i < length; i++) |
{ |
- v8::Local<v8::Value> item = array->Get(i); |
+ v8::Local<v8::Value> item = CHECKED_TO_LOCAL( |
+ isolate, array->Get(currentContext, i)); |
result.push_back(JsValue(jsEngine, item)); |
} |
return result; |
} |
std::vector<std::string> AdblockPlus::JsValue::GetOwnPropertyNames() const |
{ |
if (!IsObject()) |
throw std::runtime_error("Attempting to get propert list for a non-object"); |
const JsContext context(*jsEngine); |
+ auto isolate = jsEngine->GetIsolate(); |
v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(UnwrapValue()); |
- JsValueList properties = JsValue(jsEngine, object->GetOwnPropertyNames()).AsList(); |
+ auto propertyNames = CHECKED_TO_LOCAL(isolate, |
+ object->GetOwnPropertyNames(isolate->GetCurrentContext())); |
+ JsValueList properties = JsValue(jsEngine, propertyNames).AsList(); |
std::vector<std::string> result; |
for (const auto& property : properties) |
result.push_back(property.AsString()); |
return result; |
} |
AdblockPlus::JsValue AdblockPlus::JsValue::GetProperty(const std::string& name) const |
@@ -195,17 +205,17 @@ |
{ |
if (!IsObject()) |
throw std::runtime_error("Attempting to set property on a non-object"); |
auto isolate = jsEngine->GetIsolate(); |
v8::Local<v8::String> property = CHECKED_TO_LOCAL( |
isolate, Utils::ToV8String(isolate, name)); |
v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(UnwrapValue()); |
- obj->Set(property, val); |
+ CHECKED_TO_VALUE(obj->Set(isolate->GetCurrentContext(), property, val)); |
} |
v8::Local<v8::Value> AdblockPlus::JsValue::UnwrapValue() const |
{ |
return v8::Local<v8::Value>::New(jsEngine->GetIsolate(), *value); |
} |
void AdblockPlus::JsValue::SetProperty(const std::string& name, const std::string& val) |