Index: src/JsValue.cpp |
=================================================================== |
--- a/src/JsValue.cpp |
+++ b/src/JsValue.cpp |
@@ -31,9 +31,9 @@ |
{ |
} |
-JsValue::JsValue(const JsValuePtr& value) |
- : jsEngine(value->jsEngine) |
- , value(value->value) |
+JsValue::JsValue(JsValue&& src) |
+ : jsEngine{src.jsEngine} |
+ , value{std::move(src.value)} |
{ |
} |
@@ -44,70 +44,70 @@ |
bool JsValue::IsUndefined() const |
{ |
- const JsContext context(jsEngine); |
+ const JsContext context{*jsEngine}; |
return unwrapValue()->IsUndefined(); |
} |
bool JsValue::IsNull() const |
{ |
- const JsContext context(jsEngine); |
+ const JsContext context{*jsEngine}; |
return unwrapValue()->IsNull(); |
} |
bool JsValue::IsString() const |
{ |
- const JsContext context(jsEngine); |
+ const JsContext context{*jsEngine}; |
auto value = unwrapValue(); |
return value->IsString() || value->IsStringObject(); |
} |
bool JsValue::IsNumber() const |
{ |
- const JsContext context(jsEngine); |
+ const JsContext context{*jsEngine}; |
auto value = unwrapValue(); |
return value->IsNumber() || value->IsNumberObject(); |
} |
bool JsValue::IsBool() const |
{ |
- const JsContext context(jsEngine); |
+ const JsContext context{*jsEngine}; |
auto value = unwrapValue(); |
return value->IsBoolean() || value->IsBooleanObject(); |
} |
bool JsValue::IsObject() const |
{ |
- const JsContext context(jsEngine); |
+ const JsContext context{*jsEngine}; |
return unwrapValue()->IsObject(); |
} |
bool JsValue::IsArray() const |
{ |
- const JsContext context(jsEngine); |
+ const JsContext context{*jsEngine}; |
return unwrapValue()->IsArray(); |
} |
bool JsValue::IsFunction() const |
{ |
- const JsContext context(jsEngine); |
+ const JsContext context{*jsEngine}; |
return unwrapValue()->IsFunction(); |
} |
std::string JsValue::AsString() const |
{ |
- const JsContext context(jsEngine); |
+ const JsContext context{*jsEngine}; |
return Utils::FromV8String(unwrapValue()); |
} |
int64_t JsValue::AsInt() const |
{ |
- const JsContext context(jsEngine); |
+ const JsContext context{*jsEngine}; |
return unwrapValue()->IntegerValue(); |
} |
bool JsValue::AsBool() const |
{ |
- const JsContext context(jsEngine); |
+ const JsContext context{*jsEngine}; |
return unwrapValue()->BooleanValue(); |
} |
@@ -116,14 +116,14 @@ |
if (!IsArray()) |
throw std::runtime_error("Cannot convert a non-array to list"); |
- const JsContext context(jsEngine); |
+ const JsContext context{*jsEngine}; |
JsValueList result; |
auto 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); |
- result.push_back(std::make_shared<JsValue>(jsEngine, item, PrivateCtrArg())); |
+ result.emplace_back(std::make_shared<JsValue>(jsEngine, item, PrivateCtrArg{})); |
} |
return result; |
} |
@@ -133,12 +133,12 @@ |
if (!IsObject()) |
throw new std::runtime_error("Attempting to get propert list for a non-object"); |
- const JsContext context(jsEngine); |
+ const JsContext context{*jsEngine}; |
std::vector<std::string> result; |
auto object = v8::Local<v8::Object>::Cast(unwrapValue()); |
- JsValueList properties = std::make_shared<JsValue>(jsEngine, object->GetOwnPropertyNames(), PrivateCtrArg())->AsList(); |
- for (JsValueList::iterator it = properties.begin(); it != properties.end(); ++it) |
- result.push_back((*it)->AsString()); |
+ JsValueList properties = std::make_shared<JsValue>(jsEngine, object->GetOwnPropertyNames(), PrivateCtrArg{})->AsList(); |
+ for(const auto& property : properties) |
+ result.emplace_back(property->AsString()); |
return result; |
} |
@@ -148,10 +148,10 @@ |
if (!IsObject()) |
throw new std::runtime_error("Attempting to get property of a non-object"); |
- const JsContext context(jsEngine); |
+ const JsContext context{*jsEngine}; |
v8::Local<v8::String> property = Utils::ToV8String(jsEngine->isolate, name); |
auto obj = v8::Local<v8::Object>::Cast(unwrapValue()); |
- return std::make_shared<JsValue>(jsEngine, obj->Get(property), PrivateCtrArg()); |
+ return std::make_shared<JsValue>(jsEngine, obj->Get(property), PrivateCtrArg{}); |
} |
void JsValue::SetProperty(const std::string& name, const v8::Handle<v8::Value> val) |
@@ -171,26 +171,26 @@ |
void JsValue::SetProperty(const std::string& name, const std::string& val) |
{ |
- const JsContext context(jsEngine); |
+ const JsContext context{*jsEngine}; |
SetProperty(name, Utils::ToV8String(jsEngine->isolate, val)); |
} |
void JsValue::SetProperty(const std::string& name, int64_t val) |
{ |
- const JsContext context(jsEngine); |
+ const JsContext context{*jsEngine}; |
SetProperty(name, v8::Number::New(jsEngine->isolate, val)); |
} |
void JsValue::SetProperty(const std::string& name, const JsValuePtr& val) |
{ |
- const JsContext context(jsEngine); |
+ const JsContext context{*jsEngine}; |
SetProperty(name, val->unwrapValue()); |
} |
void JsValue::SetProperty(const std::string& name, bool val) |
{ |
- const JsContext context(jsEngine); |
- SetProperty(name, v8::Boolean::New(val)); |
+ const JsContext context{*jsEngine}; |
+ SetProperty(name, v8::Boolean::New(jsEngine->isolate, val)); |
} |
std::string JsValue::GetClass() const |
@@ -198,14 +198,14 @@ |
if (!IsObject()) |
throw new std::runtime_error("Cannot get constructor of a non-object"); |
- const JsContext context(jsEngine); |
+ const JsContext context{*jsEngine}; |
auto obj = v8::Local<v8::Object>::Cast(unwrapValue()); |
return Utils::FromV8String(obj->GetConstructorName()); |
} |
JsValuePtr JsValue::Call(const JsValueList& params, JsValuePtr thisPtr) const |
{ |
- const JsContext context(jsEngine); |
+ const JsContext context{*jsEngine}; |
if (!IsFunction()) |
throw new std::runtime_error("Attempting to call a non-function"); |
@@ -213,15 +213,15 @@ |
if (!thisPtr) |
{ |
auto localContext = v8::Local<v8::Context>::New(jsEngine->isolate, jsEngine->context); |
- thisPtr = std::make_shared<JsValue>(jsEngine, localContext->Global(), PrivateCtrArg()); |
+ thisPtr = std::make_shared<JsValue>(jsEngine, localContext->Global(), PrivateCtrArg{}); |
} |
if (!thisPtr->IsObject()) |
throw new std::runtime_error("`this` pointer has to be an object"); |
auto thisObj = v8::Local<v8::Object>::Cast(thisPtr->unwrapValue()); |
std::vector<v8::Handle<v8::Value>> argv; |
- for (JsValueList::const_iterator it = params.begin(); it != params.end(); ++it) |
- argv.push_back((*it)->unwrapValue()); |
+ for (const auto& param : params) |
+ argv.emplace_back(param->unwrapValue()); |
const v8::TryCatch tryCatch; |
auto func = v8::Local<v8::Function>::Cast(unwrapValue()); |
@@ -231,5 +231,5 @@ |
if (tryCatch.HasCaught()) |
throw JsError(tryCatch.Exception(), tryCatch.Message()); |
- return std::make_shared<JsValue>(jsEngine, result, JsValue::Private::CtrArg()); |
+ return std::make_shared<JsValue>(jsEngine, result, JsValue::Private::CtrArg{}); |
} |