From 6232426b5cdd6e70cacc21149115cb1eb13ea093 Mon Sep 17 00:00:00 2001 From: "Shao,Ting" Date: Fri, 25 Nov 2016 15:08:10 +0800 Subject: [PATCH] Add long long and unsigned long long support Use v8::Number when representing attributes, and return value. Parameters are also supported. --- templates/nanCxxImplMethod.def | 4 ++++ templates/nanCxxImplProperty.def | 2 ++ test/primitives/primitives-attributes.widl | 2 ++ test/primitives/primitives-param.widl | 2 ++ test/primitives/primitives_attributes.cpp | 4 +++- test/primitives/primitives_attributes.h | 28 ++++++++++++++++++++++ test/primitives/primitives_param.cpp | 15 ++++++++++++ test/primitives/primitives_param.h | 7 ++++++ test/test-primitives.js | 3 +++ 9 files changed, 66 insertions(+), 1 deletion(-) diff --git a/templates/nanCxxImplMethod.def b/templates/nanCxxImplMethod.def index 1896970..97db5c6 100644 --- a/templates/nanCxxImplMethod.def +++ b/templates/nanCxxImplMethod.def @@ -146,6 +146,10 @@ var argStr = args.join(', '); {{?? isArray(method.idlType) }} auto value = myself->impl_->{{=methodName}}({{=argStr}}); info.GetReturnValue().Set(static_cast>(value)); +{{?? method.idlType.idlType === 'long long' || method.idlType.idlType === 'unsigned long long' }} + // Primitive types (int, double ...) + auto value = {{=functionCallPrefix}}{{=methodName}}({{=argStr}}); + info.GetReturnValue().Set(Nan::New(value)); {{?? true }} // Primitive types (int, double ...) auto value = {{=functionCallPrefix}}{{=methodName}}({{=argStr}}); diff --git a/templates/nanCxxImplProperty.def b/templates/nanCxxImplProperty.def index d5973d9..d7f5b09 100644 --- a/templates/nanCxxImplProperty.def +++ b/templates/nanCxxImplProperty.def @@ -79,6 +79,8 @@ NAN_GETTER({{=className}}::{{=p.name}}Getter) { } else { info.GetReturnValue().Set(Nan::Undefined()); } +{{?? p.idlType.idlType === 'long long' || p.idlType.idlType === 'unsigned long long' }} + info.GetReturnValue().Set(Nan::New(impl_val){{=str}}); {{?? true}} info.GetReturnValue().Set(Nan::New(impl_val){{=str}}); {{?}} diff --git a/test/primitives/primitives-attributes.widl b/test/primitives/primitives-attributes.widl index 6eb2fb8..2d52cd0 100644 --- a/test/primitives/primitives-attributes.widl +++ b/test/primitives/primitives-attributes.widl @@ -17,4 +17,6 @@ interface PrimitivesAttributes { attribute unrestricted float vUnrestrictFloat; attribute double vDouble; attribute unrestricted double vUnrestrictDouble; + attribute long long vLongLong; + attribute unsigned long long vUnsignedLongLong; }; diff --git a/test/primitives/primitives-param.widl b/test/primitives/primitives-param.widl index edf944b..6e8f611 100644 --- a/test/primitives/primitives-param.widl +++ b/test/primitives/primitives-param.widl @@ -20,5 +20,7 @@ interface PrimitivesParam { unsigned long addUnsignedLong(unsigned long a, unsigned long b); DOMString show(DOMString str); void setvalue(boolean flag,float f,double d,unrestricted float uf,unrestricted double ud); + long long addLongLong(long long a, long long b); + unsigned long long addUnsignedLongLong(unsigned long long a, unsigned long long b); }; diff --git a/test/primitives/primitives_attributes.cpp b/test/primitives/primitives_attributes.cpp index 7955786..f714d21 100644 --- a/test/primitives/primitives_attributes.cpp +++ b/test/primitives/primitives_attributes.cpp @@ -10,7 +10,9 @@ PrimitivesAttributes::PrimitivesAttributes() vShort_(-32768), vUnsignedShort_(65535), vLong_(-200000), - vUnsignedLong_(200000) { + vUnsignedLong_(200000), + vLongLong_(0xffffffffffff), + vUnsignedLongLong_(0xffffffffffff) { } PrimitivesAttributes::~PrimitivesAttributes() { diff --git a/test/primitives/primitives_attributes.h b/test/primitives/primitives_attributes.h index 4289412..54ce46e 100644 --- a/test/primitives/primitives_attributes.h +++ b/test/primitives/primitives_attributes.h @@ -18,11 +18,14 @@ #include #include "gen/generator_helper.h" +#include "gen/array_helper.h" class PrimitivesAttributes { public: PrimitivesAttributes(); + PrimitivesAttributes(const PrimitivesAttributes& rhs); + ~PrimitivesAttributes(); PrimitivesAttributes& operator = (const PrimitivesAttributes& rhs); @@ -116,6 +119,27 @@ class PrimitivesAttributes { this->vUnrestrictDouble_ = new_value; } + int64_t get_vLongLong() const { + return this->vLongLong_; + } + + void set_vLongLong(const int64_t& new_value) { + this->vLongLong_ = new_value; + } + + uint64_t get_vUnsignedLongLong() const { + return this->vUnsignedLongLong_; + } + + void set_vUnsignedLongLong(const uint64_t& new_value) { + this->vUnsignedLongLong_ = new_value; + } + + void SetJavaScriptThis(v8::Local obj) { + // Ignore this if you don't need it + // Typical usage: emit an event on `obj` + } + private: int8_t vByte_; @@ -138,6 +162,10 @@ class PrimitivesAttributes { double vDouble_; double vUnrestrictDouble_; + + int64_t vLongLong_; + + uint64_t vUnsignedLongLong_; }; #endif // _PRIMITIVESATTRIBUTES_H_ diff --git a/test/primitives/primitives_param.cpp b/test/primitives/primitives_param.cpp index b54fe1d..0d43f11 100644 --- a/test/primitives/primitives_param.cpp +++ b/test/primitives/primitives_param.cpp @@ -5,9 +5,16 @@ #include "primitives_param.h" PrimitivesParam::PrimitivesParam() { + // TODO(widl-nan): init your members +} + +PrimitivesParam::PrimitivesParam(const PrimitivesParam& rhs) { + // TODO(widl-nan): copy from rhs if you want this behavior + // Or mark ctor = delete in primitives_param.h } PrimitivesParam::~PrimitivesParam() { + // TODO(widl-nan): do cleanup if necessary } PrimitivesParam& PrimitivesParam::operator = @@ -58,3 +65,11 @@ const double& d, const double& uf, const double& ud) { vUnrestrictDouble_ = ud; } +int64_t PrimitivesParam::addLongLong(const int64_t& a, const int64_t& b) { + return a + b; +} + +uint64_t PrimitivesParam::addUnsignedLongLong( + const uint64_t& a, const uint64_t& b) { + return a + b; +} diff --git a/test/primitives/primitives_param.h b/test/primitives/primitives_param.h index ff04a21..a4f8501 100644 --- a/test/primitives/primitives_param.h +++ b/test/primitives/primitives_param.h @@ -18,11 +18,14 @@ #include #include "gen/generator_helper.h" +#include "gen/array_helper.h" class PrimitivesParam { public: PrimitivesParam(); + PrimitivesParam(const PrimitivesParam& rhs); + ~PrimitivesParam(); PrimitivesParam& operator = (const PrimitivesParam& rhs); @@ -85,6 +88,10 @@ class PrimitivesParam { void setvalue(const bool& flag, const double& f, const double& d, const double& uf, const double& ud); + int64_t addLongLong(const int64_t& a, const int64_t& b); + + uint64_t addUnsignedLongLong(const uint64_t& a, const uint64_t& b); + private: bool vBoolean_; diff --git a/test/test-primitives.js b/test/test-primitives.js index f0ab2bb..514473a 100644 --- a/test/test-primitives.js +++ b/test/test-primitives.js @@ -53,6 +53,7 @@ describe('widl-nan Unit Test - primitives', function() { assert.equal(x.vShort, -32768); assert.equal(x.vUnsignedShort, 65535); assert.equal(x.vLong, -200000); + assert.equal(x.vLongLong, 281474976710655); assert.equal(x.vUnsignedLong, 200000); assert.equal(typeof x.vBoolean, 'boolean'); @@ -60,6 +61,7 @@ describe('widl-nan Unit Test - primitives', function() { assert.equal(typeof x.vDouble, 'number'); assert.equal(typeof x.vUnrestrictFloat, 'number'); assert.equal(typeof x.vUnrestrictDouble, 'number'); + assert.equal(typeof x.vLongLong, 'number'); x.vBoolean = true; x.vFloat = 1.0; @@ -83,6 +85,7 @@ describe('widl-nan Unit Test - primitives', function() { assert.equal(y.addShort(-150, -2000), -2150); assert.equal(y.addUnsignedShort(200, 3000), 3200); assert.equal(y.addLong(-100000, -30000), -130000); + assert.equal(y.addLongLong(1, 281474976710655), 281474976710656); assert.equal(y.addUnsignedLong(120000, 240000), 360000); assert.equal(y.show('DOMString'), 'DOMString');