MIRROR: javascript for 🐜's, a tiny runtime with big ambitions
1// Test primitive wrapper objects with SLOT_PRIMITIVE
2
3let passed = 0;
4let failed = 0;
5
6function test(name, condition) {
7 if (condition) {
8 console.log('✓', name);
9 passed++;
10 } else {
11 console.log('✗', name);
12 failed++;
13 }
14}
15
16// String wrapper
17let s = new String('hello');
18test('String wrapper typeof', typeof s === 'object');
19test('String wrapper + concat', s + ' world' === 'hello world');
20test('String wrapper length', s.length === 5);
21test('String wrapper valueOf', s.valueOf() === 'hello');
22
23// Number wrapper
24let n = new Number(42);
25test('Number wrapper typeof', typeof n === 'object');
26test('Number wrapper + arithmetic', n + 8 === 50);
27test('Number wrapper valueOf', n.valueOf() === 42);
28
29// Boolean wrapper
30let b = new Boolean(true);
31test('Boolean wrapper typeof', typeof b === 'object');
32test('Boolean wrapper is truthy', !!b === true);
33test('Boolean wrapper valueOf', b.valueOf() === true);
34
35// Object() wrapping primitives
36let wrapped = Object('test');
37test('Object(string) is object', typeof wrapped === 'object');
38test('Object(string) valueOf', wrapped.valueOf() === 'test');
39
40console.log('\nResults:', passed, 'passed,', failed, 'failed');