Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update V8U to latest version

  • Loading branch information...
commit 76a0b3606b11ed73265857a9df513ee0a90a5b46 1 parent 83c42b4
@jmendeth jmendeth authored
Showing with 58 additions and 45 deletions.
  1. +38 −25 src/v8u.hpp
  2. +19 −19 src/version.hpp
  3. +1 −1  v8u
View
63 src/v8u.hpp
@@ -61,8 +61,7 @@ namespace v8u {
return ThrowException(v8::Exception::Error(v8::String::New(err.data(), err.length())));\
} catch (...) { \
return ThrowException(v8::Exception::Error(v8::String::New("Unknown error!")));\
- } \
-}
+ }
#define V8_WRAP_END_NR() \
} catch (v8::Persistent<v8::Value>& err) { \
@@ -79,8 +78,7 @@ namespace v8u {
ThrowException(v8::Exception::Error(v8::String::New(err.data(), err.length())));\
} catch (...) { \
ThrowException(v8::Exception::Error(v8::String::New("Unknown error!"))); \
- } \
-}
+ }
// JS arguments
@@ -91,42 +89,57 @@ inline void CheckArguments(int min, const v8::Arguments& args) {
// V8 callback templates
+#define V8_S_CALLBACK(IDENTIFIER) \
+ v8::Handle<v8::Value> IDENTIFIER(const v8::Arguments& args)
+
#define V8_CALLBACK(IDENTIFIER, MIN) \
-v8::Handle<v8::Value> IDENTIFIER(const v8::Arguments& args) { \
+V8_S_CALLBACK(IDENTIFIER) { \
V8_WRAP_START() \
CheckArguments(MIN, args);
+#define V8_CALLBACK_END() V8_WRAP_END() }
+
+#define V8_S_GETTER(IDENTIFIER) \
+ v8::Handle<v8::Value> IDENTIFIER(v8::Local<v8::String> name, \
+ const v8::AccessorInfo& info)
+
#define V8_GETTER(IDENTIFIER) \
-v8::Handle<v8::Value> IDENTIFIER(v8::Local<v8::String> name, \
- const v8::AccessorInfo& info) { \
+V8_S_GETTER(IDENTIFIER) { \
V8_WRAP_START()
+#define V8_GETTER_END() V8_WRAP_END() }
+
+#define V8_S_SETTER(IDENTIFIER) \
+ void IDENTIFIER(v8::Local<v8::String> name, v8::Local<v8::Value> value, \
+ const v8::AccessorInfo& info)
+
#define V8_SETTER(IDENTIFIER) \
-void IDENTIFIER(v8::Local<v8::String> name, v8::Local<v8::Value> value, \
- const v8::AccessorInfo& info) { \
+V8_S_SETTER(IDENTIFIER) { \
V8_WRAP_START()
+#define V8_SETTER_END() V8_WRAP_END_NR() }
+
#define V8_UNWRAP(CPP_TYPE, OBJ) \
CPP_TYPE* inst = node::ObjectWrap::Unwrap<CPP_TYPE>(OBJ.Holder());
// Class-specific templates
#define V8_CL_CTOR(CPP_TYPE, MIN) \
-static v8::Handle<v8::Value> NewInstance(const v8::Arguments& args) { \
- V8_WRAP_START() \
+static V8_S_CALLBACK(NewInstance) { \
if ((args.Length()==1) && (args[0]->IsExternal())) { \
((CPP_TYPE*)v8::External::Unwrap(args[0]))->Wrap(args.This()); \
- return scope.Close(args.This()); \
+ return args.This(); \
} \
if (!args.IsConstructCall()) \
- throw v8::Persistent<v8::Value>::New(v8::Exception::ReferenceError(v8::String::New("You must call this as a constructor")));\
+ return v8::ThrowException(v8u::ReferenceErr("You must call this as a constructor"));\
+ V8_WRAP_START() \
CheckArguments(MIN, args); \
CPP_TYPE* inst;
#define V8_CL_CTOR_END() \
inst->Wrap(args.This()); \
return scope.Close(args.This()); \
-V8_WRAP_END()
+V8_CALLBACK_END()
#define V8_CL_GETTER(CPP_TYPE, CPP_VAR) \
static V8_GETTER(Getter__##CPP_VAR) \
@@ -281,21 +294,21 @@ inline bool Bool(v8::Handle<v8::Value> hdl) {
// Defining things
-#define V8_DEF_TYPE(CPP_TYPE, V8_NAME) \
+#define V8_DEF_TYPE(V8_NAME) \
v8::Persistent<v8::FunctionTemplate> prot = v8::Persistent<v8::FunctionTemplate>::New(\
- v8::FunctionTemplate::New(CPP_TYPE::NewInstance)); \
+ v8::FunctionTemplate::New(NewInstance)); \
v8::Handle<v8::String> __cname = v8::String::NewSymbol(V8_NAME); \
prot->SetClassName(__cname); \
prot->InstanceTemplate()->SetInternalFieldCount(1);
-#define V8_DEF_PROP(CPP_TYPE, CPP_VAR, V8_NAME) \
- prot->InstanceTemplate()->SetAccessor(NODE_PSYMBOL(V8_NAME), CPP_TYPE::Getter__##CPP_VAR, CPP_TYPE::Setter__##CPP_VAR);
+#define V8_DEF_PROP(CPP_VAR, V8_NAME) \
+ prot->InstanceTemplate()->SetAccessor(NODE_PSYMBOL(V8_NAME), Getter__##CPP_VAR, Setter__##CPP_VAR);
-#define V8_DEF_RPROP(CPP_TYPE, CPP_VAR, V8_NAME) \
- prot->InstanceTemplate()->SetAccessor(NODE_PSYMBOL(V8_NAME), CPP_TYPE::Getter__##CPP_VAR);
+#define V8_DEF_RPROP(CPP_VAR, V8_NAME) \
+ prot->InstanceTemplate()->SetAccessor(NODE_PSYMBOL(V8_NAME), Getter__##CPP_VAR);
-#define V8_DEF_METHOD(CPP_TYPE, CPP_METHOD, V8_NAME) \
- NODE_SET_PROTOTYPE_METHOD(prot, V8_NAME, CPP_TYPE::CPP_METHOD);
+#define V8_DEF_METHOD(CPP_METHOD, V8_NAME) \
+ NODE_SET_PROTOTYPE_METHOD(prot, V8_NAME, CPP_METHOD);
#define V8_INHERIT(CLASSNAME) prot->Inherit(GetTemplate(CLASSNAME));
@@ -304,10 +317,10 @@ inline bool Bool(v8::Handle<v8::Value> hdl) {
#define NODE_DEF(IDENTIFIER) \
void IDENTIFIER(v8::Handle<v8::Object> target)
-#define NODE_DEF_TYPE(CPP_TYPE, V8_NAME) \
- NODE_DEF(init##CPP_TYPE) { \
+#define NODE_DEF_TYPE(V8_NAME) \
+ inline static NODE_DEF(init) { \
v8::HandleScope scope; \
- V8_DEF_TYPE(CPP_TYPE, V8_NAME)
+ V8_DEF_TYPE(V8_NAME)
#define NODE_DEF_TYPE_END() \
target->Set(__cname, prot->GetFunction()); \
View
38 src/version.hpp
@@ -66,47 +66,47 @@ class Version: public node::ObjectWrap {
V8_CL_CALLBACK(Version, ToString, 0) {
return scope.Close(Str(inst->toString()));
- } V8_WRAP_END()
+ } V8_CALLBACK_END()
V8_CL_CALLBACK(Version, Inspect, 0) {
return scope.Close(Str("<Version "+inst->toString()+">"));
- } V8_WRAP_END()
+ } V8_CALLBACK_END()
//Getters
V8_CL_GETTER(Version, Major) {
return scope.Close(Int(inst->major_));
- } V8_WRAP_END()
+ } V8_GETTER_END()
V8_CL_GETTER(Version, Minor) {
return scope.Close(Int(inst->minor_));
- } V8_WRAP_END()
+ } V8_GETTER_END()
V8_CL_GETTER(Version, Revision) {
return scope.Close(Int(inst->revision_));
- } V8_WRAP_END()
+ } V8_GETTER_END()
//Setters
V8_CL_SETTER(Version, Major) {
inst->major_ = Int(value);
- } V8_WRAP_END_NR()
+ } V8_SETTER_END()
V8_CL_SETTER(Version, Minor) {
inst->minor_ = Int(value);
- } V8_WRAP_END_NR()
+ } V8_SETTER_END()
V8_CL_SETTER(Version, Revision) {
inst->revision_ = Int(value);
- } V8_WRAP_END_NR()
-private:
- int major_, minor_, revision_;
-};
+ } V8_SETTER_END()
-NODE_DEF_TYPE(Version, "Version") {
- V8_DEF_PROP(Version, Major, "major");
- V8_DEF_PROP(Version, Minor, "minor");
- V8_DEF_PROP(Version, Revision, "revision");
+ NODE_DEF_TYPE("Version") {
+ V8_DEF_PROP(Major, "major");
+ V8_DEF_PROP(Minor, "minor");
+ V8_DEF_PROP(Revision, "revision");
- V8_DEF_METHOD(Version, ToString, "toString");
- V8_DEF_METHOD(Version, Inspect, "inspect");
+ V8_DEF_METHOD(ToString, "toString");
+ V8_DEF_METHOD(Inspect, "inspect");
- StoreTemplate("v8u::Version", prot);
-} NODE_DEF_TYPE_END()
+ StoreTemplate("v8u::Version", prot);
+ } NODE_DEF_TYPE_END()
+private:
+ int major_, minor_, revision_;
+};
};
2  v8u
@@ -1 +1 @@
-Subproject commit 61c9399d762d231d3c20bd8f23aa1952803e9196
+Subproject commit b41912fc591f3ada9ca46fea44f88dd728af2709
Please sign in to comment.
Something went wrong with that request. Please try again.