dart2js js代码`undefined不是函数`

时间:2014-05-13 14:24:52

标签: dart dart2js

我正在尝试在javascript中编译我的项目。

编译有效,但在浏览器(chrome)中我有:

Uncaught TypeError: undefined is not a function client.dart.js:14753
J.get$length$asx client.dart.js:14753
InputStream.InputStream$4$byteOrder$length$start input_stream.dart:19
InputStream.static.InputStream$ input_stream.dart:17
DartAgnanAsk__get_data_closure.call$1 bzip2_decoder.dart:9
invokeClosure_closure0.call$0 js_helper.dart:1822
_IsolateContext.eval$1 isolate_helper.dart:355
_callInIsolate isolate_helper.dart:30
invokeClosure js_helper.dart:1822
(anonymous function)

编译我使用此命令:

dart2js -v --out=client.dart.js main.dart

dart2js -v --analyze-all --out=client.dart.js main.dart给出:

Info: Option '--analyze-all' implies '--analyze-only'.
Info: Options [--out=client.dart.js] indicate that output is expected, but compilation is turned off by the option '--analyze-only'.
Info: Package root is file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Documents/GitHub/DartAgnan/web/dart/packages/
Info: Allowed library categories: {Client, Shared, Internal}
Info: Scanning library dart:_js_helper (file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Dart/Dart tools/dart/dart-sdk/lib/_internal/lib/js_helper.dart)
Info: Scanning library dart:core (file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Dart/Dart tools/dart/dart-sdk/lib/core/core.dart)
Info: Scanning library dart:_internal (file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Dart/Dart tools/dart/dart-sdk/lib/internal/internal.dart)
Info: Scanning library dart:_js_primitives (file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Dart/Dart tools/dart/dart-sdk/lib/_internal/lib/js_primitives.dart)
Info: Scanning library dart:_foreign_helper (file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Dart/Dart tools/dart/dart-sdk/lib/_internal/lib/foreign_helper.dart)
Info: Scanning library dart:_interceptors (file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Dart/Dart tools/dart/dart-sdk/lib/_internal/lib/interceptors.dart)
Info: Scanning library dart:collection (file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Dart/Dart tools/dart/dart-sdk/lib/collection/collection.dart)
Info: Scanning library dart:math (file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Dart/Dart tools/dart/dart-sdk/lib/math/math.dart)
Info: Scanning library dart:convert (file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Dart/Dart tools/dart/dart-sdk/lib/convert/convert.dart)
Info: Scanning library dart:async (file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Dart/Dart tools/dart/dart-sdk/lib/async/async.dart)
Info: Scanning library dart:_isolate_helper (file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Dart/Dart tools/dart/dart-sdk/lib/_internal/lib/isolate_helper.dart)
Info: Scanning library dart:isolate (file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Dart/Dart tools/dart/dart-sdk/lib/isolate/isolate.dart)
Info: Scanning library dart:_js_names (file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Dart/Dart tools/dart/dart-sdk/lib/_internal/lib/js_names.dart)
Info: Analyzing file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Documents/GitHub/DartAgnan/web/dart/main.dart (1.3.6)
Info: Scanning library file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Documents/GitHub/DartAgnan/web/dart/main.dart
Info: Scanning library package:route_hierarchical/client.dart
Info: Scanning library dart:html (file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Dart/Dart tools/dart/dart-sdk/lib/html/dart2js/html_dart2js.dart)
Info: Scanning library dart:html_common (file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Dart/Dart tools/dart/dart-sdk/lib/html/html_common/html_common_dart2js.dart)
Info: Scanning library dart:web_gl (file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Dart/Dart tools/dart/dart-sdk/lib/web_gl/dart2js/web_gl_dart2js.dart)
Info: Scanning library dart:_native_typed_data (file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Dart/Dart tools/dart/dart-sdk/lib/typed_data/dart2js/native_typed_data_dart2js.dart)
Info: Scanning library dart:typed_data (file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Dart/Dart tools/dart/dart-sdk/lib/typed_data/dart2js/typed_data_dart2js.dart)
Info: Scanning library file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Dart/Dart tools/dart/dart-sdk/lib/html/html_common/metadata.dart
Info: Scanning library dart:indexed_db (file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Dart/Dart tools/dart/dart-sdk/lib/indexed_db/dart2js/indexed_db_dart2js.dart)
Info: Scanning library dart:svg (file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Dart/Dart tools/dart/dart-sdk/lib/svg/dart2js/svg_dart2js.dart)
Info: Scanning library dart:web_audio (file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Dart/Dart tools/dart/dart-sdk/lib/web_audio/dart2js/web_audio_dart2js.dart)
Info: Scanning library dart:web_sql (file:///Volumes/Data/nfs/zfs-student-4/users/2013/tcaron/Dart/Dart tools/dart/dart-sdk/lib/web_sql/dart2js/web_sql_dart2js.dart)
Info: Scanning library package:logging/logging.dart
Info: Scanning library package:collection/wrappers.dart
Info: Scanning library package:route_hierarchical/src/utils.dart
Info: Scanning library package:route_hierarchical/link_matcher.dart
Info: Scanning library package:route_hierarchical/click_handler.dart
Info: Scanning library package:route_hierarchical/url_matcher.dart
Info: Scanning library package:route_hierarchical/url_template.dart
Info: Scanning library package:DartAgnan/module/initMod.dart
Info: Scanning library package:DartAgnan/module/home/controller/homeCtrl.dart
Info: Scanning library package:DartAgnan/module/ask/controller/DartAgnanAsk.dart
Info: Scanning library package:archive/archive.dart
Info: Scanning library package:crypto/crypto.dart
Info: Resolving...
Info: Resolved 1495 elements.
Info: Resolved 4746 elements.
Info: Preserving names.
Info: Resolved 14467 elements.
Info: Resolved 50 native elements used, 531 native elements dead.
Hint: 1 warning(s) suppressed in package:route_hierarchical.
Info: LibraryLoader took 63msec
Info: Scanner took 195msec
Info: Diet Parser took 115msec
Info: Parser took 607msec
Info: Patching Parser took 16msec
Info: Resolver took 2402msec
Info: Closure Simplifier took 0msec
Info: Type checker took 346msec
Info: IR builder took 0msec
Info: Type inference took 0msec
Info: ConstantHandler took 393msec
Info: Deferred Loading took 0msec
Info: Unknown task took 0msec
Info: Enqueue took 283msec
Info: Dump Info took 0msec
Info: SSA builder took 0msec
Info: SSA optimizer took 0msec
Info: SSA code generator took 0msec
Info: CodeEmitter took 0msec
Info: Total compile-time 4978msec; unaccounted 558msec

当我使用pub build --mode=debug时:

Loading source assets...
Building DartAgnan...
[Info from Dart2JS]:
Compiling DartAgnan|web/dart/main.dart...
[Dart2JS on DartAgnan|web/dart/main.dart]:
1 warning(s) suppressed in package:route_hierarchical.
[Info from Dart2JS]:
Took 0:00:10.001875 to compile DartAgnan|web/dart/main.dart.
Built 514 files to "build".

你知道我的错误在哪里吗?或者有一个更明确的调试命令? 谢谢。

1 个答案:

答案 0 :(得分:1)

我在服务器端使用过这些:

_ws.binaryType = 'arraybyte';
...
_ws.onMessage.listen((MessageEvent data) {
            var response = JSON.decode(new String.fromCharCodes(new BZip2Decoder().decodeBytes(data.data)));
            _sender_list[response['ws_id']].add(response);
            if (response['status'] != 1) {
                _sender_list[response['ws_id']].close();
            }
}

在没有编译到JS的情况下运行良好。通过编译,我们得到指出的错误。

该解决方案直接使用Blob。

//_ws.binaryType = 'arraybyte';
...
_ws.onMessage.listen((MessageEvent data) {
  FileReader reader = new FileReader();

  reader.onLoadEnd.listen((ProgressEvent event) {
    var response = JSON.decode(new String.fromCharCodes(new BZip2Decoder().decodeBytes(reader.result)));
        _sender_list[response['ws_id']].add(response);
          if (response['status'] != 1) {
            _sender_list[response['ws_id']].close();
        }
  });
  reader.readAsArrayBuffer(data.data);
});

现在,编译效果很好。