OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
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 | |
4 | |
5 #library('JsInteropObjInvokeTest'); | |
6 #import('../../pkg/unittest/unittest.dart'); | |
7 #import('../../pkg/unittest/html_config.dart'); | |
8 #import('dart:html'); | |
9 #import('dart:isolate'); | |
10 | |
11 injectSource(code) { | |
12 final script = new ScriptElement(); | |
13 script.type = 'text/javascript'; | |
14 script.innerHTML = code; | |
15 document.body.nodes.add(script); | |
16 } | |
17 | |
18 var jsProxyTest = """ | |
19 function TestType(x) { | |
20 this.x = x; | |
21 } | |
22 TestType.prototype.razzle = function () { | |
23 return this.x * 2; | |
24 } | |
25 var data = new TestType(21); | |
26 | |
27 var port = window.lookupPort('test1'); | |
28 port.callSync(data); | |
29 """; | |
30 | |
31 main() { | |
32 useHtmlConfiguration(); | |
33 | |
34 test('js-proxy', () { | |
35 int invoked = 0; | |
36 | |
37 var port = new ReceivePortSync(); | |
38 port.receive((data) { | |
39 expect(data.x, equals(21)); | |
40 expect(data.razzle(), equals(42)); | |
41 data.x = 100; | |
42 expect(data.razzle(), equals(200)); | |
43 | |
44 ++invoked; | |
45 }); | |
46 window.registerPort('test1', port.toSendPort()); | |
47 | |
48 injectSource(jsProxyTest); | |
49 expect(invoked, equals(1)); | |
50 }); | |
51 } | |
OLD | NEW |