Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/JsValue.cpp

Issue 29813591: Issue 6526 - Use Maybe<> version of soon to be deprecated API in v8 6.7 (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Rebased Created Aug. 6, 2018, 7:30 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/JsEngine.cpp ('k') | src/Utils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
« no previous file with comments | « src/JsEngine.cpp ('k') | src/Utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld