| OLD | NEW |
| 1 var _isolate_helper; | 1 var _isolate_helper; |
| 2 (function(exports) { | 2 (function(exports) { |
| 3 'use strict'; | 3 'use strict'; |
| 4 // Function _serializeMessage: (dynamic) → dynamic | 4 // Function _serializeMessage: (dynamic) → dynamic |
| 5 function _serializeMessage(message) { | 5 function _serializeMessage(message) { |
| 6 return new _Serializer().serialize(message); | 6 return new _Serializer().serialize(message); |
| 7 } | 7 } |
| 8 // Function _deserializeMessage: (dynamic) → dynamic | 8 // Function _deserializeMessage: (dynamic) → dynamic |
| 9 function _deserializeMessage(message) { | 9 function _deserializeMessage(message) { |
| 10 return new _Deserializer().deserialize(message); | 10 return new _Deserializer().deserialize(message); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 class _Serializer extends core.Object { | 24 class _Serializer extends core.Object { |
| 25 _Serializer(opts) { | 25 _Serializer(opts) { |
| 26 let serializeSendPorts = opts && 'serializeSendPorts' in opts ? opts.seria
lizeSendPorts : true; | 26 let serializeSendPorts = opts && 'serializeSendPorts' in opts ? opts.seria
lizeSendPorts : true; |
| 27 this.serializedObjectIds = new core.Map.identity(); | 27 this.serializedObjectIds = new core.Map.identity(); |
| 28 this[_serializeSendPorts] = dart.as(serializeSendPorts, core.bool); | 28 this[_serializeSendPorts] = dart.as(serializeSendPorts, core.bool); |
| 29 } | 29 } |
| 30 serialize(x) { | 30 serialize(x) { |
| 31 if (this.isPrimitive(x)) | 31 if (this.isPrimitive(x)) |
| 32 return this.serializePrimitive(x); | 32 return this.serializePrimitive(x); |
| 33 let serializationId = this.serializedObjectIds.get(x); | 33 let serializationId = this.serializedObjectIds.get(x); |
| 34 if (serializationId !== null) | 34 if (serializationId != null) |
| 35 return this.makeRef(serializationId); | 35 return this.makeRef(serializationId); |
| 36 serializationId = this.serializedObjectIds.length; | 36 serializationId = this.serializedObjectIds.length; |
| 37 this.serializedObjectIds.set(x, serializationId); | 37 this.serializedObjectIds.set(x, serializationId); |
| 38 if (dart.is(x, _native_typed_data.NativeByteBuffer)) | 38 if (dart.is(x, _native_typed_data.NativeByteBuffer)) |
| 39 return this.serializeByteBuffer(dart.as(x, _native_typed_data.NativeByte
Buffer)); | 39 return this.serializeByteBuffer(dart.as(x, _native_typed_data.NativeByte
Buffer)); |
| 40 if (dart.is(x, _native_typed_data.NativeTypedData)) | 40 if (dart.is(x, _native_typed_data.NativeTypedData)) |
| 41 return this.serializeTypedData(dart.as(x, _native_typed_data.NativeTyped
Data)); | 41 return this.serializeTypedData(dart.as(x, _native_typed_data.NativeTyped
Data)); |
| 42 if (dart.is(x, _interceptors.JSIndexable)) | 42 if (dart.is(x, _interceptors.JSIndexable)) |
| 43 return this.serializeJSIndexable(dart.as(x, _interceptors.JSIndexable)); | 43 return this.serializeJSIndexable(dart.as(x, _interceptors.JSIndexable)); |
| 44 if (dart.is(x, _js_helper.InternalMap)) | 44 if (dart.is(x, _js_helper.InternalMap)) |
| 45 return this.serializeMap(dart.as(x, core.Map)); | 45 return this.serializeMap(dart.as(x, core.Map)); |
| 46 if (dart.is(x, _interceptors.JSObject)) | 46 if (dart.is(x, _interceptors.JSObject)) |
| 47 return this.serializeJSObject(dart.as(x, _interceptors.JSObject)); | 47 return this.serializeJSObject(dart.as(x, _interceptors.JSObject)); |
| 48 if (dart.is(x, _interceptors.Interceptor)) | 48 if (dart.is(x, _interceptors.Interceptor)) |
| 49 this.unsupported(x); | 49 this.unsupported(x); |
| 50 if (dart.is(x, isolate.RawReceivePort)) { | 50 if (dart.is(x, isolate.RawReceivePort)) { |
| 51 this.unsupported(x, "RawReceivePorts can't be transmitted:"); | 51 this.unsupported(x, "RawReceivePorts can't be transmitted:"); |
| 52 } | 52 } |
| 53 if (dart.is(x, _NativeJsSendPort)) | 53 if (dart.is(x, _NativeJsSendPort)) |
| 54 return this.serializeJsSendPort(dart.as(x, _NativeJsSendPort)); | 54 return this.serializeJsSendPort(dart.as(x, _NativeJsSendPort)); |
| 55 if (dart.is(x, _WorkerSendPort)) | 55 if (dart.is(x, _WorkerSendPort)) |
| 56 return this.serializeWorkerSendPort(dart.as(x, _WorkerSendPort)); | 56 return this.serializeWorkerSendPort(dart.as(x, _WorkerSendPort)); |
| 57 if (dart.is(x, _js_helper.Closure)) | 57 if (dart.is(x, _js_helper.Closure)) |
| 58 return this.serializeClosure(dart.as(x, _js_helper.Closure)); | 58 return this.serializeClosure(dart.as(x, _js_helper.Closure)); |
| 59 return this.serializeDartObject(x); | 59 return this.serializeDartObject(x); |
| 60 } | 60 } |
| 61 unsupported(x, message) { | 61 unsupported(x, message) { |
| 62 if (message === void 0) | 62 if (message === void 0) |
| 63 message = null; | 63 message = null; |
| 64 if (message === null) | 64 if (message == null) |
| 65 message = "Can't transmit:"; | 65 message = "Can't transmit:"; |
| 66 throw new core.UnsupportedError(`${message} ${x}`); | 66 throw new core.UnsupportedError(`${message} ${x}`); |
| 67 } | 67 } |
| 68 makeRef(serializationId) { | 68 makeRef(serializationId) { |
| 69 return new core.List.from(["ref", serializationId]); | 69 return new core.List.from(["ref", serializationId]); |
| 70 } | 70 } |
| 71 isPrimitive(x) { | 71 isPrimitive(x) { |
| 72 return dart.notNull(x === null) || dart.notNull(typeof x == 'string') || d
art.notNull(dart.is(x, core.num)) || dart.notNull(typeof x == 'boolean'); | 72 return dart.notNull(x == null) || dart.notNull(typeof x == 'string') || da
rt.notNull(dart.is(x, core.num)) || dart.notNull(typeof x == 'boolean'); |
| 73 } | 73 } |
| 74 serializePrimitive(primitive) { | 74 serializePrimitive(primitive) { |
| 75 return primitive; | 75 return primitive; |
| 76 } | 76 } |
| 77 serializeByteBuffer(buffer) { | 77 serializeByteBuffer(buffer) { |
| 78 return new core.List.from(["buffer", buffer]); | 78 return new core.List.from(["buffer", buffer]); |
| 79 } | 79 } |
| 80 serializeTypedData(data) { | 80 serializeTypedData(data) { |
| 81 return new core.List.from(["typed", data]); | 81 return new core.List.from(["typed", data]); |
| 82 } | 82 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 let workerId = exports._globalState.currentManagerId; | 135 let workerId = exports._globalState.currentManagerId; |
| 136 return new core.List.from(['sendport', workerId, x[_isolateId], x[_recei
vePort][_id]]); | 136 return new core.List.from(['sendport', workerId, x[_isolateId], x[_recei
vePort][_id]]); |
| 137 } | 137 } |
| 138 return new core.List.from(['raw sendport', x]); | 138 return new core.List.from(['raw sendport', x]); |
| 139 } | 139 } |
| 140 serializeCapability(x) { | 140 serializeCapability(x) { |
| 141 return new core.List.from(['capability', x[_id]]); | 141 return new core.List.from(['capability', x[_id]]); |
| 142 } | 142 } |
| 143 serializeClosure(x) { | 143 serializeClosure(x) { |
| 144 let name = IsolateNatives._getJSFunctionName(x); | 144 let name = IsolateNatives._getJSFunctionName(x); |
| 145 if (name === null) { | 145 if (name == null) { |
| 146 this.unsupported(x, "Closures can't be transmitted:"); | 146 this.unsupported(x, "Closures can't be transmitted:"); |
| 147 } | 147 } |
| 148 return new core.List.from(['function', name]); | 148 return new core.List.from(['function', name]); |
| 149 } | 149 } |
| 150 serializeDartObject(x) { | 150 serializeDartObject(x) { |
| 151 let classExtractor = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_n
ames.CLASS_ID_EXTRACTOR); | 151 let classExtractor = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_n
ames.CLASS_ID_EXTRACTOR); |
| 152 let fieldsExtractor = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_
names.CLASS_FIELDS_EXTRACTOR); | 152 let fieldsExtractor = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_
names.CLASS_FIELDS_EXTRACTOR); |
| 153 let classId = classExtractor(x); | 153 let classId = classExtractor(x); |
| 154 let fields = dart.as(fieldsExtractor(x), core.List); | 154 let fields = dart.as(fieldsExtractor(x), core.List); |
| 155 return new core.List.from(['dart', classId, this.serializeArrayInPlace(dar
t.as(fields, _interceptors.JSArray))]); | 155 return new core.List.from(['dart', classId, this.serializeArrayInPlace(dar
t.as(fields, _interceptors.JSArray))]); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 { | 220 { |
| 221 return this.deserializeDartObject(x); | 221 return this.deserializeDartObject(x); |
| 222 } | 222 } |
| 223 default: | 223 default: |
| 224 { | 224 { |
| 225 throw `couldn't deserialize: ${x}`; | 225 throw `couldn't deserialize: ${x}`; |
| 226 } | 226 } |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 isPrimitive(x) { | 229 isPrimitive(x) { |
| 230 return dart.notNull(x === null) || dart.notNull(typeof x == 'string') || d
art.notNull(dart.is(x, core.num)) || dart.notNull(typeof x == 'boolean'); | 230 return dart.notNull(x == null) || dart.notNull(typeof x == 'string') || da
rt.notNull(dart.is(x, core.num)) || dart.notNull(typeof x == 'boolean'); |
| 231 } | 231 } |
| 232 deserializePrimitive(x) { | 232 deserializePrimitive(x) { |
| 233 return x; | 233 return x; |
| 234 } | 234 } |
| 235 deserializeRef(x) { | 235 deserializeRef(x) { |
| 236 dart.assert(dart.equals(dart.dindex(x, 0), 'ref')); | 236 dart.assert(dart.equals(dart.dindex(x, 0), 'ref')); |
| 237 let serializationId = dart.as(dart.dindex(x, 1), core.int); | 237 let serializationId = dart.as(dart.dindex(x, 1), core.int); |
| 238 return this.deserializedObjects.get(serializationId); | 238 return this.deserializedObjects.get(serializationId); |
| 239 } | 239 } |
| 240 deserializeByteBuffer(x) { | 240 deserializeByteBuffer(x) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 result.set(keys.get(i), this.deserialize(values.get(i))); | 290 result.set(keys.get(i), this.deserialize(values.get(i))); |
| 291 } | 291 } |
| 292 return result; | 292 return result; |
| 293 } | 293 } |
| 294 deserializeSendPort(x) { | 294 deserializeSendPort(x) { |
| 295 dart.assert(dart.equals(dart.dindex(x, 0), 'sendport')); | 295 dart.assert(dart.equals(dart.dindex(x, 0), 'sendport')); |
| 296 let managerId = dart.as(dart.dindex(x, 1), core.int); | 296 let managerId = dart.as(dart.dindex(x, 1), core.int); |
| 297 let isolateId = dart.as(dart.dindex(x, 2), core.int); | 297 let isolateId = dart.as(dart.dindex(x, 2), core.int); |
| 298 let receivePortId = dart.as(dart.dindex(x, 3), core.int); | 298 let receivePortId = dart.as(dart.dindex(x, 3), core.int); |
| 299 let result = null; | 299 let result = null; |
| 300 if (managerId === exports._globalState.currentManagerId) { | 300 if (managerId == exports._globalState.currentManagerId) { |
| 301 let isolate = exports._globalState.isolates.get(isolateId); | 301 let isolate = exports._globalState.isolates.get(isolateId); |
| 302 if (isolate === null) | 302 if (isolate == null) |
| 303 return null; | 303 return null; |
| 304 let receivePort = isolate.lookup(receivePortId); | 304 let receivePort = isolate.lookup(receivePortId); |
| 305 if (receivePort === null) | 305 if (receivePort == null) |
| 306 return null; | 306 return null; |
| 307 result = new _NativeJsSendPort(receivePort, isolateId); | 307 result = new _NativeJsSendPort(receivePort, isolateId); |
| 308 } else { | 308 } else { |
| 309 result = new _WorkerSendPort(managerId, isolateId, receivePortId); | 309 result = new _WorkerSendPort(managerId, isolateId, receivePortId); |
| 310 } | 310 } |
| 311 this.deserializedObjects.add(result); | 311 this.deserializedObjects.add(result); |
| 312 return result; | 312 return result; |
| 313 } | 313 } |
| 314 deserializeRawSendPort(x) { | 314 deserializeRawSendPort(x) { |
| 315 dart.assert(dart.equals(dart.dindex(x, 0), 'raw sendport')); | 315 dart.assert(dart.equals(dart.dindex(x, 0), 'raw sendport')); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 function isWorker() { | 367 function isWorker() { |
| 368 return exports._globalState.isWorker; | 368 return exports._globalState.isWorker; |
| 369 } | 369 } |
| 370 // Function _currentIsolate: () → _IsolateContext | 370 // Function _currentIsolate: () → _IsolateContext |
| 371 function _currentIsolate() { | 371 function _currentIsolate() { |
| 372 return exports._globalState.currentContext; | 372 return exports._globalState.currentContext; |
| 373 } | 373 } |
| 374 // Function startRootIsolate: (dynamic, dynamic) → void | 374 // Function startRootIsolate: (dynamic, dynamic) → void |
| 375 function startRootIsolate(entry, args) { | 375 function startRootIsolate(entry, args) { |
| 376 args = args; | 376 args = args; |
| 377 if (args === null) | 377 if (args == null) |
| 378 args = new core.List.from([]); | 378 args = new core.List.from([]); |
| 379 if (!dart.is(args, core.List)) { | 379 if (!dart.is(args, core.List)) { |
| 380 throw new core.ArgumentError(`Arguments to main must be a List: ${args}`); | 380 throw new core.ArgumentError(`Arguments to main must be a List: ${args}`); |
| 381 } | 381 } |
| 382 exports._globalState = new _Manager(dart.as(entry, core.Function)); | 382 exports._globalState = new _Manager(dart.as(entry, core.Function)); |
| 383 if (exports._globalState.isWorker) | 383 if (exports._globalState.isWorker) |
| 384 return; | 384 return; |
| 385 let rootContext = new _IsolateContext(); | 385 let rootContext = new _IsolateContext(); |
| 386 exports._globalState.rootContext = rootContext; | 386 exports._globalState.rootContext = rootContext; |
| 387 exports._globalState.currentContext = rootContext; | 387 exports._globalState.currentContext = rootContext; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 this[_nativeDetectEnvironment](); | 431 this[_nativeDetectEnvironment](); |
| 432 this.topEventLoop = new _EventLoop(); | 432 this.topEventLoop = new _EventLoop(); |
| 433 this.isolates = new core.Map(); | 433 this.isolates = new core.Map(); |
| 434 this.managers = new core.Map(); | 434 this.managers = new core.Map(); |
| 435 if (this.isWorker) { | 435 if (this.isWorker) { |
| 436 this.mainManager = new _MainManagerStub(); | 436 this.mainManager = new _MainManagerStub(); |
| 437 this[_nativeInitWorkerMessageHandler](); | 437 this[_nativeInitWorkerMessageHandler](); |
| 438 } | 438 } |
| 439 } | 439 } |
| 440 [_nativeDetectEnvironment]() { | 440 [_nativeDetectEnvironment]() { |
| 441 let isWindowDefined = exports.globalWindow !== null; | 441 let isWindowDefined = exports.globalWindow != null; |
| 442 let isWorkerDefined = exports.globalWorker !== null; | 442 let isWorkerDefined = exports.globalWorker != null; |
| 443 this.isWorker = !dart.notNull(isWindowDefined) && dart.notNull(exports.glo
balPostMessageDefined); | 443 this.isWorker = !dart.notNull(isWindowDefined) && dart.notNull(exports.glo
balPostMessageDefined); |
| 444 this.supportsWorkers = dart.notNull(this.isWorker) || dart.notNull(isWorke
rDefined) && dart.notNull(IsolateNatives.thisScript !== null); | 444 this.supportsWorkers = dart.notNull(this.isWorker) || dart.notNull(isWorke
rDefined) && dart.notNull(IsolateNatives.thisScript != null); |
| 445 this.fromCommandLine = !dart.notNull(isWindowDefined) && !dart.notNull(thi
s.isWorker); | 445 this.fromCommandLine = !dart.notNull(isWindowDefined) && !dart.notNull(thi
s.isWorker); |
| 446 } | 446 } |
| 447 [_nativeInitWorkerMessageHandler]() { | 447 [_nativeInitWorkerMessageHandler]() { |
| 448 let function$0 = function(f, a) { | 448 let function$0 = function(f, a) { |
| 449 return function(e) { | 449 return function(e) { |
| 450 f(a, e); | 450 f(a, e); |
| 451 }; | 451 }; |
| 452 }(_foreign_helper.DART_CLOSURE_TO_JS(IsolateNatives[_processWorkerMessage]
), this.mainManager); | 452 }(_foreign_helper.DART_CLOSURE_TO_JS(IsolateNatives[_processWorkerMessage]
), this.mainManager); |
| 453 self.onmessage = function$0; | 453 self.onmessage = function$0; |
| 454 self.dartPrint = self.dartPrint || function(serialize) { | 454 self.dartPrint = self.dartPrint || function(serialize) { |
| 455 return function(object) { | 455 return function(object) { |
| 456 if (self.console && self.console.log) { | 456 if (self.console && self.console.log) { |
| 457 self.console.log(object); | 457 self.console.log(object); |
| 458 } else { | 458 } else { |
| 459 self.postMessage(serialize(object)); | 459 self.postMessage(serialize(object)); |
| 460 } | 460 } |
| 461 }; | 461 }; |
| 462 }(_foreign_helper.DART_CLOSURE_TO_JS(_Manager[_serializePrintMessage])); | 462 }(_foreign_helper.DART_CLOSURE_TO_JS(_Manager[_serializePrintMessage])); |
| 463 } | 463 } |
| 464 static [_serializePrintMessage](object) { | 464 static [_serializePrintMessage](object) { |
| 465 return _serializeMessage(dart.map({command: "print", msg: object})); | 465 return _serializeMessage(dart.map({command: "print", msg: object})); |
| 466 } | 466 } |
| 467 maybeCloseWorker() { | 467 maybeCloseWorker() { |
| 468 if (dart.notNull(this.isWorker) && dart.notNull(this.isolates.isEmpty) &&
this.topEventLoop[_activeJsAsyncCount] === 0) { | 468 if (dart.notNull(this.isWorker) && dart.notNull(this.isolates.isEmpty) &&
this.topEventLoop[_activeJsAsyncCount] == 0) { |
| 469 this.mainManager.postMessage(_serializeMessage(dart.map({command: 'close
'}))); | 469 this.mainManager.postMessage(_serializeMessage(dart.map({command: 'close
'}))); |
| 470 } | 470 } |
| 471 } | 471 } |
| 472 } | 472 } |
| 473 let _controlPort = Symbol('_controlPort'); | 473 let _controlPort = Symbol('_controlPort'); |
| 474 let _scheduledControlEvents = Symbol('_scheduledControlEvents'); | 474 let _scheduledControlEvents = Symbol('_scheduledControlEvents'); |
| 475 let _isExecutingEvent = Symbol('_isExecutingEvent'); | 475 let _isExecutingEvent = Symbol('_isExecutingEvent'); |
| 476 let _updateGlobalState = Symbol('_updateGlobalState'); | 476 let _updateGlobalState = Symbol('_updateGlobalState'); |
| 477 let _setGlobals = Symbol('_setGlobals'); | 477 let _setGlobals = Symbol('_setGlobals'); |
| 478 let _addRegistration = Symbol('_addRegistration'); | 478 let _addRegistration = Symbol('_addRegistration'); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 if (this.pauseTokens.isEmpty) { | 511 if (this.pauseTokens.isEmpty) { |
| 512 while (this.delayedEvents.isNotEmpty) { | 512 while (this.delayedEvents.isNotEmpty) { |
| 513 let event = this.delayedEvents.removeLast(); | 513 let event = this.delayedEvents.removeLast(); |
| 514 exports._globalState.topEventLoop.prequeue(event); | 514 exports._globalState.topEventLoop.prequeue(event); |
| 515 } | 515 } |
| 516 this.isPaused = false; | 516 this.isPaused = false; |
| 517 } | 517 } |
| 518 this[_updateGlobalState](); | 518 this[_updateGlobalState](); |
| 519 } | 519 } |
| 520 addDoneListener(responsePort) { | 520 addDoneListener(responsePort) { |
| 521 if (this.doneHandlers === null) { | 521 if (this.doneHandlers == null) { |
| 522 this.doneHandlers = new core.List.from([]); | 522 this.doneHandlers = new core.List.from([]); |
| 523 } | 523 } |
| 524 if (dart.dinvoke(this.doneHandlers, 'contains', responsePort)) | 524 if (dart.dinvoke(this.doneHandlers, 'contains', responsePort)) |
| 525 return; | 525 return; |
| 526 dart.dinvoke(this.doneHandlers, 'add', responsePort); | 526 dart.dinvoke(this.doneHandlers, 'add', responsePort); |
| 527 } | 527 } |
| 528 removeDoneListener(responsePort) { | 528 removeDoneListener(responsePort) { |
| 529 if (this.doneHandlers === null) | 529 if (this.doneHandlers == null) |
| 530 return; | 530 return; |
| 531 dart.dinvoke(this.doneHandlers, 'remove', responsePort); | 531 dart.dinvoke(this.doneHandlers, 'remove', responsePort); |
| 532 } | 532 } |
| 533 setErrorsFatal(authentification, errorsAreFatal) { | 533 setErrorsFatal(authentification, errorsAreFatal) { |
| 534 if (!dart.equals(this.terminateCapability, authentification)) | 534 if (!dart.equals(this.terminateCapability, authentification)) |
| 535 return; | 535 return; |
| 536 this.errorsAreFatal = errorsAreFatal; | 536 this.errorsAreFatal = errorsAreFatal; |
| 537 } | 537 } |
| 538 handlePing(responsePort, pingType) { | 538 handlePing(responsePort, pingType) { |
| 539 if (pingType === isolate.Isolate.IMMEDIATE || pingType === isolate.Isolate
.BEFORE_NEXT_EVENT && !dart.notNull(this[_isExecutingEvent])) { | 539 if (pingType == isolate.Isolate.IMMEDIATE || pingType == isolate.Isolate.B
EFORE_NEXT_EVENT && !dart.notNull(this[_isExecutingEvent])) { |
| 540 responsePort.send(null); | 540 responsePort.send(null); |
| 541 return; | 541 return; |
| 542 } | 542 } |
| 543 // Function respond: () → void | 543 // Function respond: () → void |
| 544 function respond() { | 544 function respond() { |
| 545 responsePort.send(null); | 545 responsePort.send(null); |
| 546 } | 546 } |
| 547 if (pingType === isolate.Isolate.AS_EVENT) { | 547 if (pingType == isolate.Isolate.AS_EVENT) { |
| 548 exports._globalState.topEventLoop.enqueue(this, respond, "ping"); | 548 exports._globalState.topEventLoop.enqueue(this, respond, "ping"); |
| 549 return; | 549 return; |
| 550 } | 550 } |
| 551 dart.assert(pingType === isolate.Isolate.BEFORE_NEXT_EVENT); | 551 dart.assert(pingType == isolate.Isolate.BEFORE_NEXT_EVENT); |
| 552 if (this[_scheduledControlEvents] === null) { | 552 if (this[_scheduledControlEvents] == null) { |
| 553 this[_scheduledControlEvents] = new collection.Queue(); | 553 this[_scheduledControlEvents] = new collection.Queue(); |
| 554 } | 554 } |
| 555 dart.dinvoke(this[_scheduledControlEvents], 'addLast', respond); | 555 dart.dinvoke(this[_scheduledControlEvents], 'addLast', respond); |
| 556 } | 556 } |
| 557 handleKill(authentification, priority) { | 557 handleKill(authentification, priority) { |
| 558 if (!dart.equals(this.terminateCapability, authentification)) | 558 if (!dart.equals(this.terminateCapability, authentification)) |
| 559 return; | 559 return; |
| 560 if (priority === isolate.Isolate.IMMEDIATE || priority === isolate.Isolate
.BEFORE_NEXT_EVENT && !dart.notNull(this[_isExecutingEvent])) { | 560 if (priority == isolate.Isolate.IMMEDIATE || priority == isolate.Isolate.B
EFORE_NEXT_EVENT && !dart.notNull(this[_isExecutingEvent])) { |
| 561 this.kill(); | 561 this.kill(); |
| 562 return; | 562 return; |
| 563 } | 563 } |
| 564 if (priority === isolate.Isolate.AS_EVENT) { | 564 if (priority == isolate.Isolate.AS_EVENT) { |
| 565 exports._globalState.topEventLoop.enqueue(this, this.kill, "kill"); | 565 exports._globalState.topEventLoop.enqueue(this, this.kill, "kill"); |
| 566 return; | 566 return; |
| 567 } | 567 } |
| 568 dart.assert(priority === isolate.Isolate.BEFORE_NEXT_EVENT); | 568 dart.assert(priority == isolate.Isolate.BEFORE_NEXT_EVENT); |
| 569 if (this[_scheduledControlEvents] === null) { | 569 if (this[_scheduledControlEvents] == null) { |
| 570 this[_scheduledControlEvents] = new collection.Queue(); | 570 this[_scheduledControlEvents] = new collection.Queue(); |
| 571 } | 571 } |
| 572 dart.dinvoke(this[_scheduledControlEvents], 'addLast', this.kill); | 572 dart.dinvoke(this[_scheduledControlEvents], 'addLast', this.kill); |
| 573 } | 573 } |
| 574 addErrorListener(port) { | 574 addErrorListener(port) { |
| 575 this.errorPorts.add(port); | 575 this.errorPorts.add(port); |
| 576 } | 576 } |
| 577 removeErrorListener(port) { | 577 removeErrorListener(port) { |
| 578 this.errorPorts.remove(port); | 578 this.errorPorts.remove(port); |
| 579 } | 579 } |
| 580 handleUncaughtError(error, stackTrace) { | 580 handleUncaughtError(error, stackTrace) { |
| 581 if (this.errorPorts.isEmpty) { | 581 if (this.errorPorts.isEmpty) { |
| 582 if (dart.notNull(this.errorsAreFatal) && dart.notNull(core.identical(thi
s, exports._globalState.rootContext))) { | 582 if (dart.notNull(this.errorsAreFatal) && dart.notNull(core.identical(thi
s, exports._globalState.rootContext))) { |
| 583 return; | 583 return; |
| 584 } | 584 } |
| 585 if (self.console && self.console.error) { | 585 if (self.console && self.console.error) { |
| 586 self.console.error(error, stackTrace); | 586 self.console.error(error, stackTrace); |
| 587 } else { | 587 } else { |
| 588 core.print(error); | 588 core.print(error); |
| 589 if (stackTrace !== null) | 589 if (stackTrace != null) |
| 590 core.print(stackTrace); | 590 core.print(stackTrace); |
| 591 } | 591 } |
| 592 return; | 592 return; |
| 593 } | 593 } |
| 594 let message = new core.List(2); | 594 let message = new core.List(2); |
| 595 message.set(0, dart.dinvoke(error, 'toString')); | 595 message.set(0, dart.dinvoke(error, 'toString')); |
| 596 message.set(1, stackTrace === null ? null : stackTrace.toString()); | 596 message.set(1, stackTrace == null ? null : stackTrace.toString()); |
| 597 for (let port of this.errorPorts) | 597 for (let port of this.errorPorts) |
| 598 port.send(message); | 598 port.send(message); |
| 599 } | 599 } |
| 600 eval(code) { | 600 eval(code) { |
| 601 let old = exports._globalState.currentContext; | 601 let old = exports._globalState.currentContext; |
| 602 exports._globalState.currentContext = this; | 602 exports._globalState.currentContext = this; |
| 603 this._setGlobals(); | 603 this._setGlobals(); |
| 604 let result = null; | 604 let result = null; |
| 605 this[_isExecutingEvent] = true; | 605 this[_isExecutingEvent] = true; |
| 606 try { | 606 try { |
| 607 result = dart.dinvokef(code); | 607 result = dart.dinvokef(code); |
| 608 } catch (e) { | 608 } catch (e) { |
| 609 let s = dart.stackTrace(e); | 609 let s = dart.stackTrace(e); |
| 610 this.handleUncaughtError(e, s); | 610 this.handleUncaughtError(e, s); |
| 611 if (this.errorsAreFatal) { | 611 if (this.errorsAreFatal) { |
| 612 this.kill(); | 612 this.kill(); |
| 613 if (core.identical(this, exports._globalState.rootContext)) { | 613 if (core.identical(this, exports._globalState.rootContext)) { |
| 614 throw e; | 614 throw e; |
| 615 } | 615 } |
| 616 } | 616 } |
| 617 } | 617 } |
| 618 finally { | 618 finally { |
| 619 this[_isExecutingEvent] = false; | 619 this[_isExecutingEvent] = false; |
| 620 exports._globalState.currentContext = old; | 620 exports._globalState.currentContext = old; |
| 621 if (old !== null) | 621 if (old != null) |
| 622 old._setGlobals(); | 622 old._setGlobals(); |
| 623 if (this[_scheduledControlEvents] !== null) { | 623 if (this[_scheduledControlEvents] != null) { |
| 624 while (dart.dload(this[_scheduledControlEvents], 'isNotEmpty')) { | 624 while (dart.dload(this[_scheduledControlEvents], 'isNotEmpty')) { |
| 625 dart.dinvokef(dart.dinvoke(this[_scheduledControlEvents], 'removeFir
st')); | 625 dart.dinvokef(dart.dinvoke(this[_scheduledControlEvents], 'removeFir
st')); |
| 626 } | 626 } |
| 627 } | 627 } |
| 628 } | 628 } |
| 629 return result; | 629 return result; |
| 630 } | 630 } |
| 631 [_setGlobals]() { | 631 [_setGlobals]() { |
| 632 _foreign_helper.JS_SET_CURRENT_ISOLATE(this.isolateStatics); | 632 _foreign_helper.JS_SET_CURRENT_ISOLATE(this.isolateStatics); |
| 633 } | 633 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 this[_addRegistration](portId, port); | 699 this[_addRegistration](portId, port); |
| 700 } | 700 } |
| 701 [_updateGlobalState]() { | 701 [_updateGlobalState]() { |
| 702 if (dart.notNull(this.ports.length) - dart.notNull(this.weakPorts.length)
> 0 || dart.notNull(this.isPaused) || !dart.notNull(this.initialized)) { | 702 if (dart.notNull(this.ports.length) - dart.notNull(this.weakPorts.length)
> 0 || dart.notNull(this.isPaused) || !dart.notNull(this.initialized)) { |
| 703 exports._globalState.isolates.set(this.id, this); | 703 exports._globalState.isolates.set(this.id, this); |
| 704 } else { | 704 } else { |
| 705 this.kill(); | 705 this.kill(); |
| 706 } | 706 } |
| 707 } | 707 } |
| 708 kill() { | 708 kill() { |
| 709 if (this[_scheduledControlEvents] !== null) { | 709 if (this[_scheduledControlEvents] != null) { |
| 710 dart.dinvoke(this[_scheduledControlEvents], 'clear'); | 710 dart.dinvoke(this[_scheduledControlEvents], 'clear'); |
| 711 } | 711 } |
| 712 for (let port of this.ports.values) { | 712 for (let port of this.ports.values) { |
| 713 dart.dinvoke(port, '_close'); | 713 dart.dinvoke(port, '_close'); |
| 714 } | 714 } |
| 715 this.ports.clear(); | 715 this.ports.clear(); |
| 716 this.weakPorts.clear(); | 716 this.weakPorts.clear(); |
| 717 exports._globalState.isolates.remove(this.id); | 717 exports._globalState.isolates.remove(this.id); |
| 718 this.errorPorts.clear(); | 718 this.errorPorts.clear(); |
| 719 if (this.doneHandlers !== null) { | 719 if (this.doneHandlers != null) { |
| 720 for (let port of this.doneHandlers) { | 720 for (let port of this.doneHandlers) { |
| 721 port.send(null); | 721 port.send(null); |
| 722 } | 722 } |
| 723 this.doneHandlers = null; | 723 this.doneHandlers = null; |
| 724 } | 724 } |
| 725 } | 725 } |
| 726 unregister(portId) { | 726 unregister(portId) { |
| 727 this.ports.remove(portId); | 727 this.ports.remove(portId); |
| 728 this.weakPorts.remove(portId); | 728 this.weakPorts.remove(portId); |
| 729 this[_updateGlobalState](); | 729 this[_updateGlobalState](); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 740 } | 740 } |
| 741 prequeue(event) { | 741 prequeue(event) { |
| 742 this.events.addFirst(event); | 742 this.events.addFirst(event); |
| 743 } | 743 } |
| 744 dequeue() { | 744 dequeue() { |
| 745 if (this.events.isEmpty) | 745 if (this.events.isEmpty) |
| 746 return null; | 746 return null; |
| 747 return this.events.removeFirst(); | 747 return this.events.removeFirst(); |
| 748 } | 748 } |
| 749 checkOpenReceivePortsFromCommandLine() { | 749 checkOpenReceivePortsFromCommandLine() { |
| 750 if (dart.notNull(exports._globalState.rootContext !== null) && dart.notNul
l(exports._globalState.isolates.containsKey(exports._globalState.rootContext.id)
) && dart.notNull(exports._globalState.fromCommandLine) && dart.notNull(exports.
_globalState.rootContext.ports.isEmpty)) { | 750 if (dart.notNull(exports._globalState.rootContext != null) && dart.notNull
(exports._globalState.isolates.containsKey(exports._globalState.rootContext.id))
&& dart.notNull(exports._globalState.fromCommandLine) && dart.notNull(exports._
globalState.rootContext.ports.isEmpty)) { |
| 751 throw new core.Exception("Program exited with open ReceivePorts."); | 751 throw new core.Exception("Program exited with open ReceivePorts."); |
| 752 } | 752 } |
| 753 } | 753 } |
| 754 runIteration() { | 754 runIteration() { |
| 755 let event = this.dequeue(); | 755 let event = this.dequeue(); |
| 756 if (event === null) { | 756 if (event == null) { |
| 757 this.checkOpenReceivePortsFromCommandLine(); | 757 this.checkOpenReceivePortsFromCommandLine(); |
| 758 exports._globalState.maybeCloseWorker(); | 758 exports._globalState.maybeCloseWorker(); |
| 759 return false; | 759 return false; |
| 760 } | 760 } |
| 761 event.process(); | 761 event.process(); |
| 762 return true; | 762 return true; |
| 763 } | 763 } |
| 764 [_runHelper]() { | 764 [_runHelper]() { |
| 765 if (exports.globalWindow !== null) { | 765 if (exports.globalWindow != null) { |
| 766 // Function next: () → void | 766 // Function next: () → void |
| 767 function next() { | 767 function next() { |
| 768 if (!dart.notNull(this.runIteration())) | 768 if (!dart.notNull(this.runIteration())) |
| 769 return; | 769 return; |
| 770 async.Timer.run(next); | 770 async.Timer.run(next); |
| 771 } | 771 } |
| 772 next(); | 772 next(); |
| 773 } else { | 773 } else { |
| 774 while (this.runIteration()) { | 774 while (this.runIteration()) { |
| 775 } | 775 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 let _log = Symbol('_log'); | 831 let _log = Symbol('_log'); |
| 832 let _consoleLog = Symbol('_consoleLog'); | 832 let _consoleLog = Symbol('_consoleLog'); |
| 833 let _getJSFunctionName = Symbol('_getJSFunctionName'); | 833 let _getJSFunctionName = Symbol('_getJSFunctionName'); |
| 834 let _allocate = Symbol('_allocate'); | 834 let _allocate = Symbol('_allocate'); |
| 835 let _startWorker = Symbol('_startWorker'); | 835 let _startWorker = Symbol('_startWorker'); |
| 836 let _startNonWorker = Symbol('_startNonWorker'); | 836 let _startNonWorker = Symbol('_startNonWorker'); |
| 837 let _spawnWorker = Symbol('_spawnWorker'); | 837 let _spawnWorker = Symbol('_spawnWorker'); |
| 838 class IsolateNatives extends core.Object { | 838 class IsolateNatives extends core.Object { |
| 839 static computeThisScript() { | 839 static computeThisScript() { |
| 840 let currentScript = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_na
mes.CURRENT_SCRIPT); | 840 let currentScript = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_na
mes.CURRENT_SCRIPT); |
| 841 if (currentScript !== null) { | 841 if (currentScript != null) { |
| 842 return String(currentScript.src); | 842 return String(currentScript.src); |
| 843 } | 843 } |
| 844 if (_js_helper.Primitives.isD8) | 844 if (_js_helper.Primitives.isD8) |
| 845 return IsolateNatives.computeThisScriptD8(); | 845 return IsolateNatives.computeThisScriptD8(); |
| 846 if (_js_helper.Primitives.isJsshell) | 846 if (_js_helper.Primitives.isJsshell) |
| 847 return IsolateNatives.computeThisScriptJsshell(); | 847 return IsolateNatives.computeThisScriptJsshell(); |
| 848 if (exports._globalState.isWorker) | 848 if (exports._globalState.isWorker) |
| 849 return IsolateNatives.computeThisScriptFromTrace(); | 849 return IsolateNatives.computeThisScriptFromTrace(); |
| 850 return null; | 850 return null; |
| 851 } | 851 } |
| 852 static computeThisScriptJsshell() { | 852 static computeThisScriptJsshell() { |
| 853 return dart.as(thisFilename(), core.String); | 853 return dart.as(thisFilename(), core.String); |
| 854 } | 854 } |
| 855 static computeThisScriptD8() { | 855 static computeThisScriptD8() { |
| 856 return IsolateNatives.computeThisScriptFromTrace(); | 856 return IsolateNatives.computeThisScriptFromTrace(); |
| 857 } | 857 } |
| 858 static computeThisScriptFromTrace() { | 858 static computeThisScriptFromTrace() { |
| 859 let stack = new Error().stack; | 859 let stack = new Error().stack; |
| 860 if (stack === null) { | 860 if (stack == null) { |
| 861 stack = function() { | 861 stack = function() { |
| 862 try { | 862 try { |
| 863 throw new Error(); | 863 throw new Error(); |
| 864 } catch (e) { | 864 } catch (e) { |
| 865 return e.stack; | 865 return e.stack; |
| 866 } | 866 } |
| 867 | 867 |
| 868 }(); | 868 }(); |
| 869 if (stack === null) | 869 if (stack == null) |
| 870 throw new core.UnsupportedError('No stack trace'); | 870 throw new core.UnsupportedError('No stack trace'); |
| 871 } | 871 } |
| 872 let pattern = null, matches = null; | 872 let pattern = null, matches = null; |
| 873 pattern = new RegExp("^ *at [^(]*\\((.*):[0-9]*:[0-9]*\\)$", "m"); | 873 pattern = new RegExp("^ *at [^(]*\\((.*):[0-9]*:[0-9]*\\)$", "m"); |
| 874 matches = stack.match(pattern); | 874 matches = stack.match(pattern); |
| 875 if (matches !== null) | 875 if (matches != null) |
| 876 return matches[1]; | 876 return matches[1]; |
| 877 pattern = new RegExp("^[^@]*@(.*):[0-9]*$", "m"); | 877 pattern = new RegExp("^[^@]*@(.*):[0-9]*$", "m"); |
| 878 matches = stack.match(pattern); | 878 matches = stack.match(pattern); |
| 879 if (matches !== null) | 879 if (matches != null) |
| 880 return matches[1]; | 880 return matches[1]; |
| 881 throw new core.UnsupportedError(`Cannot extract URI from "${stack}"`); | 881 throw new core.UnsupportedError(`Cannot extract URI from "${stack}"`); |
| 882 } | 882 } |
| 883 static [_getEventData](e) { | 883 static [_getEventData](e) { |
| 884 return e.data; | 884 return e.data; |
| 885 } | 885 } |
| 886 static [_processWorkerMessage](sender, e) { | 886 static [_processWorkerMessage](sender, e) { |
| 887 let msg = _deserializeMessage(IsolateNatives[_getEventData](e)); | 887 let msg = _deserializeMessage(IsolateNatives[_getEventData](e)); |
| 888 switch (dart.dindex(msg, 'command')) { | 888 switch (dart.dindex(msg, 'command')) { |
| 889 case 'start': | 889 case 'start': |
| 890 { | 890 { |
| 891 exports._globalState.currentManagerId = dart.as(dart.dindex(msg, 'id')
, core.int); | 891 exports._globalState.currentManagerId = dart.as(dart.dindex(msg, 'id')
, core.int); |
| 892 let functionName = dart.as(dart.dindex(msg, 'functionName'), core.Stri
ng); | 892 let functionName = dart.as(dart.dindex(msg, 'functionName'), core.Stri
ng); |
| 893 let entryPoint = dart.as(functionName === null ? exports._globalState.
entry : IsolateNatives[_getJSFunctionFromName](functionName), core.Function); | 893 let entryPoint = dart.as(functionName == null ? exports._globalState.e
ntry : IsolateNatives[_getJSFunctionFromName](functionName), core.Function); |
| 894 let args = dart.dindex(msg, 'args'); | 894 let args = dart.dindex(msg, 'args'); |
| 895 let message = _deserializeMessage(dart.dindex(msg, 'msg')); | 895 let message = _deserializeMessage(dart.dindex(msg, 'msg')); |
| 896 let isSpawnUri = dart.dindex(msg, 'isSpawnUri'); | 896 let isSpawnUri = dart.dindex(msg, 'isSpawnUri'); |
| 897 let startPaused = dart.dindex(msg, 'startPaused'); | 897 let startPaused = dart.dindex(msg, 'startPaused'); |
| 898 let replyTo = _deserializeMessage(dart.dindex(msg, 'replyTo')); | 898 let replyTo = _deserializeMessage(dart.dindex(msg, 'replyTo')); |
| 899 let context = new _IsolateContext(); | 899 let context = new _IsolateContext(); |
| 900 exports._globalState.topEventLoop.enqueue(context, () => { | 900 exports._globalState.topEventLoop.enqueue(context, () => { |
| 901 IsolateNatives[_startIsolate](entryPoint, dart.as(args, core.List$(c
ore.String)), message, dart.as(isSpawnUri, core.bool), dart.as(startPaused, core
.bool), dart.as(replyTo, isolate.SendPort)); | 901 IsolateNatives[_startIsolate](entryPoint, dart.as(args, core.List$(c
ore.String)), message, dart.as(isSpawnUri, core.bool), dart.as(startPaused, core
.bool), dart.as(replyTo, isolate.SendPort)); |
| 902 }, 'worker-start'); | 902 }, 'worker-start'); |
| 903 exports._globalState.currentContext = context; | 903 exports._globalState.currentContext = context; |
| 904 exports._globalState.topEventLoop.run(); | 904 exports._globalState.topEventLoop.run(); |
| 905 break; | 905 break; |
| 906 } | 906 } |
| 907 case 'spawn-worker': | 907 case 'spawn-worker': |
| 908 { | 908 { |
| 909 if (IsolateNatives.enableSpawnWorker !== null) | 909 if (IsolateNatives.enableSpawnWorker != null) |
| 910 IsolateNatives.handleSpawnWorkerRequest(msg); | 910 IsolateNatives.handleSpawnWorkerRequest(msg); |
| 911 break; | 911 break; |
| 912 } | 912 } |
| 913 case 'message': | 913 case 'message': |
| 914 { | 914 { |
| 915 let port = dart.as(dart.dindex(msg, 'port'), isolate.SendPort); | 915 let port = dart.as(dart.dindex(msg, 'port'), isolate.SendPort); |
| 916 if (port !== null) { | 916 if (port != null) { |
| 917 dart.dinvoke(dart.dindex(msg, 'port'), 'send', dart.dindex(msg, 'msg
')); | 917 dart.dinvoke(dart.dindex(msg, 'port'), 'send', dart.dindex(msg, 'msg
')); |
| 918 } | 918 } |
| 919 exports._globalState.topEventLoop.run(); | 919 exports._globalState.topEventLoop.run(); |
| 920 break; | 920 break; |
| 921 } | 921 } |
| 922 case 'close': | 922 case 'close': |
| 923 { | 923 { |
| 924 exports._globalState.managers.remove(IsolateNatives.workerIds.get(send
er)); | 924 exports._globalState.managers.remove(IsolateNatives.workerIds.get(send
er)); |
| 925 sender.terminate(); | 925 sender.terminate(); |
| 926 exports._globalState.topEventLoop.run(); | 926 exports._globalState.topEventLoop.run(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 979 } | 979 } |
| 980 static [_getJSFunctionName](f) { | 980 static [_getJSFunctionName](f) { |
| 981 return dart.as(dart.is(f, _js_helper.Closure) ? f.$name : null, core.Strin
g); | 981 return dart.as(dart.is(f, _js_helper.Closure) ? f.$name : null, core.Strin
g); |
| 982 } | 982 } |
| 983 static [_allocate](ctor) { | 983 static [_allocate](ctor) { |
| 984 return new ctor(); | 984 return new ctor(); |
| 985 } | 985 } |
| 986 static spawnFunction(topLevelFunction, message, startPaused) { | 986 static spawnFunction(topLevelFunction, message, startPaused) { |
| 987 IsolateNatives.enableSpawnWorker = true; | 987 IsolateNatives.enableSpawnWorker = true; |
| 988 let name = IsolateNatives[_getJSFunctionName](topLevelFunction); | 988 let name = IsolateNatives[_getJSFunctionName](topLevelFunction); |
| 989 if (name === null) { | 989 if (name == null) { |
| 990 throw new core.UnsupportedError("only top-level functions can be spawned
."); | 990 throw new core.UnsupportedError("only top-level functions can be spawned
."); |
| 991 } | 991 } |
| 992 let isLight = false; | 992 let isLight = false; |
| 993 let isSpawnUri = false; | 993 let isSpawnUri = false; |
| 994 return IsolateNatives.spawn(name, null, null, message, isLight, isSpawnUri
, startPaused); | 994 return IsolateNatives.spawn(name, null, null, message, isLight, isSpawnUri
, startPaused); |
| 995 } | 995 } |
| 996 static spawnUri(uri, args, message, startPaused) { | 996 static spawnUri(uri, args, message, startPaused) { |
| 997 IsolateNatives.enableSpawnWorker = true; | 997 IsolateNatives.enableSpawnWorker = true; |
| 998 let isLight = false; | 998 let isLight = false; |
| 999 let isSpawnUri = true; | 999 let isSpawnUri = true; |
| 1000 return IsolateNatives.spawn(null, uri.toString(), args, message, isLight,
isSpawnUri, startPaused); | 1000 return IsolateNatives.spawn(null, uri.toString(), args, message, isLight,
isSpawnUri, startPaused); |
| 1001 } | 1001 } |
| 1002 static spawn(functionName, uri, args, message, isLight, isSpawnUri, startPau
sed) { | 1002 static spawn(functionName, uri, args, message, isLight, isSpawnUri, startPau
sed) { |
| 1003 if (dart.notNull(uri !== null) && dart.notNull(uri.endsWith(".dart"))) | 1003 if (dart.notNull(uri != null) && dart.notNull(uri.endsWith(".dart"))) |
| 1004 uri = ".js"; | 1004 uri = ".js"; |
| 1005 let port = new isolate.ReceivePort(); | 1005 let port = new isolate.ReceivePort(); |
| 1006 let completer = dart.as(new async.Completer(), async.Completer$(core.List)
); | 1006 let completer = dart.as(new async.Completer(), async.Completer$(core.List)
); |
| 1007 port.first.then(((msg) => { | 1007 port.first.then(((msg) => { |
| 1008 if (dart.equals(dart.dindex(msg, 0), _SPAWNED_SIGNAL)) { | 1008 if (dart.equals(dart.dindex(msg, 0), _SPAWNED_SIGNAL)) { |
| 1009 completer.complete(msg); | 1009 completer.complete(msg); |
| 1010 } else { | 1010 } else { |
| 1011 dart.assert(dart.equals(dart.dindex(msg, 0), _SPAWN_FAILED_SIGNAL)); | 1011 dart.assert(dart.equals(dart.dindex(msg, 0), _SPAWN_FAILED_SIGNAL)); |
| 1012 completer.completeError(dart.dindex(msg, 1)); | 1012 completer.completeError(dart.dindex(msg, 1)); |
| 1013 } | 1013 } |
| 1014 }).bind(this)); | 1014 }).bind(this)); |
| 1015 let signalReply = port.sendPort; | 1015 let signalReply = port.sendPort; |
| 1016 if (dart.notNull(exports._globalState.useWorkers) && !dart.notNull(isLight
)) { | 1016 if (dart.notNull(exports._globalState.useWorkers) && !dart.notNull(isLight
)) { |
| 1017 IsolateNatives[_startWorker](functionName, uri, args, message, isSpawnUr
i, startPaused, signalReply, ((message) => completer.completeError(message)).bin
d(this)); | 1017 IsolateNatives[_startWorker](functionName, uri, args, message, isSpawnUr
i, startPaused, signalReply, ((message) => completer.completeError(message)).bin
d(this)); |
| 1018 } else { | 1018 } else { |
| 1019 IsolateNatives[_startNonWorker](functionName, uri, args, message, isSpaw
nUri, startPaused, signalReply); | 1019 IsolateNatives[_startNonWorker](functionName, uri, args, message, isSpaw
nUri, startPaused, signalReply); |
| 1020 } | 1020 } |
| 1021 return completer.future; | 1021 return completer.future; |
| 1022 } | 1022 } |
| 1023 static [_startWorker](functionName, uri, args, message, isSpawnUri, startPau
sed, replyPort, onError) { | 1023 static [_startWorker](functionName, uri, args, message, isSpawnUri, startPau
sed, replyPort, onError) { |
| 1024 if (args !== null) | 1024 if (args != null) |
| 1025 args = new core.List.from(args); | 1025 args = new core.List.from(args); |
| 1026 if (exports._globalState.isWorker) { | 1026 if (exports._globalState.isWorker) { |
| 1027 exports._globalState.mainManager.postMessage(_serializeMessage(dart.map(
{command: 'spawn-worker', functionName: functionName, args: args, msg: message,
uri: uri, isSpawnUri: isSpawnUri, startPaused: startPaused, replyPort: replyPort
}))); | 1027 exports._globalState.mainManager.postMessage(_serializeMessage(dart.map(
{command: 'spawn-worker', functionName: functionName, args: args, msg: message,
uri: uri, isSpawnUri: isSpawnUri, startPaused: startPaused, replyPort: replyPort
}))); |
| 1028 } else { | 1028 } else { |
| 1029 IsolateNatives[_spawnWorker](functionName, uri, args, message, isSpawnUr
i, startPaused, replyPort, onError); | 1029 IsolateNatives[_spawnWorker](functionName, uri, args, message, isSpawnUr
i, startPaused, replyPort, onError); |
| 1030 } | 1030 } |
| 1031 } | 1031 } |
| 1032 static [_startNonWorker](functionName, uri, args, message, isSpawnUri, start
Paused, replyPort) { | 1032 static [_startNonWorker](functionName, uri, args, message, isSpawnUri, start
Paused, replyPort) { |
| 1033 if (uri !== null) { | 1033 if (uri != null) { |
| 1034 throw new core.UnsupportedError("Currently spawnUri is not supported wit
hout web workers."); | 1034 throw new core.UnsupportedError("Currently spawnUri is not supported wit
hout web workers."); |
| 1035 } | 1035 } |
| 1036 message = _clone(message); | 1036 message = _clone(message); |
| 1037 if (args !== null) | 1037 if (args != null) |
| 1038 args = new core.List.from(args); | 1038 args = new core.List.from(args); |
| 1039 exports._globalState.topEventLoop.enqueue(new _IsolateContext(), () => { | 1039 exports._globalState.topEventLoop.enqueue(new _IsolateContext(), () => { |
| 1040 let func = IsolateNatives[_getJSFunctionFromName](functionName); | 1040 let func = IsolateNatives[_getJSFunctionFromName](functionName); |
| 1041 IsolateNatives[_startIsolate](dart.as(func, core.Function), args, messag
e, isSpawnUri, startPaused, replyPort); | 1041 IsolateNatives[_startIsolate](dart.as(func, core.Function), args, messag
e, isSpawnUri, startPaused, replyPort); |
| 1042 }, 'nonworker start'); | 1042 }, 'nonworker start'); |
| 1043 } | 1043 } |
| 1044 static get currentIsolate() { | 1044 static get currentIsolate() { |
| 1045 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola
teContext); | 1045 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola
teContext); |
| 1046 return new isolate.Isolate(context.controlPort.sendPort, {pauseCapability:
context.pauseCapability, terminateCapability: context.terminateCapability}); | 1046 return new isolate.Isolate(context.controlPort.sendPort, {pauseCapability:
context.pauseCapability, terminateCapability: context.terminateCapability}); |
| 1047 } | 1047 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1063 } | 1063 } |
| 1064 } | 1064 } |
| 1065 if (startPaused) { | 1065 if (startPaused) { |
| 1066 context.addPause(context.pauseCapability, context.pauseCapability); | 1066 context.addPause(context.pauseCapability, context.pauseCapability); |
| 1067 exports._globalState.topEventLoop.enqueue(context, runStartFunction, 'st
art isolate'); | 1067 exports._globalState.topEventLoop.enqueue(context, runStartFunction, 'st
art isolate'); |
| 1068 } else { | 1068 } else { |
| 1069 runStartFunction(); | 1069 runStartFunction(); |
| 1070 } | 1070 } |
| 1071 } | 1071 } |
| 1072 static [_spawnWorker](functionName, uri, args, message, isSpawnUri, startPau
sed, replyPort, onError) { | 1072 static [_spawnWorker](functionName, uri, args, message, isSpawnUri, startPau
sed, replyPort, onError) { |
| 1073 if (uri === null) | 1073 if (uri == null) |
| 1074 uri = IsolateNatives.thisScript; | 1074 uri = IsolateNatives.thisScript; |
| 1075 let worker = new Worker(uri); | 1075 let worker = new Worker(uri); |
| 1076 let onerrorTrampoline = function(f, u, c) { | 1076 let onerrorTrampoline = function(f, u, c) { |
| 1077 return function(e) { | 1077 return function(e) { |
| 1078 return f(e, u, c); | 1078 return f(e, u, c); |
| 1079 }; | 1079 }; |
| 1080 }(_foreign_helper.DART_CLOSURE_TO_JS(IsolateNatives.workerOnError), uri, o
nError); | 1080 }(_foreign_helper.DART_CLOSURE_TO_JS(IsolateNatives.workerOnError), uri, o
nError); |
| 1081 worker.onerror = onerrorTrampoline; | 1081 worker.onerror = onerrorTrampoline; |
| 1082 let processWorkerMessageTrampoline = function(f, a) { | 1082 let processWorkerMessageTrampoline = function(f, a) { |
| 1083 return function(e) { | 1083 return function(e) { |
| 1084 e.onerror = null; | 1084 e.onerror = null; |
| 1085 return f(a, e); | 1085 return f(a, e); |
| 1086 }; | 1086 }; |
| 1087 }(_foreign_helper.DART_CLOSURE_TO_JS(IsolateNatives[_processWorkerMessage]
), worker); | 1087 }(_foreign_helper.DART_CLOSURE_TO_JS(IsolateNatives[_processWorkerMessage]
), worker); |
| 1088 worker.onmessage = processWorkerMessageTrampoline; | 1088 worker.onmessage = processWorkerMessageTrampoline; |
| 1089 let workerId = ((x$) => exports._globalState.nextManagerId = dart.notNull(
x$) + 1, x$).bind(this)(exports._globalState.nextManagerId); | 1089 let workerId = ((x$) => exports._globalState.nextManagerId = dart.notNull(
x$) + 1, x$).bind(this)(exports._globalState.nextManagerId); |
| 1090 IsolateNatives.workerIds.set(worker, workerId); | 1090 IsolateNatives.workerIds.set(worker, workerId); |
| 1091 exports._globalState.managers.set(workerId, worker); | 1091 exports._globalState.managers.set(workerId, worker); |
| 1092 worker.postMessage(_serializeMessage(dart.map({command: 'start', id: worke
rId, replyTo: _serializeMessage(replyPort), args: args, msg: _serializeMessage(m
essage), isSpawnUri: isSpawnUri, startPaused: startPaused, functionName: functio
nName}))); | 1092 worker.postMessage(_serializeMessage(dart.map({command: 'start', id: worke
rId, replyTo: _serializeMessage(replyPort), args: args, msg: _serializeMessage(m
essage), isSpawnUri: isSpawnUri, startPaused: startPaused, functionName: functio
nName}))); |
| 1093 } | 1093 } |
| 1094 static workerOnError(event, uri, onError) { | 1094 static workerOnError(event, uri, onError) { |
| 1095 event.preventDefault(); | 1095 event.preventDefault(); |
| 1096 let message = dart.as(event.message, core.String); | 1096 let message = dart.as(event.message, core.String); |
| 1097 if (message === null) { | 1097 if (message == null) { |
| 1098 message = `Error spawning worker for ${uri}`; | 1098 message = `Error spawning worker for ${uri}`; |
| 1099 } else { | 1099 } else { |
| 1100 message = `Error spawning worker for ${uri} (${message})`; | 1100 message = `Error spawning worker for ${uri} (${message})`; |
| 1101 } | 1101 } |
| 1102 onError(message); | 1102 onError(message); |
| 1103 return true; | 1103 return true; |
| 1104 } | 1104 } |
| 1105 } | 1105 } |
| 1106 IsolateNatives.enableSpawnWorker = null; | 1106 IsolateNatives.enableSpawnWorker = null; |
| 1107 dart.defineLazyProperties(IsolateNatives, { | 1107 dart.defineLazyProperties(IsolateNatives, { |
| 1108 get thisScript() { | 1108 get thisScript() { |
| 1109 return IsolateNatives.computeThisScript(); | 1109 return IsolateNatives.computeThisScript(); |
| 1110 }, | 1110 }, |
| 1111 set thisScript(_) {}, | 1111 set thisScript(_) {}, |
| 1112 get workerIds() { | 1112 get workerIds() { |
| 1113 return new core.Expando(); | 1113 return new core.Expando(); |
| 1114 } | 1114 } |
| 1115 }); | 1115 }); |
| 1116 let _checkReplyTo = Symbol('_checkReplyTo'); | 1116 let _checkReplyTo = Symbol('_checkReplyTo'); |
| 1117 class _BaseSendPort extends core.Object { | 1117 class _BaseSendPort extends core.Object { |
| 1118 _BaseSendPort(isolateId$) { | 1118 _BaseSendPort(isolateId$) { |
| 1119 this[_isolateId] = isolateId$; | 1119 this[_isolateId] = isolateId$; |
| 1120 } | 1120 } |
| 1121 [_checkReplyTo](replyTo) { | 1121 [_checkReplyTo](replyTo) { |
| 1122 if (dart.notNull(replyTo !== null) && dart.notNull(!dart.is(replyTo, _Nati
veJsSendPort)) && dart.notNull(!dart.is(replyTo, _WorkerSendPort))) { | 1122 if (dart.notNull(replyTo != null) && dart.notNull(!dart.is(replyTo, _Nativ
eJsSendPort)) && dart.notNull(!dart.is(replyTo, _WorkerSendPort))) { |
| 1123 throw new core.Exception("SendPort.send: Illegal replyTo port type"); | 1123 throw new core.Exception("SendPort.send: Illegal replyTo port type"); |
| 1124 } | 1124 } |
| 1125 } | 1125 } |
| 1126 } | 1126 } |
| 1127 let _isClosed = Symbol('_isClosed'); | 1127 let _isClosed = Symbol('_isClosed'); |
| 1128 class _NativeJsSendPort extends _BaseSendPort { | 1128 class _NativeJsSendPort extends _BaseSendPort { |
| 1129 _NativeJsSendPort(receivePort$, isolateId) { | 1129 _NativeJsSendPort(receivePort$, isolateId) { |
| 1130 this[_receivePort] = receivePort$; | 1130 this[_receivePort] = receivePort$; |
| 1131 super._BaseSendPort(isolateId); | 1131 super._BaseSendPort(isolateId); |
| 1132 } | 1132 } |
| 1133 send(message) { | 1133 send(message) { |
| 1134 let isolate = exports._globalState.isolates.get(this[_isolateId]); | 1134 let isolate = exports._globalState.isolates.get(this[_isolateId]); |
| 1135 if (isolate === null) | 1135 if (isolate == null) |
| 1136 return; | 1136 return; |
| 1137 if (this[_receivePort][_isClosed]) | 1137 if (this[_receivePort][_isClosed]) |
| 1138 return; | 1138 return; |
| 1139 let msg = _clone(message); | 1139 let msg = _clone(message); |
| 1140 if (dart.equals(isolate.controlPort, this[_receivePort])) { | 1140 if (dart.equals(isolate.controlPort, this[_receivePort])) { |
| 1141 isolate.handleControlMessage(msg); | 1141 isolate.handleControlMessage(msg); |
| 1142 return; | 1142 return; |
| 1143 } | 1143 } |
| 1144 exports._globalState.topEventLoop.enqueue(isolate, (() => { | 1144 exports._globalState.topEventLoop.enqueue(isolate, (() => { |
| 1145 if (!dart.notNull(this[_receivePort][_isClosed])) { | 1145 if (!dart.notNull(this[_receivePort][_isClosed])) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1159 this[_workerId] = workerId$; | 1159 this[_workerId] = workerId$; |
| 1160 this[_receivePortId] = receivePortId$; | 1160 this[_receivePortId] = receivePortId$; |
| 1161 super._BaseSendPort(isolateId); | 1161 super._BaseSendPort(isolateId); |
| 1162 } | 1162 } |
| 1163 send(message) { | 1163 send(message) { |
| 1164 let workerMessage = _serializeMessage(dart.map({command: 'message', port:
this, msg: message})); | 1164 let workerMessage = _serializeMessage(dart.map({command: 'message', port:
this, msg: message})); |
| 1165 if (exports._globalState.isWorker) { | 1165 if (exports._globalState.isWorker) { |
| 1166 exports._globalState.mainManager.postMessage(workerMessage); | 1166 exports._globalState.mainManager.postMessage(workerMessage); |
| 1167 } else { | 1167 } else { |
| 1168 let manager = exports._globalState.managers.get(this[_workerId]); | 1168 let manager = exports._globalState.managers.get(this[_workerId]); |
| 1169 if (manager !== null) { | 1169 if (manager != null) { |
| 1170 manager.postMessage(workerMessage); | 1170 manager.postMessage(workerMessage); |
| 1171 } | 1171 } |
| 1172 } | 1172 } |
| 1173 } | 1173 } |
| 1174 ['=='](other) { | 1174 ['=='](other) { |
| 1175 return dart.notNull(dart.is(other, _WorkerSendPort)) && this[_workerId] ==
= dart.dload(other, '_workerId') && this[_isolateId] === dart.dload(other, '_iso
lateId') && this[_receivePortId] === dart.dload(other, '_receivePortId'); | 1175 return dart.notNull(dart.is(other, _WorkerSendPort)) && dart.equals(this[_
workerId], dart.dload(other, '_workerId')) && dart.equals(this[_isolateId], dart
.dload(other, '_isolateId')) && dart.equals(this[_receivePortId], dart.dload(oth
er, '_receivePortId')); |
| 1176 } | 1176 } |
| 1177 get hashCode() { | 1177 get hashCode() { |
| 1178 return dart.notNull(this[_workerId]) << 16 ^ dart.notNull(this[_isolateId]
) << 8 ^ dart.notNull(this[_receivePortId]); | 1178 return dart.notNull(this[_workerId]) << 16 ^ dart.notNull(this[_isolateId]
) << 8 ^ dart.notNull(this[_receivePortId]); |
| 1179 } | 1179 } |
| 1180 } | 1180 } |
| 1181 let _handler = Symbol('_handler'); | 1181 let _handler = Symbol('_handler'); |
| 1182 let _nextFreeId = Symbol('_nextFreeId'); | 1182 let _nextFreeId = Symbol('_nextFreeId'); |
| 1183 let _close = Symbol('_close'); | 1183 let _close = Symbol('_close'); |
| 1184 let _add = Symbol('_add'); | 1184 let _add = Symbol('_add'); |
| 1185 class RawReceivePortImpl extends core.Object { | 1185 class RawReceivePortImpl extends core.Object { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1259 dart.defineNamedConstructor(ReceivePortImpl, 'weak'); | 1259 dart.defineNamedConstructor(ReceivePortImpl, 'weak'); |
| 1260 dart.defineNamedConstructor(ReceivePortImpl, 'fromRawReceivePort'); | 1260 dart.defineNamedConstructor(ReceivePortImpl, 'fromRawReceivePort'); |
| 1261 let _once = Symbol('_once'); | 1261 let _once = Symbol('_once'); |
| 1262 let _inEventLoop = Symbol('_inEventLoop'); | 1262 let _inEventLoop = Symbol('_inEventLoop'); |
| 1263 let _handle = Symbol('_handle'); | 1263 let _handle = Symbol('_handle'); |
| 1264 class TimerImpl extends core.Object { | 1264 class TimerImpl extends core.Object { |
| 1265 TimerImpl(milliseconds, callback) { | 1265 TimerImpl(milliseconds, callback) { |
| 1266 this[_once] = true; | 1266 this[_once] = true; |
| 1267 this[_inEventLoop] = false; | 1267 this[_inEventLoop] = false; |
| 1268 this[_handle] = null; | 1268 this[_handle] = null; |
| 1269 if (milliseconds === 0 && (!dart.notNull(hasTimer()) || dart.notNull(expor
ts._globalState.isWorker))) { | 1269 if (milliseconds == 0 && (!dart.notNull(hasTimer()) || dart.notNull(export
s._globalState.isWorker))) { |
| 1270 // Function internalCallback: () → void | 1270 // Function internalCallback: () → void |
| 1271 function internalCallback() { | 1271 function internalCallback() { |
| 1272 this[_handle] = null; | 1272 this[_handle] = null; |
| 1273 callback(); | 1273 callback(); |
| 1274 } | 1274 } |
| 1275 this[_handle] = 1; | 1275 this[_handle] = 1; |
| 1276 exports._globalState.topEventLoop.enqueue(exports._globalState.currentCo
ntext, internalCallback, 'timer'); | 1276 exports._globalState.topEventLoop.enqueue(exports._globalState.currentCo
ntext, internalCallback, 'timer'); |
| 1277 this[_inEventLoop] = true; | 1277 this[_inEventLoop] = true; |
| 1278 } else if (hasTimer()) { | 1278 } else if (hasTimer()) { |
| 1279 // Function internalCallback: () → void | 1279 // Function internalCallback: () → void |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1300 }).bind(this), 0), milliseconds); | 1300 }).bind(this), 0), milliseconds); |
| 1301 } else { | 1301 } else { |
| 1302 throw new core.UnsupportedError("Periodic timer."); | 1302 throw new core.UnsupportedError("Periodic timer."); |
| 1303 } | 1303 } |
| 1304 } | 1304 } |
| 1305 cancel() { | 1305 cancel() { |
| 1306 if (hasTimer()) { | 1306 if (hasTimer()) { |
| 1307 if (this[_inEventLoop]) { | 1307 if (this[_inEventLoop]) { |
| 1308 throw new core.UnsupportedError("Timer in event loop cannot be cancele
d."); | 1308 throw new core.UnsupportedError("Timer in event loop cannot be cancele
d."); |
| 1309 } | 1309 } |
| 1310 if (this[_handle] === null) | 1310 if (this[_handle] == null) |
| 1311 return; | 1311 return; |
| 1312 leaveJsAsync(); | 1312 leaveJsAsync(); |
| 1313 if (this[_once]) { | 1313 if (this[_once]) { |
| 1314 self.clearTimeout(this[_handle]); | 1314 self.clearTimeout(this[_handle]); |
| 1315 } else { | 1315 } else { |
| 1316 self.clearInterval(this[_handle]); | 1316 self.clearInterval(this[_handle]); |
| 1317 } | 1317 } |
| 1318 this[_handle] = null; | 1318 this[_handle] = null; |
| 1319 } else { | 1319 } else { |
| 1320 throw new core.UnsupportedError("Canceling a timer."); | 1320 throw new core.UnsupportedError("Canceling a timer."); |
| 1321 } | 1321 } |
| 1322 } | 1322 } |
| 1323 get isActive() { | 1323 get isActive() { |
| 1324 return this[_handle] !== null; | 1324 return this[_handle] != null; |
| 1325 } | 1325 } |
| 1326 } | 1326 } |
| 1327 dart.defineNamedConstructor(TimerImpl, 'periodic'); | 1327 dart.defineNamedConstructor(TimerImpl, 'periodic'); |
| 1328 // Function hasTimer: () → bool | 1328 // Function hasTimer: () → bool |
| 1329 function hasTimer() { | 1329 function hasTimer() { |
| 1330 _js_helper.requiresPreamble(); | 1330 _js_helper.requiresPreamble(); |
| 1331 return self.setTimeout !== null; | 1331 return self.setTimeout != null; |
| 1332 } | 1332 } |
| 1333 let _internal = Symbol('_internal'); | 1333 let _internal = Symbol('_internal'); |
| 1334 class CapabilityImpl extends core.Object { | 1334 class CapabilityImpl extends core.Object { |
| 1335 CapabilityImpl() { | 1335 CapabilityImpl() { |
| 1336 this[_internal](_js_helper.random64()); | 1336 this[_internal](_js_helper.random64()); |
| 1337 } | 1337 } |
| 1338 [_internal](id) { | 1338 [_internal](id) { |
| 1339 this[_id] = id; | 1339 this[_id] = id; |
| 1340 } | 1340 } |
| 1341 get hashCode() { | 1341 get hashCode() { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1364 exports.leaveJsAsync = leaveJsAsync; | 1364 exports.leaveJsAsync = leaveJsAsync; |
| 1365 exports.isWorker = isWorker; | 1365 exports.isWorker = isWorker; |
| 1366 exports.startRootIsolate = startRootIsolate; | 1366 exports.startRootIsolate = startRootIsolate; |
| 1367 exports.IsolateNatives = IsolateNatives; | 1367 exports.IsolateNatives = IsolateNatives; |
| 1368 exports.RawReceivePortImpl = RawReceivePortImpl; | 1368 exports.RawReceivePortImpl = RawReceivePortImpl; |
| 1369 exports.ReceivePortImpl = ReceivePortImpl; | 1369 exports.ReceivePortImpl = ReceivePortImpl; |
| 1370 exports.TimerImpl = TimerImpl; | 1370 exports.TimerImpl = TimerImpl; |
| 1371 exports.hasTimer = hasTimer; | 1371 exports.hasTimer = hasTimer; |
| 1372 exports.CapabilityImpl = CapabilityImpl; | 1372 exports.CapabilityImpl = CapabilityImpl; |
| 1373 })(_isolate_helper || (_isolate_helper = {})); | 1373 })(_isolate_helper || (_isolate_helper = {})); |
| OLD | NEW |