Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 9b139ac

Browse files
committed
Allow null args to dynamic invocations
Fixes #194. BUG= [email protected] Review URL: https://codereview.chromium.org/1149243002
1 parent 9424411 commit 9b139ac

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

lib/runtime/dart_runtime.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ var dart, _js_helper, _js_primitives;
240240
}
241241
dart.is = instanceOf;
242242

243+
function instanceOfOrNull(obj, type) {
244+
return (obj == null) || instanceOf(obj, type);
245+
}
246+
243247
/**
244248
* Computes the canonical type.
245249
* This maps JS types onto their corresponding Dart Type.
@@ -465,17 +469,15 @@ var dart, _js_helper, _js_primitives;
465469
if (actuals.length < this.args.length) return false;
466470
var index = 0;
467471
for(let i = 0; i < this.args.length; ++i) {
468-
let t = realRuntimeType(actuals[i]);
469-
if (!isSubtype(t, this.args[i])) return false;
472+
if (!instanceOfOrNull(actuals[i], this.args[i])) return false;
470473
++index;
471474
}
472475
if (actuals.length == this.args.length) return true;
473476
let extras = actuals.length - this.args.length;
474477
if (this.optionals.length > 0) {
475478
if (extras > this.optionals.length) return false;
476-
for(let i = 0; i < extras; ++i) {
477-
let t = realRuntimeType(actuals[index + i]);
478-
if (!isSubtype(t, this.optionals[i])) return false;
479+
for(let i = 0, j=index; i < extras; ++i, ++j) {
480+
if (!instanceOfOrNull(actuals[j], this.optionals[i])) return false;
479481
}
480482
return true;
481483
}
@@ -493,8 +495,7 @@ var dart, _js_helper, _js_primitives;
493495
if (!(Object.prototype.hasOwnProperty.call(this.named, name))) {
494496
return false;
495497
}
496-
let t = realRuntimeType(opts[name]);
497-
if (!isSubtype(t, this.named[name])) return false;
498+
if (!instanceOfOrNull(opts[name], this.named[name])) return false;
498499
}
499500
return true;
500501
}

test/browser/runtime_tests.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,27 +479,32 @@ suite('instanceOf', () => {
479479

480480
// Method send
481481
assert.equal(dart.dsend(o, 'm', 3, 4), 3);
482+
assert.equal(dart.dsend(o, 'm', null, 4), null);
482483
assert.throws(() => dart.dsend(o, 'm', 3));
483484
assert.throws(() => dart.dsend(o, 'm', "hello", "world"));
484485
assert.throws(() => dart.dsend(o, 'q', 3));
485486

486487
// Method send through a field
487488
assert.equal(dart.dsend(o, 'f', 3), 3);
489+
assert.equal(dart.dsend(o, 'f', null), null);
488490
assert.throws(() => dart.dsend(o, 'f', "hello"));
489491
assert.throws(() => dart.dsend(o, 'f', 3, 4));
490492

491493
// Static method call
492494
assert.equal(dart.dcall(Tester.s, "hello"), "hello");
495+
assert.equal(dart.dcall(Tester.s, null), null);
493496
assert.throws(() => dart.dcall(Tester.s, "hello", "world"));
494497
assert.throws(() => dart.dcall(Tester.s, 0, 1));
495498

496499
// Calling an object with a call method
497500
assert.equal(dart.dcall(o, 3), 3);
501+
assert.equal(dart.dcall(o, null), null);
498502
assert.throws(() => dart.dcall(o, "hello"));
499503
assert.throws(() => dart.dcall(o, 3, 4));
500504

501505
// Calling through a field containing an object with a call method
502506
assert.equal(dart.dsend(o, 'me', 3), 3);
507+
assert.equal(dart.dsend(o, 'me', null), null);
503508
assert.throws(() => dart.dsend(o, 'me', "hello"));
504509
assert.throws(() => dart.dsend(o, 'me', 3, 4));
505510
});

0 commit comments

Comments
 (0)