-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathnode-forge+0.10.0.patch
597 lines (558 loc) · 18.6 KB
/
node-forge+0.10.0.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
diff --git a/node_modules/node-forge/lib/ed25519.js b/node_modules/node-forge/lib/ed25519.js
index f3e6faa..ed764bc 100644
--- a/node_modules/node-forge/lib/ed25519.js
+++ b/node_modules/node-forge/lib/ed25519.js
@@ -22,7 +22,6 @@ if(typeof BigInteger === 'undefined') {
}
var ByteBuffer = forge.util.ByteBuffer;
-var NativeBuffer = typeof Buffer === 'undefined' ? Uint8Array : Buffer;
/*
* Ed25519 algorithms, see RFC 8032:
@@ -56,10 +55,10 @@ ed25519.generateKeyPair = function(options) {
'"seed" must be a node.js Buffer, Uint8Array, or a binary string.');
}
- seed = messageToNativeBuffer({message: seed, encoding: 'binary'});
+ seed = messageToBuffer({message: seed, encoding: 'binary'});
- var pk = new NativeBuffer(ed25519.constants.PUBLIC_KEY_BYTE_LENGTH);
- var sk = new NativeBuffer(ed25519.constants.PRIVATE_KEY_BYTE_LENGTH);
+ var pk = new Buffer(ed25519.constants.PUBLIC_KEY_BYTE_LENGTH);
+ var sk = new Buffer(ed25519.constants.PRIVATE_KEY_BYTE_LENGTH);
for(var i = 0; i < 32; ++i) {
sk[i] = seed[i];
}
@@ -93,7 +92,7 @@ ed25519.privateKeyFromAsn1 = function(obj) {
var privateKey = capture.privateKey;
// manually extract the private key bytes from nested octet string, see FIXME:
// https://github.com/digitalbazaar/forge/blob/master/lib/asn1.js#L542
- var privateKeyBytes = messageToNativeBuffer({
+ var privateKeyBytes = messageToBuffer({
message: forge.asn1.fromDer(privateKey).value,
encoding: 'binary'
});
@@ -130,7 +129,7 @@ ed25519.publicKeyFromAsn1 = function(obj) {
if(publicKeyBytes.length !== ed25519.constants.PUBLIC_KEY_BYTE_LENGTH) {
throw new Error('Key length is invalid.');
}
- return messageToNativeBuffer({
+ return messageToBuffer({
message: publicKeyBytes,
encoding: 'binary'
});
@@ -138,7 +137,7 @@ ed25519.publicKeyFromAsn1 = function(obj) {
ed25519.publicKeyFromPrivateKey = function(options) {
options = options || {};
- var privateKey = messageToNativeBuffer({
+ var privateKey = messageToBuffer({
message: options.privateKey, encoding: 'binary'
});
if(privateKey.length !== ed25519.constants.PRIVATE_KEY_BYTE_LENGTH) {
@@ -147,7 +146,7 @@ ed25519.publicKeyFromPrivateKey = function(options) {
ed25519.constants.PRIVATE_KEY_BYTE_LENGTH);
}
- var pk = new NativeBuffer(ed25519.constants.PUBLIC_KEY_BYTE_LENGTH);
+ var pk = new Buffer(ed25519.constants.PUBLIC_KEY_BYTE_LENGTH);
for(var i = 0; i < pk.length; ++i) {
pk[i] = privateKey[32 + i];
}
@@ -156,8 +155,8 @@ ed25519.publicKeyFromPrivateKey = function(options) {
ed25519.sign = function(options) {
options = options || {};
- var msg = messageToNativeBuffer(options);
- var privateKey = messageToNativeBuffer({
+ var msg = messageToBuffer(options);
+ var privateKey = messageToBuffer({
message: options.privateKey,
encoding: 'binary'
});
@@ -171,11 +170,11 @@ ed25519.sign = function(options) {
ed25519.constants.PRIVATE_KEY_BYTE_LENGTH);
}
- var signedMsg = new NativeBuffer(
+ var signedMsg = new Buffer(
ed25519.constants.SIGN_BYTE_LENGTH + msg.length);
crypto_sign(signedMsg, msg, msg.length, privateKey);
- var sig = new NativeBuffer(ed25519.constants.SIGN_BYTE_LENGTH);
+ var sig = new Buffer(ed25519.constants.SIGN_BYTE_LENGTH);
for(var i = 0; i < sig.length; ++i) {
sig[i] = signedMsg[i];
}
@@ -184,13 +183,13 @@ ed25519.sign = function(options) {
ed25519.verify = function(options) {
options = options || {};
- var msg = messageToNativeBuffer(options);
+ var msg = messageToBuffer(options);
if(options.signature === undefined) {
throw new TypeError(
'"options.signature" must be a node.js Buffer, a Uint8Array, a forge ' +
'ByteBuffer, or a binary string.');
}
- var sig = messageToNativeBuffer({
+ var sig = messageToBuffer({
message: options.signature,
encoding: 'binary'
});
@@ -199,7 +198,7 @@ ed25519.verify = function(options) {
'"options.signature" must have a byte length of ' +
ed25519.constants.SIGN_BYTE_LENGTH);
}
- var publicKey = messageToNativeBuffer({
+ var publicKey = messageToBuffer({
message: options.publicKey,
encoding: 'binary'
});
@@ -209,8 +208,8 @@ ed25519.verify = function(options) {
ed25519.constants.PUBLIC_KEY_BYTE_LENGTH);
}
- var sm = new NativeBuffer(ed25519.constants.SIGN_BYTE_LENGTH + msg.length);
- var m = new NativeBuffer(ed25519.constants.SIGN_BYTE_LENGTH + msg.length);
+ var sm = new Buffer(ed25519.constants.SIGN_BYTE_LENGTH + msg.length);
+ var m = new Buffer(ed25519.constants.SIGN_BYTE_LENGTH + msg.length);
var i;
for(i = 0; i < ed25519.constants.SIGN_BYTE_LENGTH; ++i) {
sm[i] = sig[i];
@@ -221,9 +220,9 @@ ed25519.verify = function(options) {
return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0);
};
-function messageToNativeBuffer(options) {
+function messageToBuffer(options) {
var message = options.message;
- if(message instanceof Uint8Array || message instanceof NativeBuffer) {
+ if(message instanceof Uint8Array || message instanceof Buffer) {
return message;
}
@@ -255,39 +254,74 @@ function messageToNativeBuffer(options) {
}
// convert to native buffer
- var buffer = new NativeBuffer(message.length());
+ var buffer = new Buffer(message.length());
for(var i = 0; i < buffer.length; ++i) {
buffer[i] = message.at(i);
}
return buffer;
}
-var gf0 = gf();
-var gf1 = gf([1]);
-var D = gf([
- 0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070,
- 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]);
-var D2 = gf([
- 0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0,
- 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]);
-var X = gf([
- 0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c,
- 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]);
-var Y = gf([
- 0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666,
- 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]);
-var L = new Float64Array([
- 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
- 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10]);
-var I = gf([
- 0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43,
- 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]);
+// We are lazy loading the TypedArrays because electron-mksnapshot segfaults
+// till v30.0.0.
+// TODO(RaisinTen): Directly assign the values when we are on >= v30.0.0.
+var gf0;
+function initGf0() {
+ if (gf0) return;
+ gf0 = gf();
+}
+var gf1;
+function initGf1() {
+ if (gf1) return;
+ gf1 = gf([1]);
+}
+var D;
+function initD() {
+ if (D) return;
+ D = gf([
+ 0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070,
+ 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]);
+}
+var D2;
+function initD2() {
+ if (D2) return;
+ D2 = gf([
+ 0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0,
+ 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]);
+}
+var X;
+function initX() {
+ if (X) return;
+ X = gf([
+ 0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c,
+ 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]);
+}
+var Y;
+function initY() {
+ if (Y) return;
+ Y = gf([
+ 0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666,
+ 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]);
+}
+var L;
+function initL() {
+ if (L) return;
+ L = new Float64Array([
+ 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
+ 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10]);
+}
+var I;
+function initI() {
+ if (I) return;
+ I = gf([
+ 0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43,
+ 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]);
+}
// TODO: update forge buffer implementation to use `Buffer` or `Uint8Array`,
// whichever is available, to improve performance
function sha512(msg, msgLen) {
- // Note: `out` and `msg` are NativeBuffer
+ // Note: `out` and `msg` are Buffer
var md = forge.md.sha512.create();
var buffer = new ByteBuffer(msg);
md.update(buffer.getBytes(msgLen), 'binary');
@@ -295,7 +329,7 @@ function sha512(msg, msgLen) {
if(typeof Buffer !== 'undefined') {
return Buffer.from(hash, 'binary');
}
- var out = new NativeBuffer(ed25519.constants.HASH_BYTE_LENGTH);
+ var out = new Buffer(ed25519.constants.HASH_BYTE_LENGTH);
for(var i = 0; i < 64; ++i) {
out[i] = hash.charCodeAt(i);
}
@@ -367,7 +401,7 @@ function crypto_sign(sm, m, n, sk) {
function crypto_sign_open(m, sm, n, pk) {
var i, mlen;
- var t = new NativeBuffer(32);
+ var t = new Buffer(32);
var p = [gf(), gf(), gf(), gf()],
q = [gf(), gf(), gf(), gf()];
@@ -411,6 +445,7 @@ function crypto_sign_open(m, sm, n, pk) {
function modL(r, x) {
var carry, i, j, k;
+ initL();
for(i = 63; i >= 32; --i) {
carry = 0;
for(j = i - 32, k = i - 12; j < k; ++j) {
@@ -457,6 +492,7 @@ function add(p, q) {
A(t, q[0], q[1]);
M(b, b, t);
M(c, p[3], q[3]);
+ initD2();
M(c, c, D2);
M(d, p[2], q[2]);
A(d, d, d);
@@ -517,9 +553,11 @@ function unpackneg(r, p) {
den = gf(), den2 = gf(), den4 = gf(),
den6 = gf();
+ initGf1();
set25519(r[2], gf1);
unpack25519(r[1], p);
S(num, r[1]);
+ initD();
M(den, num, D);
Z(num, num, r[2]);
A(den, r[2], den);
@@ -539,6 +577,7 @@ function unpackneg(r, p) {
S(chk, r[0]);
M(chk, chk, den);
if(neq25519(chk, num)) {
+ initI();
M(r[0], r[0], I);
}
@@ -549,6 +588,7 @@ function unpackneg(r, p) {
}
if(par25519(r[0]) === (p[31] >> 7)) {
+ initGf0();
Z(r[0], gf0, r[0]);
}
@@ -582,8 +622,8 @@ function pow2523(o, i) {
}
function neq25519(a, b) {
- var c = new NativeBuffer(32);
- var d = new NativeBuffer(32);
+ var c = new Buffer(32);
+ var d = new Buffer(32);
pack25519(c, a);
pack25519(d, b);
return crypto_verify_32(c, 0, d, 0);
@@ -602,14 +642,16 @@ function vn(x, xi, y, yi, n) {
}
function par25519(a) {
- var d = new NativeBuffer(32);
+ var d = new Buffer(32);
pack25519(d, a);
return d[0] & 1;
}
function scalarmult(p, q, s) {
var b, i;
+ initGf0();
set25519(p[0], gf0);
+ initGf1();
set25519(p[1], gf1);
set25519(p[2], gf1);
set25519(p[3], gf0);
@@ -624,8 +666,11 @@ function scalarmult(p, q, s) {
function scalarbase(p, s) {
var q = [gf(), gf(), gf(), gf()];
+ initX();
set25519(q[0], X);
+ initY();
set25519(q[1], Y);
+ initGf1();
set25519(q[2], gf1);
M(q[3], X, Y);
scalarmult(p, q, s);
diff --git a/node_modules/node-forge/lib/pbkdf2.js b/node_modules/node-forge/lib/pbkdf2.js
index 714560e..33e5b56 100644
--- a/node_modules/node-forge/lib/pbkdf2.js
+++ b/node_modules/node-forge/lib/pbkdf2.js
@@ -14,10 +14,7 @@ require('./util');
var pkcs5 = forge.pkcs5 = forge.pkcs5 || {};
-var crypto;
-if(forge.util.isNodejs && !forge.options.usePureJavaScript) {
- crypto = require('crypto');
-}
+var crypto = require('crypto');
/**
* Derives a key from a password.
diff --git a/node_modules/node-forge/lib/prng.js b/node_modules/node-forge/lib/prng.js
index c2f5f05..32afb04 100644
--- a/node_modules/node-forge/lib/prng.js
+++ b/node_modules/node-forge/lib/prng.js
@@ -12,11 +12,7 @@
var forge = require('./forge');
require('./util');
-var _crypto = null;
-if(forge.util.isNodejs && !forge.options.usePureJavaScript &&
- !process.versions['node-webkit']) {
- _crypto = require('crypto');
-}
+var _crypto = require('crypto');
/* PRNG API */
var prng = module.exports = forge.prng = forge.prng || {};
diff --git a/node_modules/node-forge/lib/random.js b/node_modules/node-forge/lib/random.js
index d4e4bea..a937374 100644
--- a/node_modules/node-forge/lib/random.js
+++ b/node_modules/node-forge/lib/random.js
@@ -109,82 +109,11 @@ function spawnPrng() {
return ctx;
}
-// create default prng context
-var _ctx = spawnPrng();
-
-// add other sources of entropy only if window.crypto.getRandomValues is not
-// available -- otherwise this source will be automatically used by the prng
-var getRandomValues = null;
-var globalScope = forge.util.globalScope;
-var _crypto = globalScope.crypto || globalScope.msCrypto;
-if(_crypto && _crypto.getRandomValues) {
- getRandomValues = function(arr) {
- return _crypto.getRandomValues(arr);
- };
-}
-
-if(forge.options.usePureJavaScript ||
- (!forge.util.isNodejs && !getRandomValues)) {
- // if this is a web worker, do not use weak entropy, instead register to
- // receive strong entropy asynchronously from the main thread
- if(typeof window === 'undefined' || window.document === undefined) {
- // FIXME:
- }
-
- // get load time entropy
- _ctx.collectInt(+new Date(), 32);
-
- // add some entropy from navigator object
- if(typeof(navigator) !== 'undefined') {
- var _navBytes = '';
- for(var key in navigator) {
- try {
- if(typeof(navigator[key]) == 'string') {
- _navBytes += navigator[key];
- }
- } catch(e) {
- /* Some navigator keys might not be accessible, e.g. the geolocation
- attribute throws an exception if touched in Mozilla chrome://
- context.
-
- Silently ignore this and just don't use this as a source of
- entropy. */
- }
- }
- _ctx.collect(_navBytes);
- _navBytes = null;
- }
-
- // add mouse and keyboard collectors if jquery is available
- if(jQuery) {
- // set up mouse entropy capture
- jQuery().mousemove(function(e) {
- // add mouse coords
- _ctx.collectInt(e.clientX, 16);
- _ctx.collectInt(e.clientY, 16);
- });
-
- // set up keyboard entropy capture
- jQuery().keypress(function(e) {
- _ctx.collectInt(e.charCode, 8);
- });
- }
-}
-
-/* Random API */
-if(!forge.random) {
- forge.random = _ctx;
-} else {
- // extend forge.random with _ctx
- for(var key in _ctx) {
- forge.random[key] = _ctx[key];
- }
-}
-
-// expose spawn PRNG
-forge.random.createInstance = spawnPrng;
-
-module.exports = forge.random;
+// The default context is created and monkey-patched in unsnapshottable.js, so
+// that this can be snapshotted without requiring the use of the Node.js crypto
+// module.
+module.exports.forge = forge;
+module.exports.spawnPrng = spawnPrng;
})(typeof(jQuery) !== 'undefined' ? jQuery : null);
diff --git a/node_modules/node-forge/lib/rsa.js b/node_modules/node-forge/lib/rsa.js
index 7c67917..ddae716 100644
--- a/node_modules/node-forge/lib/rsa.js
+++ b/node_modules/node-forge/lib/rsa.js
@@ -74,7 +74,7 @@ if(typeof BigInteger === 'undefined') {
var BigInteger = forge.jsbn.BigInteger;
}
-var _crypto = forge.util.isNodejs ? require('crypto') : null;
+var _crypto = require('crypto');
// shortcut for asn.1 API
var asn1 = forge.asn1;
diff --git a/node_modules/node-forge/lib/util.js b/node_modules/node-forge/lib/util.js
index 98dfd34..bd04250 100644
--- a/node_modules/node-forge/lib/util.js
+++ b/node_modules/node-forge/lib/util.js
@@ -11,117 +11,8 @@ var baseN = require('./baseN');
/* Utilities API */
var util = module.exports = forge.util = forge.util || {};
-// define setImmediate and nextTick
-(function() {
- // use native nextTick (unless we're in webpack)
- // webpack (or better node-libs-browser polyfill) sets process.browser.
- // this way we can detect webpack properly
- if(typeof process !== 'undefined' && process.nextTick && !process.browser) {
- util.nextTick = process.nextTick;
- if(typeof setImmediate === 'function') {
- util.setImmediate = setImmediate;
- } else {
- // polyfill setImmediate with nextTick, older versions of node
- // (those w/o setImmediate) won't totally starve IO
- util.setImmediate = util.nextTick;
- }
- return;
- }
-
- // polyfill nextTick with native setImmediate
- if(typeof setImmediate === 'function') {
- util.setImmediate = function() { return setImmediate.apply(undefined, arguments); };
- util.nextTick = function(callback) {
- return setImmediate(callback);
- };
- return;
- }
-
- /* Note: A polyfill upgrade pattern is used here to allow combining
- polyfills. For example, MutationObserver is fast, but blocks UI updates,
- so it needs to allow UI updates periodically, so it falls back on
- postMessage or setTimeout. */
-
- // polyfill with setTimeout
- util.setImmediate = function(callback) {
- setTimeout(callback, 0);
- };
-
- // upgrade polyfill to use postMessage
- if(typeof window !== 'undefined' &&
- typeof window.postMessage === 'function') {
- var msg = 'forge.setImmediate';
- var callbacks = [];
- util.setImmediate = function(callback) {
- callbacks.push(callback);
- // only send message when one hasn't been sent in
- // the current turn of the event loop
- if(callbacks.length === 1) {
- window.postMessage(msg, '*');
- }
- };
- function handler(event) {
- if(event.source === window && event.data === msg) {
- event.stopPropagation();
- var copy = callbacks.slice();
- callbacks.length = 0;
- copy.forEach(function(callback) {
- callback();
- });
- }
- }
- window.addEventListener('message', handler, true);
- }
-
- // upgrade polyfill to use MutationObserver
- if(typeof MutationObserver !== 'undefined') {
- // polyfill with MutationObserver
- var now = Date.now();
- var attr = true;
- var div = document.createElement('div');
- var callbacks = [];
- new MutationObserver(function() {
- var copy = callbacks.slice();
- callbacks.length = 0;
- copy.forEach(function(callback) {
- callback();
- });
- }).observe(div, {attributes: true});
- var oldSetImmediate = util.setImmediate;
- util.setImmediate = function(callback) {
- if(Date.now() - now > 15) {
- now = Date.now();
- oldSetImmediate(callback);
- } else {
- callbacks.push(callback);
- // only trigger observer when it hasn't been triggered in
- // the current turn of the event loop
- if(callbacks.length === 1) {
- div.setAttribute('a', attr = !attr);
- }
- }
- };
- }
-
- util.nextTick = util.setImmediate;
-})();
-
// check if running under Node.js
-util.isNodejs =
- typeof process !== 'undefined' && process.versions && process.versions.node;
-
-
-// 'self' will also work in Web Workers (instance of WorkerGlobalScope) while
-// it will point to `window` in the main thread.
-// To remain compatible with older browsers, we fall back to 'window' if 'self'
-// is not available.
-util.globalScope = (function() {
- if(util.isNodejs) {
- return global;
- }
-
- return typeof self === 'undefined' ? window : self;
-})();
+util.isNodejs = true;
// define isArray
util.isArray = Array.isArray || function(x) {