Skip to content

Commit

Permalink
Make is checks work on JavaScriptFunction objects.
Browse files Browse the repository at this point in the history
BUG=
R=sra@google.com

Review URL: https://codereview.chromium.org/2110273003 .
  • Loading branch information
jacob314 committed Jul 1, 2016
1 parent eb20b68 commit 595ec1d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/compiler/lib/src/js_backend/js_interop_analysis.dart
Expand Up @@ -8,6 +8,11 @@ library compiler.src.js_backend.js_interop_analysis;
import '../common.dart';
import '../constants/values.dart'
show ConstantValue, ConstructedConstantValue, StringConstantValue;
import '../dart_types.dart'
show
DartType,
DynamicType,
FunctionType;
import '../diagnostics/messages.dart' show MessageKind;
import '../elements/elements.dart'
show
Expand Down Expand Up @@ -185,4 +190,14 @@ class JsInteropAnalysis {
});
return new jsAst.Block(statements);
}

FunctionType buildJsFunctionType() {
// TODO(jacobr): consider using codegenWorld.isChecks to determine the
// range of positional arguments that need to be supported by JavaScript
// function types.
return new FunctionType.synthesized(
const DynamicType(),
[],
new List<DartType>.filled(16, const DynamicType()));
}
}
11 changes: 11 additions & 0 deletions pkg/compiler/lib/src/js_emitter/runtime_type_generator.dart
Expand Up @@ -132,6 +132,17 @@ class RuntimeTypeGenerator {
_generateIsTestsOn(classElement, generateIsTest,
generateFunctionTypeSignature, generateSubstitution, generateTypeCheck);

if (classElement == backend.helpers.jsJavaScriptFunctionClass) {
var type = backend.jsInteropAnalysis.buildJsFunctionType();
if (type != null) {
jsAst.Expression thisAccess = new jsAst.This();
RuntimeTypesEncoder rtiEncoder = backend.rtiEncoder;
jsAst.Expression encoding =
rtiEncoder.getSignatureEncoding(type, thisAccess);
jsAst.Name operatorSignature = namer.asName(namer.operatorSignature);
result.properties[operatorSignature] = encoding;
}
}
return result;
}

Expand Down
13 changes: 13 additions & 0 deletions tests/html/js_test.dart
Expand Up @@ -194,6 +194,8 @@ someObject.role = "object";
document.body.append(script);
}

typedef bool StringToBool(String s);

// Some test are either causing other test to fail in IE9, or they are failing
// for unknown reasons
// useHtmlConfiguration+ImageData bug: dartbug.com/14355
Expand Down Expand Up @@ -922,6 +924,17 @@ main() {

});

group('JavaScriptFunction', () {
test('is check', () {
var fn = (String s) => true;
var jsFn = allowInterop(fn);
expect(fn is StringToBool, isTrue);
expect(jsFn is StringToBool, isTrue);
expect(jsFn is Function, isTrue);
expect(jsFn is List, isFalse);
});
});

group('Dart->JS', () {

test('Date', () {
Expand Down

0 comments on commit 595ec1d

Please sign in to comment.