Skip to content

Commit

Permalink
fixes #168, dart:js implementation with a test
Browse files Browse the repository at this point in the history
R=vsm@google.com

Review URL: https://codereview.chromium.org/1200233004.
  • Loading branch information
John Messerly committed Jun 25, 2015
1 parent 53345a6 commit c2e65df
Show file tree
Hide file tree
Showing 24 changed files with 1,504 additions and 470 deletions.
4 changes: 2 additions & 2 deletions pkg/dev_compiler/lib/runtime/_operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dart_library.library('dart_runtime/_operations', null, /* Imports */[
const slice = [].slice;

function _canonicalFieldName(obj, name, args, displayName) {
name = classes.canonicalMember(obj, name)
name = classes.canonicalMember(obj, name);
if (name) return name;
// TODO(jmesserly): in the future we might have types that "overlay" Dart
// methods while also exposing the full native API, e.g. dart:html vs
Expand Down Expand Up @@ -112,7 +112,7 @@ dart_library.library('dart_runtime/_operations', null, /* Imports */[
if (!(f instanceof Function)) {
// We're not a function (and hence not a method either)
// Grab the `call` method if it's not a function.
if (f !== null) {
if (f != null) {
ftype = classes.getMethodType(f, 'call');
f = f.call;
}
Expand Down
8 changes: 0 additions & 8 deletions pkg/dev_compiler/lib/runtime/dart/_foreign_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ dart_library.library('dart/_foreign_helper', null, /* Imports */[
function JS_CALL_IN_ISOLATE(isolate, func) {
}
dart.fn(JS_CALL_IN_ISOLATE, dart.dynamic, [dart.dynamic, core.Function]);
function DART_CLOSURE_TO_JS(func) {
}
dart.fn(DART_CLOSURE_TO_JS, dart.dynamic, [core.Function]);
function RAW_DART_FUNCTION_REF(func) {
}
dart.fn(RAW_DART_FUNCTION_REF, dart.dynamic, [core.Function]);
function JS_SET_CURRENT_ISOLATE(isolate) {
}
dart.fn(JS_SET_CURRENT_ISOLATE, dart.void, [dart.dynamic]);
Expand Down Expand Up @@ -132,8 +126,6 @@ dart_library.library('dart/_foreign_helper', null, /* Imports */[
exports.JS_CURRENT_ISOLATE_CONTEXT = JS_CURRENT_ISOLATE_CONTEXT;
exports.IsolateContext = IsolateContext;
exports.JS_CALL_IN_ISOLATE = JS_CALL_IN_ISOLATE;
exports.DART_CLOSURE_TO_JS = DART_CLOSURE_TO_JS;
exports.RAW_DART_FUNCTION_REF = RAW_DART_FUNCTION_REF;
exports.JS_SET_CURRENT_ISOLATE = JS_SET_CURRENT_ISOLATE;
exports.JS_CREATE_ISOLATE = JS_CREATE_ISOLATE;
exports.JS_DART_OBJECT_CONSTRUCTOR = JS_DART_OBJECT_CONSTRUCTOR;
Expand Down
14 changes: 7 additions & 7 deletions pkg/dev_compiler/lib/runtime/dart/_isolate_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ dart_library.library('dart/_isolate_helper', null, /* Imports */[
return function(e) {
f(a, e);
};
}(_foreign_helper.DART_CLOSURE_TO_JS(IsolateNatives._processWorkerMessage), this.mainManager);
}(IsolateNatives._processWorkerMessage, this.mainManager);
self.onmessage = func;
self.dartPrint = self.dartPrint || function(serialize) {
return function(object) {
Expand All @@ -516,7 +516,7 @@ dart_library.library('dart/_isolate_helper', null, /* Imports */[
self.postMessage(serialize(object));
}
};
}(_foreign_helper.DART_CLOSURE_TO_JS(_Manager._serializePrintMessage));
}(_Manager._serializePrintMessage);
}
static _serializePrintMessage(object) {
return _serializeMessage(dart.map({command: "print", msg: object}));
Expand Down Expand Up @@ -1180,14 +1180,14 @@ dart_library.library('dart/_isolate_helper', null, /* Imports */[
return function(e) {
return f(e, u, c);
};
}(_foreign_helper.DART_CLOSURE_TO_JS(IsolateNatives.workerOnError), uri, onError);
}(IsolateNatives.workerOnError, uri, onError);
worker.onerror = onerrorTrampoline;
let processWorkerMessageTrampoline = function(f, a) {
return function(e) {
e.onerror = null;
return f(a, e);
};
}(_foreign_helper.DART_CLOSURE_TO_JS(IsolateNatives._processWorkerMessage), worker);
}(IsolateNatives._processWorkerMessage, worker);
worker.onmessage = processWorkerMessageTrampoline;
let o = exports._globalState;
let workerId = o.nextManagerId;
Expand Down Expand Up @@ -1459,7 +1459,7 @@ dart_library.library('dart/_isolate_helper', null, /* Imports */[
};
dart.fn(internalCallback, dart.void, []);
enterJsAsync();
this[_handle] = self.setTimeout(_js_helper.convertDartClosureToJS(internalCallback, 0), milliseconds);
this[_handle] = self.setTimeout(internalCallback, milliseconds);
} else {
dart.assert(dart.notNull(milliseconds) > 0);
throw new core.UnsupportedError("Timer greater than 0.");
Expand All @@ -1471,9 +1471,9 @@ dart_library.library('dart/_isolate_helper', null, /* Imports */[
this[_handle] = null;
if (dart.notNull(hasTimer())) {
enterJsAsync();
this[_handle] = self.setInterval(_js_helper.convertDartClosureToJS(dart.fn(() => {
this[_handle] = self.setInterval(dart.fn(() => {
callback(this);
}), 0), milliseconds);
}), milliseconds);
} else {
throw new core.UnsupportedError("Periodic timer.");
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/dev_compiler/lib/runtime/dart/_js_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1033,10 +1033,6 @@ dart_library.library('dart/_js_helper', null, /* Imports */[
return result;
}
dart.fn(fillLiteralMap, dart.dynamic, [dart.dynamic, core.Map]);
function convertDartClosureToJS(closure, arity) {
return closure;
}
dart.fn(convertDartClosureToJS, dart.dynamic, [dart.dynamic, core.int]);
function jsHasOwnProperty(jsObject, property) {
return jsObject.hasOwnProperty(property);
}
Expand Down Expand Up @@ -1187,7 +1183,6 @@ dart_library.library('dart/_js_helper', null, /* Imports */[
exports.getTraceFromException = getTraceFromException;
exports.objectHashCode = objectHashCode;
exports.fillLiteralMap = fillLiteralMap;
exports.convertDartClosureToJS = convertDartClosureToJS;
exports.jsHasOwnProperty = jsHasOwnProperty;
exports.jsPropertyAccess = jsPropertyAccess;
exports.getFallThroughError = getFallThroughError;
Expand Down
11 changes: 5 additions & 6 deletions pkg/dev_compiler/lib/runtime/dart/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ dart_library.library('dart/async', null, /* Imports */[
'dart/_internal',
'dart/collection'
], /* Lazy imports */[
'dart/_isolate_helper',
'dart/_js_helper'
], function(exports, dart, core, _internal, collection, _isolate_helper, _js_helper) {
'dart/_isolate_helper'
], function(exports, dart, core, _internal, collection, _isolate_helper) {
'use strict';
let dartx = dart.dartx;
function _invokeErrorHandler(errorHandler, error, stackTrace) {
Expand Down Expand Up @@ -2788,7 +2787,7 @@ dart_library.library('dart/async', null, /* Imports */[
};
dart.fn(internalCallback);
;
let observer = new self.MutationObserver(_js_helper.convertDartClosureToJS(internalCallback, 1));
let observer = new self.MutationObserver(internalCallback);
observer.observe(div, {childList: true});
return dart.fn(callback => {
dart.assert(storedCallback == null);
Expand All @@ -2809,7 +2808,7 @@ dart_library.library('dart/async', null, /* Imports */[
dart.fn(internalCallback);
;
_isolate_helper.enterJsAsync();
self.scheduleImmediate(_js_helper.convertDartClosureToJS(internalCallback, 0));
self.scheduleImmediate(internalCallback);
}
static _scheduleImmediateWithSetImmediate(callback) {
let internalCallback = () => {
Expand All @@ -2819,7 +2818,7 @@ dart_library.library('dart/async', null, /* Imports */[
dart.fn(internalCallback);
;
_isolate_helper.enterJsAsync();
self.setImmediate(_js_helper.convertDartClosureToJS(internalCallback, 0));
self.setImmediate(internalCallback);
}
static _scheduleImmediateWithTimer(callback) {
Timer._createTimer(core.Duration.ZERO, callback);
Expand Down
Loading

0 comments on commit c2e65df

Please sign in to comment.