Merge pull request #417 from realm/sk-node-6

Fix issues in Node 6
This commit is contained in:
Scott Kyle 2016-05-12 12:39:31 -07:00
commit 323583ed67
4 changed files with 21 additions and 10 deletions

View File

@ -49,7 +49,7 @@
"dependencies": {
"bindings": "^1.2.1",
"mockery": "^1.6.2",
"nan": "^2.2.1",
"nan": "^2.3.3",
"node-gyp": "^3.3.1",
"rnpm": "1.6.5",
"xcode": "0.8.4"

View File

@ -104,7 +104,7 @@ class ObjectWrap<void> {
using Internal = void;
static v8::Local<v8::FunctionTemplate> get_template() {
return v8::Local<v8::FunctionTemplate>();;
return v8::Local<v8::FunctionTemplate>();
}
};
@ -195,22 +195,21 @@ inline v8::Local<v8::FunctionTemplate> ObjectWrap<ClassType>::create_template()
template<typename ClassType>
inline void ObjectWrap<ClassType>::setup_method(v8::Local<v8::FunctionTemplate> tpl, const std::string &name, Nan::FunctionCallback callback) {
v8::Local<v8::Signature> signature = Nan::New<v8::Signature>(tpl);
v8::Local<v8::FunctionTemplate> t = Nan::New<v8::FunctionTemplate>(callback, v8::Local<v8::Value>(), signature);
v8::Local<v8::Function> fn = Nan::GetFunction(t).ToLocalChecked();
v8::Local<v8::FunctionTemplate> fn_tpl = Nan::New<v8::FunctionTemplate>(callback, v8::Local<v8::Value>(), signature);
v8::Local<v8::String> fn_name = Nan::New(name).ToLocalChecked();
// The reason we use this rather than Nan::SetPrototypeMethod is DontEnum.
tpl->PrototypeTemplate()->Set(fn_name, fn, v8::PropertyAttribute::DontEnum);
fn->SetName(fn_name);
tpl->PrototypeTemplate()->Set(fn_name, fn_tpl, v8::PropertyAttribute::DontEnum);
fn_tpl->SetClassName(fn_name);
}
template<typename ClassType>
inline void ObjectWrap<ClassType>::setup_static_method(v8::Local<v8::FunctionTemplate> tpl, const std::string &name, Nan::FunctionCallback callback) {
v8::Local<v8::Function> fn = Nan::GetFunction(Nan::New<v8::FunctionTemplate>(callback)).ToLocalChecked();
v8::Local<v8::FunctionTemplate> fn_tpl = Nan::New<v8::FunctionTemplate>(callback);
v8::Local<v8::String> fn_name = Nan::New(name).ToLocalChecked();
tpl->Set(fn_name, fn, v8::PropertyAttribute::DontEnum);
fn->SetName(fn_name);
tpl->Set(fn_name, fn_tpl, v8::PropertyAttribute::DontEnum);
fn_tpl->SetClassName(fn_name);
}
template<typename ClassType>

View File

@ -109,6 +109,14 @@ module.exports = {
throw new TestFailureError(errorMessage || 'Condition expected to be true');
}
},
isNode: function() {
return typeof process == 'object' && Object.prototype.toString.call(process) == '[object process]';
},
isNode6: function() {
return this.isNode() && process.version.indexOf('v6.') == 0;
},
};
function TestFailureError(message) {

View File

@ -554,7 +554,11 @@ module.exports = BaseTest.extend({
TestCase.assertEqual(list.slice(1, 3).length, 2);
TestCase.assertEqual(list.slice(1, 3)[1].age, 12);
TestCase.assertEqual(list.join(' '), 'Ari Tim Bjarne');
// A Node 6 regression in v8 causes an error when converting our objects to strings:
// TypeError: Cannot convert a Symbol value to a string
if (!TestCase.isNode6()) {
TestCase.assertEqual(list.join(' '), 'Ari Tim Bjarne');
}
var count = 0;
list.forEach(function(p, i) {