Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: tests/compiler/dart2js_native/dispatch_property_initialization_test.dart

Issue 2379173002: Add native_testing library to mock @Native classes (Closed)
Patch Set: xxx Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // Test for initialization of dispatchPropertyName. 5 // Test for initialization of dispatchPropertyName.
6 6
7 import "package:expect/expect.dart"; 7 import 'native_testing.dart';
8 import 'dart:_foreign_helper' show JS;
9 import 'dart:_js_helper' show Native;
10 8
11 @Native("Foo") 9 @Native("Foo")
12 class Foo { 10 class Foo {
13 String method(String x) native; 11 String method(String x) native;
14 } 12 }
15 13
16 makeFoo() native; 14 makeFoo() native;
17 15
18 void setup() native r""" 16 void setup() native r"""
19 function Foo() {} 17 function Foo() {}
20 Foo.prototype.method = function(x) { return 'Foo ' + x; } 18 Foo.prototype.method = function(x) { return 'Foo ' + x; }
21 19
22 self.makeFoo = function() { return new Foo(); } 20 self.makeFoo = function() { return new Foo(); }
21
22 self.nativeConstructor(Foo);
23 """; 23 """;
24 24
25 25
26 main() { 26 main() {
27 nativeTesting();
27 setup(); 28 setup();
28 29
29 // If the dispatchPropertyName is uninitialized, it will be `undefined` or 30 // If the dispatchPropertyName is uninitialized, it will be `undefined` or
30 // `null` instead of the secret string or Symbol. These properties on 31 // `null` instead of the secret string or Symbol. These properties on
31 // `Object.prototype` will be retrieved by the lookup instead of `undefined` 32 // `Object.prototype` will be retrieved by the lookup instead of `undefined`
32 // for the dispatch record. 33 // for the dispatch record.
33 JS('', r'self.Object.prototype["undefined"] = {}'); 34 JS('', r'self.Object.prototype["undefined"] = {}');
34 JS('', r'self.Object.prototype["null"] = {}'); 35 JS('', r'self.Object.prototype["null"] = {}');
35 Expect.equals('Foo A', makeFoo().method('A')); 36 Expect.equals('Foo A', makeFoo().method('A'));
36 37
37 // Slightly different version that has malformed dispatch records. 38 // Slightly different version that has malformed dispatch records.
38 JS('', r'self.Object.prototype["undefined"] = {p: false}'); 39 JS('', r'self.Object.prototype["undefined"] = {p: false}');
39 JS('', r'self.Object.prototype["null"] = {p: false}'); 40 JS('', r'self.Object.prototype["null"] = {p: false}');
40 Expect.equals('Foo B', makeFoo().method('B')); 41 Expect.equals('Foo B', makeFoo().method('B'));
41 } 42 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js_native/dart2js_native.status ('k') | tests/compiler/dart2js_native/downcast_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698