whalesong/js-assembler/runtime-src/baselib-ports.js
2011-08-07 22:37:26 -04:00

62 lines
1.8 KiB
JavaScript

// Arity structure
/*jslint unparam: true, sub: true, vars: true, maxerr: 50, indent: 4 */
/*globals jQuery*/
(function (baselib) {
'use strict';
var exports = {};
baselib.ports = exports;
// Output Ports
var OutputPort = function () {};
var isOutputPort = baselib.makeClassPredicate(OutputPort);
var StandardOutputPort = function () {
OutputPort.call(this);
};
StandardOutputPort.prototype = baselib.heir(OutputPort.prototype);
StandardOutputPort.prototype.writeDomNode = function (MACHINE, domNode) {
MACHINE.params['currentDisplayer'](MACHINE, domNode);
jQuery('*', domNode).trigger({type : 'afterAttach'});
};
var StandardErrorPort = function () {
OutputPort.call(this);
};
StandardErrorPort.prototype = baselib.heir(OutputPort.prototype);
StandardErrorPort.prototype.writeDomNode = function (MACHINE, domNode) {
MACHINE.params['currentErrorDisplayer'](MACHINE, domNode);
jQuery('*', domNode).trigger({type : 'afterAttach'});
};
var OutputStringPort = function () {
this.buf = [];
};
OutputStringPort.prototype = baselib.heir(OutputPort.prototype);
OutputStringPort.prototype.writeDomNode = function (MACHINE, v) {
this.buf.push(jQuery(v).text());
};
OutputStringPort.prototype.getOutputString = function () {
return this.buf.join('');
};
var isOutputStringPort = baselib.makeClassPredicate(OutputStringPort);
exports.OutputPort = OutputPort;
exports.isOutputPort = isOutputPort;
exports.StandardOutputPort = StandardOutputPort;
exports.StandardErrorPort = StandardErrorPort;
exports.OutputStringPort = OutputStringPort;
exports.isOutputStringPort = isOutputStringPort;
}(this.plt.baselib));