Files
bun.sh/test/v8/v8-module/module.js
2024-09-26 16:54:37 -07:00

50 lines
1.5 KiB
JavaScript

module.exports = debugMode => {
const nativeModule = require(`./build/${debugMode ? "Debug" : "Release"}/v8tests`);
return {
...nativeModule,
test_v8_global() {
console.log("global initial value =", nativeModule.global_get());
nativeModule.global_set(123);
console.log("global after setting to 123 =", nativeModule.global_get());
nativeModule.global_set({ foo: 5, bar: ["one", "two", "three"] });
if (process.isBun) {
Bun.gc(true);
}
console.log("global after setting to object =", JSON.stringify(nativeModule.global_get()));
nativeModule.global_set(true);
console.log("global after setting to true =", nativeModule.global_get());
},
test_v8_function_template() {
const f = nativeModule.create_function_with_data();
if (process.isBun) {
Bun.gc(true);
}
console.log(f());
},
print_native_function() {
nativeModule.print_values_from_js(nativeModule.create_function_with_data());
},
call_function_with_weird_this_values() {
for (const thisValue of [null, undefined, 5, "abc"]) {
const ret = nativeModule.return_this.call(thisValue);
console.log("typeof =", typeof ret);
if (ret == globalThis) {
console.log("returned globalThis");
} else if (ret instanceof String) {
console.log("returned boxed String:", ret.toString());
} else {
console.log("returned", ret);
}
console.log("constructor is", ret.constructor.name);
}
},
};
};