Skip to content

Commit cc2f706

Browse files
author
John Messerly
committed
partial fix for #414, nSM message for dcall should show correct target
[email protected] Review URL: https://codereview.chromium.org/1601353002 .
1 parent 077465d commit cc2f706

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

pkg/dev_compiler/lib/runtime/dart/_operations.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ dart_library.library('dart/_operations', null, /* Imports */[
103103
}
104104

105105
function checkAndCall(f, ftype, obj, args, name) {
106+
let originalFunction = f;
106107
if (!(f instanceof Function)) {
107108
// We're not a function (and hence not a method either)
108109
// Grab the `call` method if it's not a function.
@@ -111,7 +112,7 @@ dart_library.library('dart/_operations', null, /* Imports */[
111112
f = f.call;
112113
}
113114
if (!(f instanceof Function)) {
114-
throwNoSuchMethod(obj, name, args);
115+
throwNoSuchMethod(obj, name, args, originalFunction);
115116
}
116117
}
117118
// If f is a function, but not a method (no method type)
@@ -133,7 +134,7 @@ dart_library.library('dart/_operations', null, /* Imports */[
133134

134135
// TODO(leafp): throw a type error (rather than NSM)
135136
// if the arity matches but the types are wrong.
136-
throwNoSuchMethod(obj, name, args, f);
137+
throwNoSuchMethod(obj, name, args, originalFunction);
137138
}
138139

139140
function dcall(f, ...args) {

pkg/dev_compiler/test/browser/runtime_tests.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ suite('generic', () => {
2424
assert.throws(() => { generic(function(){}); });
2525
});
2626

27+
test('dcall noSuchMethod has correct error target', () => {
28+
assert.throws(() => dart.dcall(42),
29+
new RegExp('NoSuchMethodError.*\nReceiver: 42', 'm'),
30+
'Calls with non-function receiver should throw a NoSuchMethodError' +
31+
' with correct target');
32+
33+
// TODO(jmesserly): we should show the name "print" in there somewhere.
34+
assert.throws(() => dart.dcall(core.print, 1, 2, 3),
35+
new RegExp('NoSuchMethodError.*\n' +
36+
"Receiver: Instance of '\\(Object\\) -> void'", 'm'),
37+
'Calls with incorrect argument types should throw a NoSuchMethodError' +
38+
' with correct target');
39+
});
40+
2741
test('can throw number', () => {
2842
try {
2943
dart.throw(42);

0 commit comments

Comments
 (0)