Commit 9189891c authored by Aurel's avatar Aurel

tell jslint this is node scripts

parent 560504ee
...@@ -75,15 +75,17 @@ module.exports = function (grunt) { ...@@ -75,15 +75,17 @@ module.exports = function (grunt) {
maxlen: 80, maxlen: 80,
indent: 2, indent: 2,
maxerr: 3, maxerr: 3,
node: true,
nomen: true nomen: true
} }
}, },
jio_nodejs_include: { jio_nodejs_include: {
src: ['src/nodejs/include.js'], src: ['src/nodejs/*.js'],
directives: { directives: {
maxlen: 80, maxlen: 80,
indent: 2, indent: 2,
maxerr: 3, maxerr: 3,
node: true,
nomen: true nomen: true
} }
}, },
......
(function (env) { (function (env) {
"use strict"; "use strict";
const process = require("process"); var process = require("process");
env._html5_weakmap = new WeakMap(); env._html5_weakmap = new WeakMap();
function EventTarget() { env._html5_weakmap.set(this, Object.create(null)); } function EventTarget() { env._html5_weakmap.set(this, Object.create(null)); }
EventTarget.prototype.addEventListener = function (type, listener) { EventTarget.prototype.addEventListener = function (type, listener) {
if (typeof listener !== "function") return; if (typeof listener !== "function") return;
const em = env._html5_weakmap.get(this); var em = env._html5_weakmap.get(this);
type = "" + type; type = "" + type;
if (em[type]) em[type].push(listener); if (em[type]) em[type].push(listener);
else em[type] = [listener]; else em[type] = [listener];
}; };
EventTarget.prototype.removeEventListener = function (type, listener) { EventTarget.prototype.removeEventListener = function (type, listener) {
if (typeof listener !== "function") return; if (typeof listener !== "function") return;
const em = env._html5_weakmap.get(this); var em = env._html5_weakmap.get(this);
var i = 0, listeners = em[type]; var i = 0, listeners = em[type];
type = "" + type; type = "" + type;
if (listeners) for (; i < listeners.length; ++i) if (listeners[i] === listener) { if (listeners) for (; i < listeners.length; ++i) if (listeners[i] === listener) {
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
} }
}; };
EventTarget.prototype.dispatchEvent = function (event) { EventTarget.prototype.dispatchEvent = function (event) {
const type = "" + event.type, var type = "" + event.type,
em = env._html5_weakmap.get(this), em = env._html5_weakmap.get(this),
ontype = "on" + type; ontype = "on" + type;
var i = 0, listeners; var i = 0, listeners;
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
function Blob(blobParts, options) { function Blob(blobParts, options) {
// https://developer.mozilla.org/en-US/docs/Web/API/Blob // https://developer.mozilla.org/en-US/docs/Web/API/Blob
var i = 0; const priv = {}, buffers = []; var i = 0; var priv = {}, buffers = [];
env._html5_weakmap.set(this, priv); env._html5_weakmap.set(this, priv);
for (; i < blobParts.length; ++i) { for (; i < blobParts.length; ++i) {
if (Buffer.isBuffer(blobParts[i])) { if (Buffer.isBuffer(blobParts[i])) {
...@@ -67,27 +67,27 @@ ...@@ -67,27 +67,27 @@
FileReader.prototype = Object.create(EventTarget.prototype); FileReader.prototype = Object.create(EventTarget.prototype);
Object.defineProperty(FileReader, "constructor", {value: FileReader}); Object.defineProperty(FileReader, "constructor", {value: FileReader});
FileReader.prototype.readAsText = function (blob) { FileReader.prototype.readAsText = function (blob) {
const priv = env._html5_weakmap.get(blob); var priv = env._html5_weakmap.get(blob);
const text = priv.data.toString(); var text = priv.data.toString();
const event = Object.freeze({type: "load", target: this}); var event = Object.freeze({type: "load", target: this});
process.nextTick(() => { process.nextTick(() => {
this.result = text; this.result = text;
this.dispatchEvent(event); this.dispatchEvent(event);
}); });
}; };
FileReader.prototype.readAsArrayBuffer = function (blob) { FileReader.prototype.readAsArrayBuffer = function (blob) {
const priv = env._html5_weakmap.get(blob); var priv = env._html5_weakmap.get(blob);
const arrayBuffer = new Uint8Array(priv.data).buffer; var arrayBuffer = new Uint8Array(priv.data).buffer;
const event = Object.freeze({type: "load", target: this}); var event = Object.freeze({type: "load", target: this});
process.nextTick(() => { process.nextTick(() => {
this.result = arrayBuffer; this.result = arrayBuffer;
this.dispatchEvent(event); this.dispatchEvent(event);
}); });
}; };
FileReader.prototype.readAsDataURL = function (blob) { FileReader.prototype.readAsDataURL = function (blob) {
const priv = env._html5_weakmap.get(blob); var priv = env._html5_weakmap.get(blob);
const dataUrl = "data:" + blob.type + ";base64," + priv.data.toString("base64"); var dataUrl = "data:" + blob.type + ";base64," + priv.data.toString("base64");
const event = Object.freeze({type: "load", target: this}); var event = Object.freeze({type: "load", target: this});
process.nextTick(() => { process.nextTick(() => {
this.result = dataUrl; this.result = dataUrl;
this.dispatchEvent(event); this.dispatchEvent(event);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment