aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental
diff options
context:
space:
mode:
authorGravatar jcgregorio <jcgregorio@google.com>2014-10-24 12:49:17 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-10-24 12:49:17 -0700
commite22f45fd89ef70b2ba645c354e951365ab8540c7 (patch)
tree316036d376d9644622272c43915ef0380cc59ea5 /experimental
parenta0036c6e337f02b6553fca0e2f2c73e9b47fc23b (diff)
Doing the "using namespace" penance by adding in v8:: everywhere, like I should have to begin with.
Also: - SkWindow now has createSurface, not createCanvas. - Add the platform init code v8 now seems to require. - Fix library linkage. - Call isolate->Enter(); because it doesn't look like v8 starts with a default isolate to begin with. BUG=skia: Review URL: https://codereview.chromium.org/673223002
Diffstat (limited to 'experimental')
-rw-r--r--experimental/SkV8Example/BaseContext.cpp92
-rw-r--r--experimental/SkV8Example/BaseContext.h54
-rw-r--r--experimental/SkV8Example/Global.cpp60
-rw-r--r--experimental/SkV8Example/Global.h25
-rw-r--r--experimental/SkV8Example/JsContext.cpp50
-rw-r--r--experimental/SkV8Example/JsContext.h8
-rw-r--r--experimental/SkV8Example/Path2D.cpp44
-rw-r--r--experimental/SkV8Example/SkV8Example.cpp30
-rw-r--r--experimental/SkV8Example/SkV8Example.h2
9 files changed, 181 insertions, 184 deletions
diff --git a/experimental/SkV8Example/BaseContext.cpp b/experimental/SkV8Example/BaseContext.cpp
index 486474e397..d617d78c18 100644
--- a/experimental/SkV8Example/BaseContext.cpp
+++ b/experimental/SkV8Example/BaseContext.cpp
@@ -8,21 +8,19 @@
*/
#include <v8.h>
-using namespace v8;
-
#include "Global.h"
#include "BaseContext.h"
#include "Path2D.h"
#include "SkCanvas.h"
-BaseContext* BaseContext::Unwrap(Handle<Object> obj) {
- Handle<External> field = Handle<External>::Cast(obj->GetInternalField(0));
+BaseContext* BaseContext::Unwrap(v8::Handle<v8::Object> obj) {
+ v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(obj->GetInternalField(0));
void* ptr = field->Value();
return static_cast<BaseContext*>(ptr);
}
-void BaseContext::FillRect(const v8::FunctionCallbackInfo<Value>& args) {
+void BaseContext::FillRect(const v8::FunctionCallbackInfo<v8::Value>& args) {
BaseContext* BaseContext = Unwrap(args.This());
SkCanvas* canvas = BaseContext->getCanvas();
if (NULL == canvas) {
@@ -49,7 +47,7 @@ void BaseContext::FillRect(const v8::FunctionCallbackInfo<Value>& args) {
canvas->drawRect(rect, BaseContext->fFillStyle);
}
-void BaseContext::Save(const v8::FunctionCallbackInfo<Value>& args) {
+void BaseContext::Save(const v8::FunctionCallbackInfo<v8::Value>& args) {
BaseContext* BaseContext = Unwrap(args.This());
SkCanvas* canvas = BaseContext->getCanvas();
if (NULL == canvas) {
@@ -59,7 +57,7 @@ void BaseContext::Save(const v8::FunctionCallbackInfo<Value>& args) {
canvas->save();
}
-void BaseContext::Restore(const v8::FunctionCallbackInfo<Value>& args) {
+void BaseContext::Restore(const v8::FunctionCallbackInfo<v8::Value>& args) {
BaseContext* BaseContext = Unwrap(args.This());
SkCanvas* canvas = BaseContext->getCanvas();
if (NULL == canvas) {
@@ -69,7 +67,7 @@ void BaseContext::Restore(const v8::FunctionCallbackInfo<Value>& args) {
canvas->restore();
}
-void BaseContext::Rotate(const v8::FunctionCallbackInfo<Value>& args) {
+void BaseContext::Rotate(const v8::FunctionCallbackInfo<v8::Value>& args) {
BaseContext* BaseContext = Unwrap(args.This());
SkCanvas* canvas = BaseContext->getCanvas();
if (NULL == canvas) {
@@ -86,7 +84,7 @@ void BaseContext::Rotate(const v8::FunctionCallbackInfo<Value>& args) {
canvas->rotate(SkRadiansToDegrees(angle));
}
-void BaseContext::Translate(const v8::FunctionCallbackInfo<Value>& args) {
+void BaseContext::Translate(const v8::FunctionCallbackInfo<v8::Value>& args) {
BaseContext* BaseContext = Unwrap(args.This());
SkCanvas* canvas = BaseContext->getCanvas();
if (NULL == canvas) {
@@ -104,7 +102,7 @@ void BaseContext::Translate(const v8::FunctionCallbackInfo<Value>& args) {
canvas->translate(SkDoubleToScalar(dx), SkDoubleToScalar(dy));
}
-void BaseContext::ResetTransform(const v8::FunctionCallbackInfo<Value>& args) {
+void BaseContext::ResetTransform(const v8::FunctionCallbackInfo<v8::Value>& args) {
BaseContext* BaseContext = Unwrap(args.This());
SkCanvas* canvas = BaseContext->getCanvas();
if (NULL == canvas) {
@@ -114,7 +112,7 @@ void BaseContext::ResetTransform(const v8::FunctionCallbackInfo<Value>& args) {
canvas->resetMatrix();
}
-void BaseContext::Stroke(const v8::FunctionCallbackInfo<Value>& args) {
+void BaseContext::Stroke(const v8::FunctionCallbackInfo<v8::Value>& args) {
BaseContext* BaseContext = Unwrap(args.This());
SkCanvas* canvas = BaseContext->getCanvas();
if (NULL == canvas) {
@@ -128,7 +126,7 @@ void BaseContext::Stroke(const v8::FunctionCallbackInfo<Value>& args) {
return;
}
- Handle<External> field = Handle<External>::Cast(
+ v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(
args[0]->ToObject()->GetInternalField(0));
void* ptr = field->Value();
Path2D* path = static_cast<Path2D*>(ptr);
@@ -136,7 +134,7 @@ void BaseContext::Stroke(const v8::FunctionCallbackInfo<Value>& args) {
canvas->drawPath(path->getSkPath(), BaseContext->fStrokeStyle);
}
-void BaseContext::Fill(const v8::FunctionCallbackInfo<Value>& args) {
+void BaseContext::Fill(const v8::FunctionCallbackInfo<v8::Value>& args) {
BaseContext* BaseContext = Unwrap(args.This());
SkCanvas* canvas = BaseContext->getCanvas();
if (NULL == canvas) {
@@ -150,7 +148,7 @@ void BaseContext::Fill(const v8::FunctionCallbackInfo<Value>& args) {
return;
}
- Handle<External> field = Handle<External>::Cast(
+ v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(
args[0]->ToObject()->GetInternalField(0));
void* ptr = field->Value();
Path2D* path = static_cast<Path2D*>(ptr);
@@ -158,21 +156,21 @@ void BaseContext::Fill(const v8::FunctionCallbackInfo<Value>& args) {
canvas->drawPath(path->getSkPath(), BaseContext->fFillStyle);
}
-void BaseContext::GetStyle(Local<String> name,
- const PropertyCallbackInfo<Value>& info,
+void BaseContext::GetStyle(v8::Local<v8::String> name,
+ const v8::PropertyCallbackInfo<v8::Value>& info,
const SkPaint& style) {
char buf[8];
SkColor color = style.getColor();
sprintf(buf, "#%02X%02X%02X", SkColorGetR(color), SkColorGetG(color),
SkColorGetB(color));
- info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), buf));
+ info.GetReturnValue().Set(v8::String::NewFromUtf8(info.GetIsolate(), buf));
}
-void BaseContext::SetStyle(Local<String> name, Local<Value> value,
- const PropertyCallbackInfo<void>& info,
+void BaseContext::SetStyle(v8::Local<v8::String> name, v8::Local<v8::Value> value,
+ const v8::PropertyCallbackInfo<void>& info,
SkPaint& style) {
- Local<String> s = value->ToString();
+ v8::Local<v8::String> s = value->ToString();
if (s->Length() != 7 && s->Length() != 9) {
info.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(
@@ -200,33 +198,33 @@ void BaseContext::SetStyle(Local<String> name, Local<Value> value,
style.setColor(SkColorSetA(SkColor(color), alpha));
}
-void BaseContext::GetFillStyle(Local<String> name,
- const PropertyCallbackInfo<Value>& info) {
+void BaseContext::GetFillStyle(v8::Local<v8::String> name,
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
BaseContext* baseContext = Unwrap(info.This());
GetStyle(name, info, baseContext->fFillStyle);
}
-void BaseContext::GetStrokeStyle(Local<String> name,
- const PropertyCallbackInfo<Value>& info) {
+void BaseContext::GetStrokeStyle(v8::Local<v8::String> name,
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
BaseContext* baseContext = Unwrap(info.This());
GetStyle(name, info, baseContext->fStrokeStyle);
}
-void BaseContext::SetFillStyle(Local<String> name, Local<Value> value,
- const PropertyCallbackInfo<void>& info) {
+void BaseContext::SetFillStyle(v8::Local<v8::String> name, v8::Local<v8::Value> value,
+ const v8::PropertyCallbackInfo<void>& info) {
BaseContext* baseContext = Unwrap(info.This());
SetStyle(name, value, info, baseContext->fFillStyle);
}
-void BaseContext::SetStrokeStyle(Local<String> name, Local<Value> value,
- const PropertyCallbackInfo<void>& info) {
+void BaseContext::SetStrokeStyle(v8::Local<v8::String> name, v8::Local<v8::Value> value,
+ const v8::PropertyCallbackInfo<void>& info) {
BaseContext* baseContext = Unwrap(info.This());
SetStyle(name, value, info, baseContext->fStrokeStyle);
}
-void BaseContext::GetWidth(Local<String> name,
- const PropertyCallbackInfo<Value>& info) {
+void BaseContext::GetWidth(v8::Local<v8::String> name,
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
BaseContext* baseContext = Unwrap(info.This());
SkCanvas* canvas = baseContext->getCanvas();
if (NULL == canvas) {
@@ -235,11 +233,11 @@ void BaseContext::GetWidth(Local<String> name,
SkISize size = canvas->getDeviceSize();
info.GetReturnValue().Set(
- Int32::New(baseContext->fGlobal->getIsolate(), size.fWidth));
+ v8::Int32::New(baseContext->fGlobal->getIsolate(), size.fWidth));
}
-void BaseContext::GetHeight(Local<String> name,
- const PropertyCallbackInfo<Value>& info) {
+void BaseContext::GetHeight(v8::Local<v8::String> name,
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
BaseContext* baseContext = Unwrap(info.This());
SkCanvas* canvas = baseContext->getCanvas();
if (NULL == canvas) {
@@ -248,30 +246,30 @@ void BaseContext::GetHeight(Local<String> name,
SkISize size = canvas->getDeviceSize();
info.GetReturnValue().Set(
- Int32::New(baseContext->fGlobal->getIsolate(), size.fHeight));
+ v8::Int32::New(baseContext->fGlobal->getIsolate(), size.fHeight));
}
#define ADD_METHOD(name, fn) \
- tmpl->Set(String::NewFromUtf8( \
+ tmpl->Set(v8::String::NewFromUtf8( \
fGlobal->getIsolate(), name, \
- String::kInternalizedString), \
- FunctionTemplate::New(fGlobal->getIsolate(), fn))
+ v8::String::kInternalizedString), \
+ v8::FunctionTemplate::New(fGlobal->getIsolate(), fn))
-void BaseContext::addAttributesAndMethods(Handle<ObjectTemplate> tmpl) {
- HandleScope scope(fGlobal->getIsolate());
+void BaseContext::addAttributesAndMethods(v8::Handle<v8::ObjectTemplate> tmpl) {
+ v8::HandleScope scope(fGlobal->getIsolate());
// Add accessors for each of the fields of the context object.
- tmpl->SetAccessor(String::NewFromUtf8(
- fGlobal->getIsolate(), "fillStyle", String::kInternalizedString),
+ tmpl->SetAccessor(v8::String::NewFromUtf8(
+ fGlobal->getIsolate(), "fillStyle", v8::String::kInternalizedString),
GetFillStyle, SetFillStyle);
- tmpl->SetAccessor(String::NewFromUtf8(
- fGlobal->getIsolate(), "strokeStyle", String::kInternalizedString),
+ tmpl->SetAccessor(v8::String::NewFromUtf8(
+ fGlobal->getIsolate(), "strokeStyle", v8::String::kInternalizedString),
GetStrokeStyle, SetStrokeStyle);
- tmpl->SetAccessor(String::NewFromUtf8(
- fGlobal->getIsolate(), "width", String::kInternalizedString),
+ tmpl->SetAccessor(v8::String::NewFromUtf8(
+ fGlobal->getIsolate(), "width", v8::String::kInternalizedString),
GetWidth);
- tmpl->SetAccessor(String::NewFromUtf8(
- fGlobal->getIsolate(), "height", String::kInternalizedString),
+ tmpl->SetAccessor(v8::String::NewFromUtf8(
+ fGlobal->getIsolate(), "height", v8::String::kInternalizedString),
GetHeight);
// Add methods.
diff --git a/experimental/SkV8Example/BaseContext.h b/experimental/SkV8Example/BaseContext.h
index b7fe3815a6..5462c85751 100644
--- a/experimental/SkV8Example/BaseContext.h
+++ b/experimental/SkV8Example/BaseContext.h
@@ -14,8 +14,6 @@
#include "SkPaint.h"
-using namespace v8;
-
class SkCanvas;
class Global;
@@ -39,46 +37,46 @@ public:
virtual SkCanvas* getCanvas() = 0;
// Add the Javascript attributes and methods that BaseContext implements to the ObjectTemplate.
- void addAttributesAndMethods(Handle<ObjectTemplate> tmpl);
+ void addAttributesAndMethods(v8::Handle<v8::ObjectTemplate> tmpl);
protected:
// Get the pointer out of obj.
- static BaseContext* Unwrap(Handle<Object> obj);
+ static BaseContext* Unwrap(v8::Handle<v8::Object> obj);
Global* fGlobal;
SkPaint fFillStyle;
SkPaint fStrokeStyle;
private:
- static void GetStyle(Local<String> name,
- const PropertyCallbackInfo<Value>& info,
+ static void GetStyle(v8::Local<v8::String> name,
+ const v8::PropertyCallbackInfo<v8::Value>& info,
const SkPaint& style);
- static void SetStyle(Local<String> name, Local<Value> value,
- const PropertyCallbackInfo<void>& info,
+ static void SetStyle(v8::Local<v8::String> name, v8::Local<v8::Value> value,
+ const v8::PropertyCallbackInfo<void>& info,
SkPaint& style);
// JS Attributes
- static void GetFillStyle(Local<String> name,
- const PropertyCallbackInfo<Value>& info);
- static void SetFillStyle(Local<String> name, Local<Value> value,
- const PropertyCallbackInfo<void>& info);
- static void GetStrokeStyle(Local<String> name,
- const PropertyCallbackInfo<Value>& info);
- static void SetStrokeStyle(Local<String> name, Local<Value> value,
- const PropertyCallbackInfo<void>& info);
- static void GetWidth(Local<String> name,
- const PropertyCallbackInfo<Value>& info);
- static void GetHeight(Local<String> name,
- const PropertyCallbackInfo<Value>& info);
+ static void GetFillStyle(v8::Local<v8::String> name,
+ const v8::PropertyCallbackInfo<v8::Value>& info);
+ static void SetFillStyle(v8::Local<v8::String> name, v8::Local<v8::Value> value,
+ const v8::PropertyCallbackInfo<void>& info);
+ static void GetStrokeStyle(v8::Local<v8::String> name,
+ const v8::PropertyCallbackInfo<v8::Value>& info);
+ static void SetStrokeStyle(v8::Local<v8::String> name, v8::Local<v8::Value> value,
+ const v8::PropertyCallbackInfo<void>& info);
+ static void GetWidth(v8::Local<v8::String> name,
+ const v8::PropertyCallbackInfo<v8::Value>& info);
+ static void GetHeight(v8::Local<v8::String> name,
+ const v8::PropertyCallbackInfo<v8::Value>& info);
// JS Methods
- static void FillRect(const v8::FunctionCallbackInfo<Value>& args);
- static void Stroke(const v8::FunctionCallbackInfo<Value>& args);
- static void Fill(const v8::FunctionCallbackInfo<Value>& args);
- static void Rotate(const v8::FunctionCallbackInfo<Value>& args);
- static void Save(const v8::FunctionCallbackInfo<Value>& args);
- static void Restore(const v8::FunctionCallbackInfo<Value>& args);
- static void Translate(const v8::FunctionCallbackInfo<Value>& args);
- static void ResetTransform(const v8::FunctionCallbackInfo<Value>& args);
+ static void FillRect(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void Stroke(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void Fill(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void Rotate(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void Save(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void Restore(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void Translate(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void ResetTransform(const v8::FunctionCallbackInfo<v8::Value>& args);
};
#endif
diff --git a/experimental/SkV8Example/Global.cpp b/experimental/SkV8Example/Global.cpp
index 4bbdb7bf45..919f247869 100644
--- a/experimental/SkV8Example/Global.cpp
+++ b/experimental/SkV8Example/Global.cpp
@@ -30,24 +30,24 @@ int32_t Global::getNextTimerID() {
}
// Slight modification to an original function found in the V8 sample shell.cc.
-void Global::reportException(TryCatch* tryCatch) {
- HandleScope handleScope(fIsolate);
- String::Utf8Value exception(tryCatch->Exception());
+void Global::reportException(v8::TryCatch* tryCatch) {
+ v8::HandleScope handleScope(fIsolate);
+ v8::String::Utf8Value exception(tryCatch->Exception());
const char* exceptionString = to_cstring(exception);
- Handle<Message> message = tryCatch->Message();
+ v8::Handle<v8::Message> message = tryCatch->Message();
if (message.IsEmpty()) {
// V8 didn't provide any extra information about this error; just
// print the exception.
fprintf(stderr, "%s\n", exceptionString);
} else {
// Print (filename):(line number): (message).
- String::Utf8Value filename(message->GetScriptOrigin().ResourceName());
+ v8::String::Utf8Value filename(message->GetScriptOrigin().ResourceName());
const char* filenameString = to_cstring(filename);
int linenum = message->GetLineNumber();
fprintf(stderr,
"%s:%i: %s\n", filenameString, linenum, exceptionString);
// Print line of source code.
- String::Utf8Value sourceline(message->GetSourceLine());
+ v8::String::Utf8Value sourceline(message->GetSourceLine());
const char* sourceLineString = to_cstring(sourceline);
fprintf(stderr, "%s\n", sourceLineString);
// Print wavy underline.
@@ -60,7 +60,7 @@ void Global::reportException(TryCatch* tryCatch) {
fprintf(stderr, "^");
}
fprintf(stderr, "\n");
- String::Utf8Value stackTrace(tryCatch->StackTrace());
+ v8::String::Utf8Value stackTrace(tryCatch->StackTrace());
if (stackTrace.length() > 0) {
const char* stackTraceString = to_cstring(stackTrace);
fprintf(stderr, "%s\n", stackTraceString);
@@ -72,7 +72,7 @@ void Global::reportException(TryCatch* tryCatch) {
// Invalidates the current window, forcing a redraw.
//
// JS: inval();
-void Global::Inval(const v8::FunctionCallbackInfo<Value>& args) {
+void Global::Inval(const v8::FunctionCallbackInfo<v8::Value>& args) {
gGlobal->getWindow()->inval(NULL);
}
@@ -83,7 +83,7 @@ void Global::Inval(const v8::FunctionCallbackInfo<Value>& args) {
// JS: print("foo", "bar");
void Global::Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
bool first = true;
- HandleScope handleScope(args.GetIsolate());
+ v8::HandleScope handleScope(args.GetIsolate());
for (int i = 0; i < args.Length(); i++) {
if (first) {
first = false;
@@ -114,7 +114,7 @@ void Global::SetTimeout(const v8::FunctionCallbackInfo<v8::Value>& args) {
printf("Not a function passed to setTimeout.\n");
return;
}
- Handle<Function> timeoutFn = Handle<Function>::Cast(args[0]);
+ v8::Handle<v8::Function> timeoutFn = v8::Handle<v8::Function>::Cast(args[0]);
double delay = args[1]->NumberValue();
int32_t id = gGlobal->getNextTimerID();
@@ -127,22 +127,22 @@ void Global::SetTimeout(const v8::FunctionCallbackInfo<v8::Value>& args) {
evt->setFast32(id);
evt->postDelay(delay);
- args.GetReturnValue().Set(Integer::New(gGlobal->fIsolate, id));
+ args.GetReturnValue().Set(v8::Integer::New(gGlobal->fIsolate, id));
}
// Callback function for SkEvents used to implement timeouts.
bool Global::TimeOutProc(const SkEvent& evt) {
// Create a handle scope to keep the temporary object references.
- HandleScope handleScope(gGlobal->getIsolate());
+ v8::HandleScope handleScope(gGlobal->getIsolate());
// Create a local context from our global context.
- Local<Context> context = gGlobal->getContext();
+ v8::Local<v8::Context> context = gGlobal->getContext();
// Enter the context so all the remaining operations take place there.
- Context::Scope contextScope(context);
+ v8::Context::Scope contextScope(context);
// Set up an exception handler before calling the Process function.
- TryCatch tryCatch;
+ v8::TryCatch tryCatch;
int32_t id = evt.getFast32();
if (gGlobal->fTimeouts.find(gGlobal->fLastTimerID) == gGlobal->fTimeouts.end()) {
@@ -151,9 +151,9 @@ bool Global::TimeOutProc(const SkEvent& evt) {
}
const int argc = 0;
- Local<Function> onTimeout =
- Local<Function>::New(gGlobal->getIsolate(), gGlobal->fTimeouts[id]);
- Handle<Value> result = onTimeout->Call(context->Global(), argc, NULL);
+ v8::Local<v8::Function> onTimeout =
+ v8::Local<v8::Function>::New(gGlobal->getIsolate(), gGlobal->fTimeouts[id]);
+ v8::Handle<v8::Value> result = onTimeout->Call(context->Global(), argc, NULL);
gGlobal->fTimeouts.erase(id);
// Handle any exceptions or output.
@@ -166,7 +166,7 @@ bool Global::TimeOutProc(const SkEvent& evt) {
if (!result->IsUndefined()) {
// If all went well and the result wasn't undefined then print the
// returned value.
- String::Utf8Value str(result);
+ v8::String::Utf8Value str(result);
const char* cstr = to_cstring(str);
printf("%s\n", cstr);
}
@@ -175,9 +175,9 @@ bool Global::TimeOutProc(const SkEvent& evt) {
}
// Creates a new execution environment containing the built-in functions.
-Handle<Context> Global::createRootContext() {
+v8::Handle<v8::Context> Global::createRootContext() {
// Create a template for the global object.
- Handle<ObjectTemplate> global = ObjectTemplate::New();
+ v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
global->Set(v8::String::NewFromUtf8(fIsolate, "print"),
v8::FunctionTemplate::New(fIsolate, Global::Print));
@@ -187,15 +187,15 @@ Handle<Context> Global::createRootContext() {
v8::FunctionTemplate::New(fIsolate, Global::Inval));
- return Context::New(fIsolate, NULL, global);
+ return v8::Context::New(fIsolate, NULL, global);
}
void Global::initialize() {
// Create a stack-allocated handle scope.
- HandleScope handleScope(fIsolate);
+ v8::HandleScope handleScope(fIsolate);
// Create a new context.
- Handle<Context> context = this->createRootContext();
+ v8::Handle<v8::Context> context = this->createRootContext();
// Make the context persistent.
fContext.Reset(fIsolate, context);
@@ -210,19 +210,19 @@ void Global::initialize() {
bool Global::parseScript(const char script[]) {
// Create a stack-allocated handle scope.
- HandleScope handleScope(fIsolate);
+ v8::HandleScope handleScope(fIsolate);
// Get the global context.
- Handle<Context> context = this->getContext();
+ v8::Handle<v8::Context> context = this->getContext();
// Enter the scope so all operations take place in the scope.
- Context::Scope contextScope(context);
+ v8::Context::Scope contextScope(context);
v8::TryCatch tryCatch;
// Compile the source code.
- Handle<String> source = String::NewFromUtf8(fIsolate, script);
- Handle<Script> compiledScript = Script::Compile(source);
+ v8::Handle<v8::String> source = v8::String::NewFromUtf8(fIsolate, script);
+ v8::Handle<v8::Script> compiledScript = v8::Script::Compile(source);
if (compiledScript.IsEmpty()) {
// Print errors that happened during compilation.
@@ -231,7 +231,7 @@ bool Global::parseScript(const char script[]) {
}
// Try running it now to create the onDraw function.
- Handle<Value> result = compiledScript->Run();
+ v8::Handle<v8::Value> result = compiledScript->Run();
// Handle any exceptions or output.
if (result.IsEmpty()) {
diff --git a/experimental/SkV8Example/Global.h b/experimental/SkV8Example/Global.h
index 6bd3c70962..a50f24442a 100644
--- a/experimental/SkV8Example/Global.h
+++ b/experimental/SkV8Example/Global.h
@@ -14,20 +14,19 @@
#include <v8.h>
-using namespace v8;
#include "SkTypes.h"
#include "SkEvent.h"
class SkOSWindow;
-typedef Persistent<Function, CopyablePersistentTraits<Function> > CopyablePersistentFn;
+typedef v8::Persistent<v8::Function, v8::CopyablePersistentTraits<v8::Function> > CopyablePersistentFn;
// Provides the global isolate and context for our V8 instance.
// Also implements all the global level functions.
class Global : SkNoncopyable {
public:
- Global(Isolate* isolate)
+ Global(v8::Isolate* isolate)
: fIsolate(isolate)
, fWindow(NULL)
, fLastTimerID(0)
@@ -40,11 +39,11 @@ public:
// The script will be parsed into the context this Global contains.
bool parseScript(const char script[]);
- Local<Context> getContext() {
- return Local<Context>::New(fIsolate, fContext);
+ v8::Local<v8::Context> getContext() {
+ return v8::Local<v8::Context>::New(fIsolate, fContext);
}
- Isolate* getIsolate() {
+ v8::Isolate* getIsolate() {
return fIsolate;
}
@@ -55,11 +54,11 @@ public:
return fWindow;
}
- void reportException(TryCatch* tryCatch);
+ void reportException(v8::TryCatch* tryCatch);
private:
void initialize();
- Handle<Context> createRootContext();
+ v8::Handle<v8::Context> createRootContext();
int32_t getNextTimerID();
static bool TimeOutProc(const SkEvent& evt);
@@ -68,12 +67,12 @@ private:
// the context.
static void SetTimeout(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Print(const v8::FunctionCallbackInfo<v8::Value>& args);
- static void Inval(const v8::FunctionCallbackInfo<Value>& args);
+ static void Inval(const v8::FunctionCallbackInfo<v8::Value>& args);
- Persistent<Context> fContext;
- Isolate* fIsolate;
- SkOSWindow* fWindow;
- static Global* gGlobal;
+ v8::Persistent<v8::Context> fContext;
+ v8::Isolate* fIsolate;
+ SkOSWindow* fWindow;
+ static Global* gGlobal;
// Handle to the functions to call when a timeout triggers as indexed by id.
std::map<int32_t, CopyablePersistentFn > fTimeouts;
diff --git a/experimental/SkV8Example/JsContext.cpp b/experimental/SkV8Example/JsContext.cpp
index 8b0b072979..959068dc7d 100644
--- a/experimental/SkV8Example/JsContext.cpp
+++ b/experimental/SkV8Example/JsContext.cpp
@@ -9,8 +9,6 @@
*/
#include <v8.h>
-using namespace v8;
-
#include "Global.h"
#include "JsContext.h"
#include "Path2D.h"
@@ -23,17 +21,17 @@ static const char* to_cstring(const v8::String::Utf8Value& value) {
return *value ? *value : "<string conversion failed>";
}
-Persistent<ObjectTemplate> JsContext::gContextTemplate;
+v8::Persistent<v8::ObjectTemplate> JsContext::gContextTemplate;
// Wraps 'this' in a Javascript object.
-Handle<Object> JsContext::wrap() {
+v8::Handle<v8::Object> JsContext::wrap() {
// Handle scope for temporary handles.
- EscapableHandleScope handleScope(fGlobal->getIsolate());
+ v8::EscapableHandleScope handleScope(fGlobal->getIsolate());
// Fetch the template for creating JavaScript JsContext wrappers.
// It only has to be created once, which we do on demand.
if (gContextTemplate.IsEmpty()) {
- Local<ObjectTemplate> localTemplate = ObjectTemplate::New();
+ v8::Local<v8::ObjectTemplate> localTemplate = v8::ObjectTemplate::New();
// Add a field to store the pointer to a JsContext instance.
localTemplate->SetInternalFieldCount(1);
@@ -42,15 +40,15 @@ Handle<Object> JsContext::wrap() {
gContextTemplate.Reset(fGlobal->getIsolate(), localTemplate);
}
- Handle<ObjectTemplate> templ =
- Local<ObjectTemplate>::New(fGlobal->getIsolate(), gContextTemplate);
+ v8::Handle<v8::ObjectTemplate> templ =
+ v8::Local<v8::ObjectTemplate>::New(fGlobal->getIsolate(), gContextTemplate);
// Create an empty JsContext wrapper.
- Local<Object> result = templ->NewInstance();
+ v8::Local<v8::Object> result = templ->NewInstance();
// Wrap the raw C++ pointer in an External so it can be referenced
// from within JavaScript.
- Handle<External> contextPtr = External::New(fGlobal->getIsolate(), this);
+ v8::Handle<v8::External> contextPtr = v8::External::New(fGlobal->getIsolate(), this);
// Store the context pointer in the JavaScript wrapper.
result->SetInternalField(0, contextPtr);
@@ -67,27 +65,27 @@ void JsContext::onDraw(SkCanvas* canvas) {
fCanvas = canvas;
// Create a handle scope to keep the temporary object references.
- HandleScope handleScope(fGlobal->getIsolate());
+ v8::HandleScope handleScope(fGlobal->getIsolate());
// Create a local context from our global context.
- Local<Context> context = fGlobal->getContext();
+ v8::Local<v8::Context> context = fGlobal->getContext();
// Enter the context so all the remaining operations take place there.
- Context::Scope contextScope(context);
+ v8::Context::Scope contextScope(context);
// Wrap the C++ this pointer in a JavaScript wrapper.
- Handle<Object> contextObj = this->wrap();
+ v8::Handle<v8::Object> contextObj = this->wrap();
// Set up an exception handler before calling the Process function.
- TryCatch tryCatch;
+ v8::TryCatch tryCatch;
// Invoke the process function, giving the global object as 'this'
// and one argument, this JsContext.
const int argc = 1;
- Handle<Value> argv[argc] = { contextObj };
- Local<Function> onDraw =
- Local<Function>::New(fGlobal->getIsolate(), fOnDraw);
- Handle<Value> result = onDraw->Call(context->Global(), argc, argv);
+ v8::Handle<v8::Value> argv[argc] = { contextObj };
+ v8::Local<v8::Function> onDraw =
+ v8::Local<v8::Function>::New(fGlobal->getIsolate(), fOnDraw);
+ v8::Handle<v8::Value> result = onDraw->Call(context->Global(), argc, argv);
// Handle any exceptions or output.
if (result.IsEmpty()) {
@@ -99,7 +97,7 @@ void JsContext::onDraw(SkCanvas* canvas) {
if (!result->IsUndefined()) {
// If all went well and the result wasn't undefined then print
// the returned value.
- String::Utf8Value str(result);
+ v8::String::Utf8Value str(result);
const char* cstr = to_cstring(str);
printf("%s\n", cstr);
}
@@ -110,19 +108,19 @@ void JsContext::onDraw(SkCanvas* canvas) {
bool JsContext::initialize() {
// Create a stack-allocated handle scope.
- HandleScope handleScope(fGlobal->getIsolate());
+ v8::HandleScope handleScope(fGlobal->getIsolate());
// Create a local context from our global context.
- Local<Context> context = fGlobal->getContext();
+ v8::Local<v8::Context> context = fGlobal->getContext();
// Enter the scope so all operations take place in the scope.
- Context::Scope contextScope(context);
+ v8::Context::Scope contextScope(context);
v8::TryCatch try_catch;
- Handle<String> fn_name = String::NewFromUtf8(
+ v8::Handle<v8::String> fn_name = v8::String::NewFromUtf8(
fGlobal->getIsolate(), "onDraw");
- Handle<Value> fn_val = context->Global()->Get(fn_name);
+ v8::Handle<v8::Value> fn_val = context->Global()->Get(fn_name);
if (!fn_val->IsFunction()) {
printf("Not a function.\n");
@@ -130,7 +128,7 @@ bool JsContext::initialize() {
}
// It is a function; cast it to a Function.
- Handle<Function> fn_fun = Handle<Function>::Cast(fn_val);
+ v8::Handle<v8::Function> fn_fun = v8::Handle<v8::Function>::Cast(fn_val);
// Store the function in a Persistent handle, since we also want that to
// remain after this call returns.
diff --git a/experimental/SkV8Example/JsContext.h b/experimental/SkV8Example/JsContext.h
index d3993ee6c7..60446f887f 100644
--- a/experimental/SkV8Example/JsContext.h
+++ b/experimental/SkV8Example/JsContext.h
@@ -15,8 +15,6 @@
#include "SkPaint.h"
#include "BaseContext.h"
-using namespace v8;
-
class SkCanvas;
class Global;
@@ -47,14 +45,14 @@ public:
private:
// Wrap the 'this' pointer into an Object. Can be retrieved via Unwrap.
- Handle<Object> wrap();
+ v8::Handle<v8::Object> wrap();
// A handle to the onDraw function defined in the script.
- Persistent<Function> fOnDraw;
+ v8::Persistent<v8::Function> fOnDraw;
// The template for what a canvas context object looks like. The canvas
// context object is what's passed into the JS onDraw() function.
- static Persistent<ObjectTemplate> gContextTemplate;
+ static v8::Persistent<v8::ObjectTemplate> gContextTemplate;
// Only valid when inside OnDraw().
SkCanvas* fCanvas;
diff --git a/experimental/SkV8Example/Path2D.cpp b/experimental/SkV8Example/Path2D.cpp
index 4118a22b80..5956f69de3 100644
--- a/experimental/SkV8Example/Path2D.cpp
+++ b/experimental/SkV8Example/Path2D.cpp
@@ -12,19 +12,19 @@
Global* Path2D::gGlobal = NULL;
-void Path2D::ConstructPath(const v8::FunctionCallbackInfo<Value>& args) {
- HandleScope handleScope(gGlobal->getIsolate());
+void Path2D::ConstructPath(const v8::FunctionCallbackInfo<v8::Value>& args) {
+ v8::HandleScope handleScope(gGlobal->getIsolate());
Path2D* path = new Path2D();
args.This()->SetInternalField(
- 0, External::New(gGlobal->getIsolate(), path));
+ 0, v8::External::New(gGlobal->getIsolate(), path));
}
#define ADD_METHOD(name, fn) \
constructor->InstanceTemplate()->Set( \
- String::NewFromUtf8( \
+ v8::String::NewFromUtf8( \
global->getIsolate(), name, \
- String::kInternalizedString), \
- FunctionTemplate::New(global->getIsolate(), fn))
+ v8::String::kInternalizedString), \
+ v8::FunctionTemplate::New(global->getIsolate(), fn))
// Install the constructor in the global scope so Path2Ds can be constructed
// in JS.
@@ -32,14 +32,14 @@ void Path2D::AddToGlobal(Global* global) {
gGlobal = global;
// Create a stack-allocated handle scope.
- HandleScope handleScope(gGlobal->getIsolate());
+ v8::HandleScope handleScope(gGlobal->getIsolate());
- Handle<Context> context = gGlobal->getContext();
+ v8::Handle<v8::Context> context = gGlobal->getContext();
// Enter the scope so all operations take place in the scope.
- Context::Scope contextScope(context);
+ v8::Context::Scope contextScope(context);
- Local<FunctionTemplate> constructor = FunctionTemplate::New(
+ v8::Local<v8::FunctionTemplate> constructor = v8::FunctionTemplate::New(
gGlobal->getIsolate(), Path2D::ConstructPath);
constructor->InstanceTemplate()->SetInternalFieldCount(1);
@@ -53,23 +53,23 @@ void Path2D::AddToGlobal(Global* global) {
ADD_METHOD("oval", Oval);
ADD_METHOD("conicTo", ConicTo);
- context->Global()->Set(String::NewFromUtf8(
+ context->Global()->Set(v8::String::NewFromUtf8(
gGlobal->getIsolate(), "Path2D"), constructor->GetFunction());
}
-Path2D* Path2D::Unwrap(const v8::FunctionCallbackInfo<Value>& args) {
- Handle<External> field = Handle<External>::Cast(
+Path2D* Path2D::Unwrap(const v8::FunctionCallbackInfo<v8::Value>& args) {
+ v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(
args.This()->GetInternalField(0));
void* ptr = field->Value();
return static_cast<Path2D*>(ptr);
}
-void Path2D::ClosePath(const v8::FunctionCallbackInfo<Value>& args) {
+void Path2D::ClosePath(const v8::FunctionCallbackInfo<v8::Value>& args) {
Path2D* path = Unwrap(args);
path->fSkPath.close();
}
-void Path2D::MoveTo(const v8::FunctionCallbackInfo<Value>& args) {
+void Path2D::MoveTo(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 2) {
args.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(
@@ -82,7 +82,7 @@ void Path2D::MoveTo(const v8::FunctionCallbackInfo<Value>& args) {
path->fSkPath.moveTo(SkDoubleToScalar(x), SkDoubleToScalar(y));
}
-void Path2D::LineTo(const v8::FunctionCallbackInfo<Value>& args) {
+void Path2D::LineTo(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 2) {
args.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(
@@ -95,7 +95,7 @@ void Path2D::LineTo(const v8::FunctionCallbackInfo<Value>& args) {
path->fSkPath.lineTo(SkDoubleToScalar(x), SkDoubleToScalar(y));
}
-void Path2D::QuadraticCurveTo(const v8::FunctionCallbackInfo<Value>& args) {
+void Path2D::QuadraticCurveTo(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 4) {
args.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(
@@ -114,7 +114,7 @@ void Path2D::QuadraticCurveTo(const v8::FunctionCallbackInfo<Value>& args) {
SkDoubleToScalar(x), SkDoubleToScalar(y));
}
-void Path2D::BezierCurveTo(const v8::FunctionCallbackInfo<Value>& args) {
+void Path2D::BezierCurveTo(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 6) {
args.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(
@@ -136,7 +136,7 @@ void Path2D::BezierCurveTo(const v8::FunctionCallbackInfo<Value>& args) {
SkDoubleToScalar(x), SkDoubleToScalar(y));
}
-void Path2D::Arc(const v8::FunctionCallbackInfo<Value>& args) {
+void Path2D::Arc(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 5 && args.Length() != 6) {
args.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(
@@ -172,7 +172,7 @@ void Path2D::Arc(const v8::FunctionCallbackInfo<Value>& args) {
SkRadiansToDegrees(sweepAngle));
}
-void Path2D::Rect(const v8::FunctionCallbackInfo<Value>& args) {
+void Path2D::Rect(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 4) {
args.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(
@@ -194,7 +194,7 @@ void Path2D::Rect(const v8::FunctionCallbackInfo<Value>& args) {
path->fSkPath.addRect(rect);
}
-void Path2D::Oval(const v8::FunctionCallbackInfo<Value>& args) {
+void Path2D::Oval(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 4 && args.Length() != 5) {
args.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(
@@ -220,7 +220,7 @@ void Path2D::Oval(const v8::FunctionCallbackInfo<Value>& args) {
path->fSkPath.addOval(rect, dir);
}
-void Path2D::ConicTo(const v8::FunctionCallbackInfo<Value>& args) {
+void Path2D::ConicTo(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 5) {
args.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(
diff --git a/experimental/SkV8Example/SkV8Example.cpp b/experimental/SkV8Example/SkV8Example.cpp
index 00fa277351..84fe648c90 100644
--- a/experimental/SkV8Example/SkV8Example.cpp
+++ b/experimental/SkV8Example/SkV8Example.cpp
@@ -7,8 +7,7 @@
*
*/
#include <v8.h>
-
-using namespace v8;
+#include <include/libplatform/libplatform.h>
#include "SkV8Example.h"
#include "Global.h"
@@ -110,16 +109,14 @@ void SkV8ExampleWindow::windowSizeChanged() {
#endif
#if SK_SUPPORT_GPU
-SkCanvas* SkV8ExampleWindow::createCanvas() {
+SkSurface* SkV8ExampleWindow::createSurface() {
if (FLAGS_gpu) {
- SkCanvas* c = fCurSurface->getCanvas();
- // Increase the ref count since the surface keeps a reference
- // to the canvas, but callers of createCanvas put the results
- // in a SkAutoTUnref.
- c->ref();
- return c;
+ // Increase the ref count since callers of createSurface put the
+ // results in a SkAutoTUnref.
+ fCurSurface->ref();
+ return fCurSurface;
} else {
- return this->INHERITED::createCanvas();
+ return this->INHERITED::createSurface();
}
}
#endif
@@ -163,13 +160,22 @@ void SkV8ExampleWindow::onHandleInval(const SkIRect& rect) {
}
#endif
+
SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) {
printf("Started\n");
SkCommandLineFlags::Parse(argc, argv);
- // Get the default Isolate created at startup.
- Isolate* isolate = Isolate::GetCurrent();
+ v8::V8::InitializeICU();
+ v8::Platform* platform = v8::platform::CreateDefaultPlatform();
+ v8::V8::InitializePlatform(platform);
+ v8::V8::Initialize();
+
+ v8::Isolate* isolate = v8::Isolate::New();
+ v8::Isolate::Scope isolate_scope(isolate);
+ v8::HandleScope handle_scope(isolate);
+ isolate->Enter();
+
Global* global = new Global(isolate);
diff --git a/experimental/SkV8Example/SkV8Example.h b/experimental/SkV8Example/SkV8Example.h
index 5e1400564c..c111a48006 100644
--- a/experimental/SkV8Example/SkV8Example.h
+++ b/experimental/SkV8Example/SkV8Example.h
@@ -29,7 +29,7 @@ protected:
virtual void onSizeChange() SK_OVERRIDE;
#if SK_SUPPORT_GPU
- virtual SkCanvas* createCanvas() SK_OVERRIDE;
+ virtual SkSurface* createSurface() SK_OVERRIDE;
#endif
#ifdef SK_BUILD_FOR_WIN