-
Notifications
You must be signed in to change notification settings - Fork 461
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes: #333
- Loading branch information
Gabriel Schulhof
committed
Sep 17, 2018
1 parent
622ffae
commit d65616c
Showing
7 changed files
with
398 additions
and
106 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#include <napi.h> | ||
|
||
static Napi::Value TestMethod(const Napi::CallbackInfo& /*info*/) { | ||
return Napi::Value(); | ||
} | ||
|
||
static Napi::Value TestGetter(const Napi::CallbackInfo& /*info*/) { | ||
return Napi::Value(); | ||
} | ||
|
||
static void TestSetter(const Napi::CallbackInfo& /*info*/) { | ||
} | ||
|
||
class TestClass : public Napi::ObjectWrap<TestClass> { | ||
public: | ||
TestClass(const Napi::CallbackInfo& info): | ||
ObjectWrap<TestClass>(info) { | ||
} | ||
static Napi::Value TestClassStaticMethod(const Napi::CallbackInfo& info) { | ||
return Napi::Number::New(info.Env(), 42); | ||
} | ||
|
||
static void TestClassStaticVoidMethod(const Napi::CallbackInfo& /*info*/) { | ||
} | ||
|
||
Napi::Value TestClassInstanceMethod(const Napi::CallbackInfo& info) { | ||
return Napi::Number::New(info.Env(), 42); | ||
} | ||
|
||
void TestClassInstanceVoidMethod(const Napi::CallbackInfo& /*info*/) { | ||
} | ||
|
||
Napi::Value TestClassInstanceGetter(const Napi::CallbackInfo& info) { | ||
return Napi::Number::New(info.Env(), 42); | ||
} | ||
|
||
void TestClassInstanceSetter(const Napi::CallbackInfo& /*info*/, | ||
const Napi::Value& /*new_value*/) { | ||
} | ||
|
||
static Napi::Function NewClass(Napi::Env env) { | ||
return DefineClass(env, "TestClass", { | ||
StaticMethod(env, "staticMethod", TestClassStaticMethod), | ||
StaticMethod(env, "staticVoidMethod", TestClassStaticVoidMethod), | ||
InstanceMethod("instanceMethod", &TestClass::TestClassInstanceMethod), | ||
InstanceMethod("instanceVoidMethod", | ||
&TestClass::TestClassInstanceVoidMethod), | ||
InstanceMethod(Napi::Symbol::New(env, "instanceMethod"), | ||
&TestClass::TestClassInstanceMethod), | ||
InstanceMethod(Napi::Symbol::New(env, "instanceVoidMethod"), | ||
&TestClass::TestClassInstanceVoidMethod), | ||
InstanceAccessor("instanceAccessor", | ||
&TestClass::TestClassInstanceGetter, | ||
&TestClass::TestClassInstanceSetter) | ||
}); | ||
} | ||
}; | ||
|
||
static Napi::Value CreateTestObject(const Napi::CallbackInfo& info) { | ||
Napi::Object item = Napi::Object::New(info.Env()); | ||
item["testMethod"] = | ||
Napi::Function::New(info.Env(), TestMethod, "testMethod"); | ||
|
||
item.DefineProperties({ | ||
Napi::PropertyDescriptor::Accessor(info.Env(), | ||
item, | ||
"accessor_1", | ||
TestGetter), | ||
Napi::PropertyDescriptor::Accessor(info.Env(), | ||
item, | ||
std::string("accessor_1_std_string"), | ||
TestGetter), | ||
Napi::PropertyDescriptor::Accessor(info.Env(), | ||
item, | ||
Napi::String::New(info.Env(), | ||
"accessor_1_js_string"), | ||
TestGetter), | ||
Napi::PropertyDescriptor::Accessor(info.Env(), | ||
item, | ||
"accessor_2", | ||
TestGetter, | ||
TestSetter), | ||
Napi::PropertyDescriptor::Accessor(info.Env(), | ||
item, | ||
std::string("accessor_2_std_string"), | ||
TestGetter, | ||
TestSetter), | ||
Napi::PropertyDescriptor::Accessor(info.Env(), | ||
item, | ||
Napi::String::New(info.Env(), | ||
"accessor_2_js_string"), | ||
TestGetter, | ||
TestSetter), | ||
Napi::PropertyDescriptor::Value("TestClass", | ||
TestClass::NewClass(info.Env())), | ||
}); | ||
|
||
return item; | ||
} | ||
|
||
Napi::Object InitThunkingManual(Napi::Env env) { | ||
Napi::Object exports = Napi::Object::New(env); | ||
exports["createTestObject"] = | ||
Napi::Function::New(env, CreateTestObject, "createTestObject"); | ||
return exports; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Flags: --expose-gc | ||
'use strict'; | ||
const buildType = process.config.target_defaults.default_configuration; | ||
const assert = require('assert'); | ||
|
||
test(require(`./build/${buildType}/binding.node`)); | ||
test(require(`./build/${buildType}/binding_noexcept.node`)); | ||
|
||
function test(binding) { | ||
console.log("Thunking: Performing initial GC"); | ||
global.gc(); | ||
console.log("Thunking: Creating test object"); | ||
let object = binding.thunking_manual.createTestObject(); | ||
object = null; | ||
console.log("Thunking: About to GC\n--------"); | ||
global.gc(); | ||
console.log("--------\nThunking: GC complete"); | ||
} |