MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

add FinalizationRegistry and WeakRef tests

+49
+28
examples/spec/finalizationregistry.js
··· 1 + import { test, summary } from './helpers.js'; 2 + 3 + console.log('FinalizationRegistry Tests\n'); 4 + 5 + let callbackCalled = false; 6 + const fr = new FinalizationRegistry(function(heldValue) { 7 + callbackCalled = true; 8 + }); 9 + 10 + test('finalizationregistry instanceof', fr instanceof FinalizationRegistry, true); 11 + test('finalizationregistry prototype', Object.getPrototypeOf(fr) === FinalizationRegistry.prototype, true); 12 + test('finalizationregistry has register', typeof fr.register, 'function'); 13 + test('finalizationregistry has unregister', typeof fr.unregister, 'function'); 14 + 15 + const target = {}; 16 + const token = {}; 17 + fr.register(target, 'held value', token); 18 + 19 + test('finalizationregistry register returns undefined', fr.register({}, 'test'), undefined); 20 + 21 + const unregisterResult = fr.unregister(token); 22 + test('finalizationregistry unregister returns boolean', typeof unregisterResult, 'boolean'); 23 + test('finalizationregistry unregister found token', unregisterResult, true); 24 + 25 + const notFoundResult = fr.unregister({}); 26 + test('finalizationregistry unregister not found', notFoundResult, false); 27 + 28 + summary();
+21
examples/spec/weakref.js
··· 1 + import { test, summary } from './helpers.js'; 2 + 3 + console.log('WeakRef Tests\n'); 4 + 5 + const obj1 = { name: 'test' }; 6 + const ref1 = new WeakRef(obj1); 7 + 8 + test('weakref deref returns target', ref1.deref() === obj1, true); 9 + test('weakref deref value', ref1.deref().name, 'test'); 10 + 11 + const obj2 = { value: 42 }; 12 + const ref2 = new WeakRef(obj2); 13 + test('weakref deref number value', ref2.deref().value, 42); 14 + 15 + const obj3 = {}; 16 + const ref3 = new WeakRef(obj3); 17 + test('weakref has deref method', typeof ref3.deref, 'function'); 18 + test('weakref instanceof', ref3 instanceof WeakRef, true); 19 + test('weakref prototype', Object.getPrototypeOf(ref3) === WeakRef.prototype, true); 20 + 21 + summary();