From ef5a98900ad056f9fb1ff52732fa496cf5405f1f Mon Sep 17 00:00:00 2001 From: David Sanders Date: Fri, 18 Oct 2024 18:17:02 -0700 Subject: [PATCH] Change methodswithdata tests line endings to LF (#971) These two files got committed with CRLF line endings, while the rest of the repo uses LF line endings. --- test/cpp/methodswithdata.cpp | 388 ++++++++++++++++---------------- test/js/methodswithdata-test.js | 74 +++--- 2 files changed, 231 insertions(+), 231 deletions(-) diff --git a/test/cpp/methodswithdata.cpp b/test/cpp/methodswithdata.cpp index 1eb87f3a..7dd6cbc3 100644 --- a/test/cpp/methodswithdata.cpp +++ b/test/cpp/methodswithdata.cpp @@ -1,194 +1,194 @@ -/********************************************************************* - * NAN - Native Abstractions for Node.js - * - * Copyright (c) 2019 NAN contributors - * - * MIT License - ********************************************************************/ - -#include - -using namespace Nan; // NOLINT(build/namespaces) - -NAN_METHOD(TestWithData) { - info.GetReturnValue().Set(false); - { - std::string datavalue = *Nan::Utf8String(info.Data()); - if (datavalue != "test-value")return; - } - info.GetReturnValue().Set(true); -} - -class SetterGetter : public ObjectWrap { - public: - static NAN_MODULE_INIT(Init); - static v8::Local NewInstance (); - static NAN_METHOD(New); - static NAN_METHOD(Log); - static NAN_GETTER(GetProp1); - static NAN_GETTER(GetProp2); - static NAN_SETTER(SetProp2); - - SetterGetter(); - - char log[1024]; - char prop1[256]; - char prop2[256]; -}; - -static Persistent settergetter_constructor; - -SetterGetter::SetterGetter() { - log[0] = '\0'; - strncpy(prop1, "this is property 1", sizeof (prop1) - 1); - prop1[sizeof (prop1) - 1] = '\0'; - prop2[0] = '\0'; -} - -v8::Local SetterGetter::NewInstance () { - EscapableHandleScope scope; - v8::Local constructorHandle = - Nan::New(settergetter_constructor); - v8::Local instance = - Nan::NewInstance( - Nan::GetFunction(constructorHandle).ToLocalChecked()).ToLocalChecked(); - return scope.Escape(instance); -} - -NAN_METHOD(SetterGetter::New) { - std::string datavalue = *Nan::Utf8String(info.Data()); - assert(datavalue == "new-data"); - - SetterGetter* settergetter = new SetterGetter(); - assert(strlen(settergetter->log) < sizeof (settergetter->log)); - strncat( - settergetter->log - , "New()\n" - , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); - settergetter->Wrap(info.This()); - - info.GetReturnValue().Set(info.This()); -} - -NAN_GETTER(SetterGetter::GetProp1) { - std::string datavalue = *Nan::Utf8String(info.Data()); - assert(datavalue == "prop1-data"); - SetterGetter* settergetter = - ObjectWrap::Unwrap(info.Holder()); - assert(strlen(settergetter->log) < sizeof (settergetter->log)); - strncat( - settergetter->log - , "Prop1:GETTER(" - , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); - assert(strlen(settergetter->log) < sizeof (settergetter->log)); - strncat( - settergetter->log - , settergetter->prop1 - , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); - assert(strlen(settergetter->log) < sizeof (settergetter->log)); - strncat( - settergetter->log - , ")\n" - , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); - - info.GetReturnValue().Set(Nan::New(settergetter->prop1).ToLocalChecked()); -} - -NAN_GETTER(SetterGetter::GetProp2) { - std::string datavalue = *Nan::Utf8String(info.Data()); - assert(datavalue == "prop2-data"); - - SetterGetter* settergetter = - ObjectWrap::Unwrap(info.Holder()); - assert(strlen(settergetter->log) < sizeof (settergetter->log)); - strncat( - settergetter->log - , "Prop2:GETTER(" - , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); - assert(strlen(settergetter->log) < sizeof (settergetter->log)); - strncat( - settergetter->log - , settergetter->prop2 - , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); - assert(strlen(settergetter->log) < sizeof (settergetter->log)); - strncat( - settergetter->log - , ")\n" - , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); - - info.GetReturnValue().Set(Nan::New(settergetter->prop2).ToLocalChecked()); -} - -NAN_SETTER(SetterGetter::SetProp2) { - std::string datavalue = *Nan::Utf8String(info.Data()); - assert(datavalue == "prop2-data"); - - SetterGetter* settergetter = - ObjectWrap::Unwrap(info.Holder()); - strncpy( - settergetter->prop2 - , *Utf8String(value) - , sizeof (settergetter->prop2)); - settergetter->prop2[sizeof (settergetter->prop2) - 1] = '\0'; - assert(strlen(settergetter->log) < sizeof (settergetter->log)); - strncat( - settergetter->log - , "Prop2:SETTER(" - , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); - assert(strlen(settergetter->log) < sizeof (settergetter->log)); - strncat( - settergetter->log - , settergetter->prop2 - , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); - assert(strlen(settergetter->log) < sizeof (settergetter->log)); - strncat( - settergetter->log - , ")\n" - , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); -} - -NAN_METHOD(SetterGetter::Log) { - SetterGetter* settergetter = - ObjectWrap::Unwrap(info.Holder()); - - info.GetReturnValue().Set(Nan::New(settergetter->log).ToLocalChecked()); -} - -NAN_METHOD(CreateNew) { - std::string datavalue = *Nan::Utf8String(info.Data()); - assert(datavalue == "create-data"); - - info.GetReturnValue().Set(SetterGetter::NewInstance()); -} - -NAN_MODULE_INIT(Init) { - SetMethod(target, "testWithData", TestWithData, New("test-value").ToLocalChecked()); - - v8::Local tpl = - Nan::New(SetterGetter::New, New("new-data").ToLocalChecked()); - settergetter_constructor.Reset(tpl); - tpl->SetClassName(Nan::New("SetterGetter").ToLocalChecked()); - tpl->InstanceTemplate()->SetInternalFieldCount(1); - SetPrototypeMethod(tpl, "log", SetterGetter::Log,Nan::New("log-data").ToLocalChecked()); - v8::Local itpl = tpl->InstanceTemplate(); - SetAccessor( - itpl - , Nan::New("prop1").ToLocalChecked() - , SetterGetter::GetProp1 - , 0 - , Nan::New("prop1-data").ToLocalChecked()); - SetAccessor( - itpl - , Nan::New("prop2").ToLocalChecked() - , SetterGetter::GetProp2 - , SetterGetter::SetProp2 - , Nan::New("prop2-data").ToLocalChecked() - ); - - v8::Local createnew = - Nan::GetFunction( - Nan::New(CreateNew, Nan::New("create-data").ToLocalChecked())).ToLocalChecked(); - Set(target, Nan::New("create").ToLocalChecked(), createnew); -} - -NODE_MODULE(methodswithdata, Init) +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2019 NAN contributors + * + * MIT License + ********************************************************************/ + +#include + +using namespace Nan; // NOLINT(build/namespaces) + +NAN_METHOD(TestWithData) { + info.GetReturnValue().Set(false); + { + std::string datavalue = *Nan::Utf8String(info.Data()); + if (datavalue != "test-value")return; + } + info.GetReturnValue().Set(true); +} + +class SetterGetter : public ObjectWrap { + public: + static NAN_MODULE_INIT(Init); + static v8::Local NewInstance (); + static NAN_METHOD(New); + static NAN_METHOD(Log); + static NAN_GETTER(GetProp1); + static NAN_GETTER(GetProp2); + static NAN_SETTER(SetProp2); + + SetterGetter(); + + char log[1024]; + char prop1[256]; + char prop2[256]; +}; + +static Persistent settergetter_constructor; + +SetterGetter::SetterGetter() { + log[0] = '\0'; + strncpy(prop1, "this is property 1", sizeof (prop1) - 1); + prop1[sizeof (prop1) - 1] = '\0'; + prop2[0] = '\0'; +} + +v8::Local SetterGetter::NewInstance () { + EscapableHandleScope scope; + v8::Local constructorHandle = + Nan::New(settergetter_constructor); + v8::Local instance = + Nan::NewInstance( + Nan::GetFunction(constructorHandle).ToLocalChecked()).ToLocalChecked(); + return scope.Escape(instance); +} + +NAN_METHOD(SetterGetter::New) { + std::string datavalue = *Nan::Utf8String(info.Data()); + assert(datavalue == "new-data"); + + SetterGetter* settergetter = new SetterGetter(); + assert(strlen(settergetter->log) < sizeof (settergetter->log)); + strncat( + settergetter->log + , "New()\n" + , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); + settergetter->Wrap(info.This()); + + info.GetReturnValue().Set(info.This()); +} + +NAN_GETTER(SetterGetter::GetProp1) { + std::string datavalue = *Nan::Utf8String(info.Data()); + assert(datavalue == "prop1-data"); + SetterGetter* settergetter = + ObjectWrap::Unwrap(info.Holder()); + assert(strlen(settergetter->log) < sizeof (settergetter->log)); + strncat( + settergetter->log + , "Prop1:GETTER(" + , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); + assert(strlen(settergetter->log) < sizeof (settergetter->log)); + strncat( + settergetter->log + , settergetter->prop1 + , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); + assert(strlen(settergetter->log) < sizeof (settergetter->log)); + strncat( + settergetter->log + , ")\n" + , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); + + info.GetReturnValue().Set(Nan::New(settergetter->prop1).ToLocalChecked()); +} + +NAN_GETTER(SetterGetter::GetProp2) { + std::string datavalue = *Nan::Utf8String(info.Data()); + assert(datavalue == "prop2-data"); + + SetterGetter* settergetter = + ObjectWrap::Unwrap(info.Holder()); + assert(strlen(settergetter->log) < sizeof (settergetter->log)); + strncat( + settergetter->log + , "Prop2:GETTER(" + , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); + assert(strlen(settergetter->log) < sizeof (settergetter->log)); + strncat( + settergetter->log + , settergetter->prop2 + , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); + assert(strlen(settergetter->log) < sizeof (settergetter->log)); + strncat( + settergetter->log + , ")\n" + , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); + + info.GetReturnValue().Set(Nan::New(settergetter->prop2).ToLocalChecked()); +} + +NAN_SETTER(SetterGetter::SetProp2) { + std::string datavalue = *Nan::Utf8String(info.Data()); + assert(datavalue == "prop2-data"); + + SetterGetter* settergetter = + ObjectWrap::Unwrap(info.Holder()); + strncpy( + settergetter->prop2 + , *Utf8String(value) + , sizeof (settergetter->prop2)); + settergetter->prop2[sizeof (settergetter->prop2) - 1] = '\0'; + assert(strlen(settergetter->log) < sizeof (settergetter->log)); + strncat( + settergetter->log + , "Prop2:SETTER(" + , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); + assert(strlen(settergetter->log) < sizeof (settergetter->log)); + strncat( + settergetter->log + , settergetter->prop2 + , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); + assert(strlen(settergetter->log) < sizeof (settergetter->log)); + strncat( + settergetter->log + , ")\n" + , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); +} + +NAN_METHOD(SetterGetter::Log) { + SetterGetter* settergetter = + ObjectWrap::Unwrap(info.Holder()); + + info.GetReturnValue().Set(Nan::New(settergetter->log).ToLocalChecked()); +} + +NAN_METHOD(CreateNew) { + std::string datavalue = *Nan::Utf8String(info.Data()); + assert(datavalue == "create-data"); + + info.GetReturnValue().Set(SetterGetter::NewInstance()); +} + +NAN_MODULE_INIT(Init) { + SetMethod(target, "testWithData", TestWithData, New("test-value").ToLocalChecked()); + + v8::Local tpl = + Nan::New(SetterGetter::New, New("new-data").ToLocalChecked()); + settergetter_constructor.Reset(tpl); + tpl->SetClassName(Nan::New("SetterGetter").ToLocalChecked()); + tpl->InstanceTemplate()->SetInternalFieldCount(1); + SetPrototypeMethod(tpl, "log", SetterGetter::Log,Nan::New("log-data").ToLocalChecked()); + v8::Local itpl = tpl->InstanceTemplate(); + SetAccessor( + itpl + , Nan::New("prop1").ToLocalChecked() + , SetterGetter::GetProp1 + , 0 + , Nan::New("prop1-data").ToLocalChecked()); + SetAccessor( + itpl + , Nan::New("prop2").ToLocalChecked() + , SetterGetter::GetProp2 + , SetterGetter::SetProp2 + , Nan::New("prop2-data").ToLocalChecked() + ); + + v8::Local createnew = + Nan::GetFunction( + Nan::New(CreateNew, Nan::New("create-data").ToLocalChecked())).ToLocalChecked(); + Set(target, Nan::New("create").ToLocalChecked(), createnew); +} + +NODE_MODULE(methodswithdata, Init) diff --git a/test/js/methodswithdata-test.js b/test/js/methodswithdata-test.js index 9f4fc524..c6d2b22f 100644 --- a/test/js/methodswithdata-test.js +++ b/test/js/methodswithdata-test.js @@ -1,38 +1,38 @@ -/********************************************************************* - * NAN - Native Abstractions for Node.js - * - * Copyright (c) 2019 NAN contributors - * - * MIT License - ********************************************************************/ - -const test = require('tap').test - , testRoot = require('path').resolve(__dirname, '..') - , bindings = require('bindings')({ module_root: testRoot, bindings: 'methodswithdata' }) - -test('SetMethod with data', function (t) { - t.plan(1); - t.ok(bindings.testWithData()); -}); - -test('accessors with data', function (t) { - t.plan(7) - var settergetter = bindings.create() - t.equal(settergetter.prop1, 'this is property 1') - t.ok(settergetter.prop2 === '') - settergetter.prop2 = 'setting a value' - t.equal(settergetter.prop2, 'setting a value') - t.equal(settergetter.log(), - 'New()\n' + - 'Prop1:GETTER(this is property 1)\n' + - 'Prop2:GETTER()\n' + - 'Prop2:SETTER(setting a value)\n' + - 'Prop2:GETTER(setting a value)\n' - ) - var derived = Object.create(settergetter) - t.equal(derived.prop1, 'this is property 1') - derived.prop2 = 'setting a new value' - t.equal(derived.prop2, 'setting a new value') - t.equal(settergetter.prop2, 'setting a new value') - }) +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2019 NAN contributors + * + * MIT License + ********************************************************************/ + +const test = require('tap').test + , testRoot = require('path').resolve(__dirname, '..') + , bindings = require('bindings')({ module_root: testRoot, bindings: 'methodswithdata' }) + +test('SetMethod with data', function (t) { + t.plan(1); + t.ok(bindings.testWithData()); +}); + +test('accessors with data', function (t) { + t.plan(7) + var settergetter = bindings.create() + t.equal(settergetter.prop1, 'this is property 1') + t.ok(settergetter.prop2 === '') + settergetter.prop2 = 'setting a value' + t.equal(settergetter.prop2, 'setting a value') + t.equal(settergetter.log(), + 'New()\n' + + 'Prop1:GETTER(this is property 1)\n' + + 'Prop2:GETTER()\n' + + 'Prop2:SETTER(setting a value)\n' + + 'Prop2:GETTER(setting a value)\n' + ) + var derived = Object.create(settergetter) + t.equal(derived.prop1, 'this is property 1') + derived.prop2 = 'setting a new value' + t.equal(derived.prop2, 'setting a new value') + t.equal(settergetter.prop2, 'setting a new value') + }) \ No newline at end of file