Skip to content

Commit ec42ea2

Browse files
billbudgeBill Budge
andauthored
Embind: test float argument conversion with and without assertions. (#15509)
Co-authored-by: Bill Budge <bbudge@chromium.org>
1 parent 5db73a6 commit ec42ea2

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/embind/embind.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ var LibraryEmbind = {
5555
// names. This lets the test suite know that.
5656
Module['DYNAMIC_EXECUTION'] = true;
5757
#endif
58+
#if ASSERTIONS
59+
Module['ASSERTIONS'] = true;
60+
#endif
5861
#if EMBIND_STD_STRING_IS_UTF8
5962
Module['EMBIND_STD_STRING_IS_UTF8'] = true;
6063
#endif

tests/embind/embind.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,24 @@ module({
638638
assert.equal(2, cm.const_ref_adder(true, true));
639639
});
640640

641+
assert.throws(TypeError, function() { cm.const_ref_adder(Symbol('0'), 1); });
642+
assert.throws(TypeError, function() { cm.const_ref_adder(BigInt(0), 1); });
643+
644+
if (cm['ASSERTIONS']) {
645+
test("can pass only number and boolean with assertions assertions", function() {
646+
assert.throws(TypeError, function() { cm.const_ref_adder(1, undefined); });
647+
assert.throws(TypeError, function() { cm.const_ref_adder(1, null); });
648+
assert.throws(TypeError, function() { cm.const_ref_adder(1, '2'); });
649+
});
650+
} else {
651+
test("can pass other types as floats without assertions", function() {
652+
assert.equal(3, cm.const_ref_adder(1, '2'));
653+
assert.equal(1, cm.const_ref_adder(1, null)); // null => 0
654+
assert.true(isNaN(cm.const_ref_adder(1, 'cannot parse')));
655+
assert.true(isNaN(cm.const_ref_adder(1, undefined))); // undefined => NaN
656+
});
657+
}
658+
641659
test("convert double to unsigned", function() {
642660
var rv = cm.emval_test_as_unsigned(1.5);
643661
assert.equal('number', typeof rv);

tests/embind/imvu_test_adapter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ function module(ignore, func) {
203203
}
204204

205205
var formatTestValue = function(v) {
206+
if (v === undefined) return 'undefined';
206207
return v.toString();
207208
/*
208209
var s = IMVU.repr(v, TEST_MAX_OUTPUT_SIZE + 1);

0 commit comments

Comments
 (0)