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

Unified Diff: src/JsValue.cpp

Issue 10184021: Some refactoring of global JavaScript objects (Closed)
Patch Set: Unbitrotted patch Created April 16, 2013, 3:32 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/WebRequestJsObject.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
@@ -26,51 +26,59 @@ AdblockPlus::JsValue::JsValue(AdblockPlu
AdblockPlus::JsValue::~JsValue()
{
value.Dispose(jsEngine.isolate);
}
bool AdblockPlus::JsValue::IsUndefined() const
{
+ const JsEngine::Context context(jsEngine);
return value->IsUndefined();
}
bool AdblockPlus::JsValue::IsNull() const
{
+ const JsEngine::Context context(jsEngine);
return value->IsNull();
}
bool AdblockPlus::JsValue::IsString() const
{
+ const JsEngine::Context context(jsEngine);
return value->IsString() || value->IsStringObject();
}
bool AdblockPlus::JsValue::IsNumber() const
{
+ const JsEngine::Context context(jsEngine);
return value->IsNumber() || value->IsNumberObject();
}
bool AdblockPlus::JsValue::IsBool() const
{
+ const JsEngine::Context context(jsEngine);
return value->IsBoolean() || value->IsBooleanObject();
}
bool AdblockPlus::JsValue::IsObject() const
{
+ const JsEngine::Context context(jsEngine);
return value->IsObject();
}
bool AdblockPlus::JsValue::IsArray() const
{
+ const JsEngine::Context context(jsEngine);
return value->IsArray();
}
bool AdblockPlus::JsValue::IsFunction() const
{
+ const JsEngine::Context context(jsEngine);
return value->IsFunction();
}
std::string AdblockPlus::JsValue::AsString() const
{
const JsEngine::Context context(jsEngine);
return fromV8String(value);
}
@@ -99,16 +107,31 @@ AdblockPlus::JsValueList AdblockPlus::Js
for (uint32_t i = 0; i < length; i++)
{
v8::Local<v8::Value> item = array->Get(i);
result.push_back(JsValuePtr(new JsValue(jsEngine, item)));
}
return result;
}
+std::vector<std::string> AdblockPlus::JsValue::GetOwnPropertyNames() const
+{
+ if (!IsObject())
+ throw new std::runtime_error("Attempting to get propert list for a non-object");
+
+ const JsEngine::Context context(jsEngine);
+ const v8::Persistent<v8::Object> object = v8::Persistent<v8::Object>::Cast(value);
+ JsValueList properties = JsValuePtr(new JsValue(jsEngine, object->GetOwnPropertyNames()))->AsList();
+ std::vector<std::string> result;
+ for (JsValueList::iterator it = properties.begin(); it != properties.end(); ++it)
+ result.push_back((*it)->AsString());
+ return result;
+}
+
+
AdblockPlus::JsValuePtr AdblockPlus::JsValue::GetProperty(const std::string& name) const
{
if (!IsObject())
throw new std::runtime_error("Attempting to get property of a non-object");
const JsEngine::Context context(jsEngine);
v8::Local<v8::String> property = toV8String(name);
v8::Persistent<v8::Object> obj = v8::Persistent<v8::Object>::Cast(value);
@@ -132,16 +155,22 @@ void AdblockPlus::JsValue::SetProperty(c
}
void AdblockPlus::JsValue::SetProperty(const std::string& name, int64_t val)
{
const JsEngine::Context context(jsEngine);
SetProperty(name, v8::Integer::New(val));
}
+void AdblockPlus::JsValue::SetProperty(const std::string& name, JsValuePtr val)
+{
+ const JsEngine::Context context(jsEngine);
+ SetProperty(name, val->value);
+}
+
void AdblockPlus::JsValue::SetProperty(const std::string& name, bool val)
{
const JsEngine::Context context(jsEngine);
SetProperty(name, v8::Boolean::New(val));
}
std::string AdblockPlus::JsValue::GetClassName() const
{
« no previous file with comments | « src/JsEngine.cpp ('k') | src/WebRequestJsObject.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld