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

Unified Diff: src/ConsoleJsObject.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/ConsoleJsObject.h ('k') | src/FileSystemJsObject.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ConsoleJsObject.cpp
===================================================================
--- a/src/ConsoleJsObject.cpp
+++ b/src/ConsoleJsObject.cpp
@@ -1,45 +1,43 @@
+#include <AdblockPlus/JsEngine.h>
+#include <AdblockPlus/JsValue.h>
#include <AdblockPlus/ErrorCallback.h>
#include <sstream>
#include "ConsoleJsObject.h"
namespace
{
v8::Handle<v8::Value> ErrorCallback(const v8::Arguments& arguments)
{
+ AdblockPlus::JsEngine& jsEngine = AdblockPlus::JsEngine::FromArguments(arguments);
+ const AdblockPlus::JsEngine::Context context(jsEngine);
+ AdblockPlus::JsValueList converted = jsEngine.ConvertArguments(arguments);
+
std::stringstream message;
- const v8::HandleScope handleScope;
- for (int i = 0; i < arguments.Length(); i++)
- {
- const v8::Handle<v8::Value> argument = arguments[i];
- const v8::String::Utf8Value value(argument);
- message << *value;
- }
- const v8::Handle<const v8::External> external =
- v8::Handle<const v8::External>::Cast(arguments.Data());
- AdblockPlus::ErrorCallback* const errorCallback =
- static_cast<AdblockPlus::ErrorCallback*>(external->Value());
- (*errorCallback)(message.str());
+ for (size_t i = 0; i < converted.size(); i++)
+ message << converted[i]->AsString();
+
+ (jsEngine.GetErrorCallback())(message.str());
return v8::Undefined();
}
v8::Handle<v8::Value> TraceCallback(const v8::Arguments& arguments)
{
return v8::Undefined();
}
}
v8::Handle<v8::ObjectTemplate> AdblockPlus::ConsoleJsObject::Create(
- AdblockPlus::ErrorCallback& errorCallback)
+ AdblockPlus::JsEngine& jsEngine)
{
v8::HandleScope handleScope;
const v8::Handle<v8::ObjectTemplate> console = v8::ObjectTemplate::New();
const v8::Handle<v8::FunctionTemplate> errorFunction =
v8::FunctionTemplate::New(::ErrorCallback,
- v8::External::New(&errorCallback));
+ v8::External::New(&jsEngine));
console->Set(v8::String::New("error"), errorFunction);
const v8::Handle<v8::FunctionTemplate> traceFunction =
v8::FunctionTemplate::New(TraceCallback);
console->Set(v8::String::New("trace"), traceFunction);
return handleScope.Close(console);
}
« no previous file with comments | « src/ConsoleJsObject.h ('k') | src/FileSystemJsObject.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld