-
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathtest-replacements.js
More file actions
174 lines (163 loc) · 5.19 KB
/
Copy pathtest-replacements.js
File metadata and controls
174 lines (163 loc) · 5.19 KB
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
const altForEachImplReplacement = require('./common-replacements').altForEachImplReplacement
, altForEachUseReplacement = require('./common-replacements').altForEachUseReplacement
, objectKeysDefine = require('./common-replacements').objectKeysDefine
, objectKeysReplacement = require('./common-replacements').objectKeysReplacement
module.exports.all = [
[
/require\(['"]string_decoder['"]\)/g
, 'require(\'../../\')'
]
, [
/Buffer\.((?:alloc)|(?:allocUnsafe)|(?:from))/g,
'bufferShim.$1'
]
, [
/^('use strict';)$/m,
'$1\nconst bufferShim = require(\'safe-buffer\').Buffer;'
]
]
module.exports['test-string-decoder.js'] = [
// test removed because it is V8-version dependant.
[
/test\('utf-8', bufferShim\.from\('EDA0B5EDB08D'.*\n.*\n/
, ''
],
, [
/test\('utf-8', bufferShim\.from\('F0B841', 'hex'.*\n/
, ''
]
, [
/test\('utf-8', bufferShim\.from\('CCE2B8B8', 'hex'.*\n/
, ''
]
, [
/test\('utf-8', bufferShim\.from\('E2B8CCB8', 'hex'.*\n/
, ''
]
, [
/assert\.strictEqual\(decoder\.end(), '\ufffd'\);\n/
, ''
]
]
module.exports['common.js'] = [
objectKeysDefine
, objectKeysReplacement
, altForEachImplReplacement
, altForEachUseReplacement
, [
/(exports.mustCall[\s\S]*)/m
, '$1\n'
+ 'if (!util._errnoException) {\n'
+ ' var uv;\n'
+ ' util._errnoException = function(err, syscall) {\n'
+ ' if (util.isUndefined(uv)) try { uv = process.binding(\'uv\'); } catch (e) {}\n'
+ ' var errname = uv ? uv.errname(err) : \'\';\n'
+ ' var e = new Error(syscall + \' \' + errname);\n'
+ ' e.code = errname;\n'
+ ' e.errno = errname;\n'
+ ' e.syscall = syscall;\n'
+ ' return e;\n'
+ ' };\n'
+ '}\n'
]
// for streams2 on node 0.11
// and dtrace in 0.10
// and coverage in all
, [
/^( for \(var x in global\) \{|function leakedGlobals\(\) \{)$/m
, ' /*<replacement>*/\n'
+ ' if (typeof constructor == \'function\')\n'
+ ' knownGlobals.push(constructor);\n'
+ ' if (typeof DTRACE_NET_SOCKET_READ == \'function\')\n'
+ ' knownGlobals.push(DTRACE_NET_SOCKET_READ);\n'
+ ' if (typeof DTRACE_NET_SOCKET_WRITE == \'function\')\n'
+ ' knownGlobals.push(DTRACE_NET_SOCKET_WRITE);\n'
+ ' if (global.__coverage__)\n'
+ ' knownGlobals.push(__coverage__);\n'
+ '\'core,__core-js_shared__,Promise,Map,Set,WeakMap,WeakSet,Reflect,System,asap,Observable,regeneratorRuntime,_babelPolyfill\'.split(\',\').filter(function (item) { return typeof global[item] !== undefined}).forEach(function (item) {knownGlobals.push(global[item])})'
+ ' /*</replacement>*/\n\n$1'
]
// for node 0.8
, [
/^/
, '/*<replacement>*/'
+ '\nif (!global.setImmediate) {\n'
+ ' global.setImmediate = function setImmediate(fn) {\n'
+ ' return setTimeout(fn.bind.apply(fn, arguments), 4);\n'
+ ' };\n'
+ '}\n'
+ 'if (!global.clearImmediate) {\n'
+ ' global.clearImmediate = function clearImmediate(i) {\n'
+ ' return clearTimeout(i);\n'
+ ' };\n'
+ '}\n'
+ '/*</replacement>*/\n'
]
, [
/^if \(global\.ArrayBuffer\) \{([^\}]+)\}$/m
, '/*<replacement>*/if (!process.browser) {'
+ '\nif \(global\.ArrayBuffer\) {$1}\n'
+ '}/*</replacement>*/\n'
]
, [
/^Object\.defineProperty\(([\w\W]+?)\}\)\;/mg
, '/*<replacement>*/if (!process.browser) {'
+ '\nObject\.defineProperty($1});\n'
+ '}/*</replacement>*/\n'
]
, [
/if \(!process\.send\)/
, 'if (!process.send && !process.browser)'
]
, [
/^/,
`/*<replacement>*/
require('babel-polyfill');
var util = require('util');
for (var i in util) exports[i] = util[i];
/*</replacement>*/`
],
[
/var regexp = `\^\(\\\\w\+\)\\\\s\+\\\\s\$\{port\}\/\$\{protocol\}\\\\s`;/,
`var regexp = '^(\\w+)\\s+\\s' + port + '/' + protocol + '\\s';`
],
[
/^var util = require\('util'\);/m
, '\n/*<replacement>*/\nvar util = require(\'core-util-is\');\n'
+ 'util.inherits = require(\'inherits\');\n/*</replacement>*/\n'
],
[
/^const util = require\('util'\);/m
, '\n/*<replacement>*/\nvar util = require(\'core-util-is\');\n'
+ 'util.inherits = require(\'inherits\');\n/*</replacement>*/\n'
]
, [
/process\.binding\('timer_wrap'\)\.Timer;/,
'{now: function (){}}'
],
[
/(exports\.enoughTestCpu[^;]+;)/,
'/*$1*/'
],
[
/exports\.buildType/,
'//exports.buildType'
],
[
/require\('async_hooks'\)/,
'/*require(\'async_hooks\')'
],
[
/\}\).enable\(\);/,
'}).enable();*/'
],
[
/(?:var|const) async_wrap = process\.binding\('async_wrap'\);\n.*(?:var|const) (?:{ )?kCheck(?: })? = async_wrap\.constants(?:\.kCheck)?;/gm,
'// const async_wrap = process.binding(\'async_wrap\');\n' +
' // const kCheck = async_wrap.constants.kCheck;'
],
[
/async_wrap\.async_hook_fields\[kCheck\] \+= 1;/,
'// async_wrap.async_hook_fields[kCheck] += 1;'
]
]