phptest 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -8,10 +8,10 @@ jobs:
|
|
|
8
8
|
|
|
9
9
|
strategy:
|
|
10
10
|
matrix:
|
|
11
|
-
node-version: [
|
|
11
|
+
node-version: [14.x, 16.x, 18.x, 19.x]
|
|
12
12
|
|
|
13
13
|
steps:
|
|
14
|
-
# Check out the repository under $GITHUB_WORKSPACE, so this job can access it
|
|
14
|
+
# Check out the repository under $GITHUB_WORKSPACE, so this job can access it.
|
|
15
15
|
- uses: actions/checkout@v2
|
|
16
16
|
|
|
17
17
|
- name: Use Node.js ${{ matrix.node-version }}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.0.
|
|
2
|
+
"version": "0.0.8",
|
|
3
3
|
"name": "phptest",
|
|
4
4
|
"description": "Test helper library for PHP core runtime components",
|
|
5
5
|
"keywords": [
|
|
@@ -25,17 +25,16 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"es6-weak-map": "^2.0.3",
|
|
27
27
|
"is-promise": "^4.0.0",
|
|
28
|
-
"jshint": "^2.13.
|
|
28
|
+
"jshint": "^2.13.6",
|
|
29
29
|
"lie": "^3.3.0",
|
|
30
30
|
"microdash": "^1.4.2",
|
|
31
31
|
"regexp.escape": "^1.1.0",
|
|
32
32
|
"source-map": "^0.8.0-beta.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"phpcore": "^7.
|
|
35
|
+
"phpcore": "^7.2.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"core-js-pure": "^3.21.1",
|
|
39
38
|
"mocha": "^10.0.0",
|
|
40
39
|
"phptoast": "^9.0.1",
|
|
41
40
|
"phptojs": "^9.0.1"
|
|
@@ -24,9 +24,10 @@ var _ = require('microdash'),
|
|
|
24
24
|
*
|
|
25
25
|
* @param {string} phpCorePath
|
|
26
26
|
* @param {Function=} initRuntime
|
|
27
|
+
* @param {boolean=} forceOpcodesAsync
|
|
27
28
|
* @returns {Object}
|
|
28
29
|
*/
|
|
29
|
-
module.exports = function (phpCorePath, initRuntime) {
|
|
30
|
+
module.exports = function (phpCorePath, initRuntime, forceOpcodesAsync) {
|
|
30
31
|
var
|
|
31
32
|
resolvedPHPCorePath = path.resolve(phpCorePath),
|
|
32
33
|
OpcodeExecutor = require(resolvedPHPCorePath + '/src/Core/Opcode/Handler/OpcodeExecutor'),
|
|
@@ -110,6 +111,8 @@ module.exports = function (phpCorePath, initRuntime) {
|
|
|
110
111
|
return phpCore;
|
|
111
112
|
});
|
|
112
113
|
|
|
114
|
+
// Note that we do not support setting additional module options for PHPCore,
|
|
115
|
+
// because module-level options are deprecated in favour of environment-level ones.
|
|
113
116
|
if (path !== null) {
|
|
114
117
|
module = module.using({
|
|
115
118
|
path: path
|
|
@@ -124,6 +127,93 @@ module.exports = function (phpCorePath, initRuntime) {
|
|
|
124
127
|
return module;
|
|
125
128
|
},
|
|
126
129
|
|
|
130
|
+
/**
|
|
131
|
+
* Forces all opcodes to be async for all async mode tests, to help ensure async handling is in place.
|
|
132
|
+
*
|
|
133
|
+
* @param {Runtime} runtime
|
|
134
|
+
*/
|
|
135
|
+
installForcedAsyncOpcodeHook = function (runtime) {
|
|
136
|
+
runtime.install({
|
|
137
|
+
serviceGroups: [
|
|
138
|
+
function (internals) {
|
|
139
|
+
var get = internals.getServiceFetcher();
|
|
140
|
+
|
|
141
|
+
// As we'll be overriding the "opcode_executor" service.
|
|
142
|
+
internals.allowServiceOverride();
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
'opcode_executor': function () {
|
|
146
|
+
var controlBridge = get('control_bridge'),
|
|
147
|
+
futureFactory = get('future_factory'),
|
|
148
|
+
referenceFactory = get('reference_factory'),
|
|
149
|
+
valueFactory = get('value_factory');
|
|
150
|
+
|
|
151
|
+
function AsyncOpcodeExecutor() {
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
util.inherits(AsyncOpcodeExecutor, OpcodeExecutor);
|
|
155
|
+
|
|
156
|
+
AsyncOpcodeExecutor.prototype.execute = function (opcode) {
|
|
157
|
+
var result = opcode.handle();
|
|
158
|
+
|
|
159
|
+
if (!opcode.isTraced()) {
|
|
160
|
+
// Don't attempt to make any untraced opcodes pause,
|
|
161
|
+
// as resuming from inside them is not possible.
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (controlBridge.isFuture(result) && result.isSettled()) {
|
|
166
|
+
// Wrap settled Futures in a deferring one to force a pause.
|
|
167
|
+
return futureFactory.createAsyncPresent(result);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (result instanceof Value) {
|
|
171
|
+
return valueFactory.createAsyncPresent(result);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (result instanceof Reference || result instanceof Variable) {
|
|
175
|
+
return referenceFactory.createAccessor(function () {
|
|
176
|
+
// Defer returning the value of the reference.
|
|
177
|
+
return valueFactory.createAsyncPresent(result.getValue());
|
|
178
|
+
}, function (value) {
|
|
179
|
+
// Defer assignment in a microtask to test for async handling.
|
|
180
|
+
return valueFactory.createAsyncMicrotaskFuture(function (resolve, reject) {
|
|
181
|
+
result.setValue(value).next(resolve, reject);
|
|
182
|
+
});
|
|
183
|
+
}, function () {
|
|
184
|
+
return result.unset();
|
|
185
|
+
}, function () {
|
|
186
|
+
return result.getReference();
|
|
187
|
+
}, function (reference) {
|
|
188
|
+
result.setReference(reference);
|
|
189
|
+
}, function () {
|
|
190
|
+
result.clearReference();
|
|
191
|
+
}, function () {
|
|
192
|
+
return result.isDefined();
|
|
193
|
+
}, function () {
|
|
194
|
+
return result.isReadable();
|
|
195
|
+
}, function () {
|
|
196
|
+
return result.isEmpty();
|
|
197
|
+
}, function () {
|
|
198
|
+
return result.isSet();
|
|
199
|
+
}, function () {
|
|
200
|
+
return result.isReference();
|
|
201
|
+
}, function () {
|
|
202
|
+
return result.raiseUndefined();
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return result;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
return new AsyncOpcodeExecutor();
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
]
|
|
214
|
+
});
|
|
215
|
+
},
|
|
216
|
+
|
|
127
217
|
// Create isolated runtimes to be shared by all tests that don't create their own,
|
|
128
218
|
// to avoid modifying the singleton module exports.
|
|
129
219
|
asyncRuntime = createAsyncRuntime(),
|
|
@@ -139,61 +229,9 @@ module.exports = function (phpCorePath, initRuntime) {
|
|
|
139
229
|
)()
|
|
140
230
|
.match(/<anonymous>:(\d+):\d+/)[1] - 1;
|
|
141
231
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
function (internals) {
|
|
146
|
-
var get = internals.getServiceFetcher();
|
|
147
|
-
|
|
148
|
-
// As we'll be overriding the "opcode_executor" service.
|
|
149
|
-
internals.allowServiceOverride();
|
|
150
|
-
|
|
151
|
-
return {
|
|
152
|
-
'opcode_executor': function () {
|
|
153
|
-
var referenceFactory = get('reference_factory'),
|
|
154
|
-
valueFactory = get('value_factory');
|
|
155
|
-
|
|
156
|
-
function AsyncOpcodeExecutor() {
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
util.inherits(AsyncOpcodeExecutor, OpcodeExecutor);
|
|
160
|
-
|
|
161
|
-
AsyncOpcodeExecutor.prototype.execute = function (opcode) {
|
|
162
|
-
var result = opcode.handle();
|
|
163
|
-
|
|
164
|
-
if (!opcode.isTraced()) {
|
|
165
|
-
// Don't attempt to make any untraced opcodes pause,
|
|
166
|
-
// as resuming from inside them is not possible.
|
|
167
|
-
return result;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (result instanceof Value) {
|
|
171
|
-
return valueFactory.createAsyncPresent(result);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (result instanceof Reference || result instanceof Variable) {
|
|
175
|
-
return referenceFactory.createAccessor(function () {
|
|
176
|
-
// Defer returning the value of the reference.
|
|
177
|
-
return valueFactory.createAsyncPresent(result.getValue());
|
|
178
|
-
}, function (value) {
|
|
179
|
-
// Defer assignment in a microtask to test for async handling.
|
|
180
|
-
return valueFactory.createAsyncMicrotaskFuture(function (resolve, reject) {
|
|
181
|
-
result.setValue(value).next(resolve, reject);
|
|
182
|
-
});
|
|
183
|
-
}, function (reference) {
|
|
184
|
-
return result.setReference(reference);
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
return result;
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
return new AsyncOpcodeExecutor();
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
]
|
|
196
|
-
});
|
|
232
|
+
if (forceOpcodesAsync !== false) {
|
|
233
|
+
installForcedAsyncOpcodeHook(asyncRuntime);
|
|
234
|
+
}
|
|
197
235
|
|
|
198
236
|
return {
|
|
199
237
|
asyncRuntime: asyncRuntime,
|
|
@@ -218,6 +256,8 @@ module.exports = function (phpCorePath, initRuntime) {
|
|
|
218
256
|
|
|
219
257
|
createSyncRuntime: createSyncRuntime,
|
|
220
258
|
|
|
259
|
+
installForcedAsyncOpcodeHook: installForcedAsyncOpcodeHook,
|
|
260
|
+
|
|
221
261
|
/**
|
|
222
262
|
* Attempts to make this integration test slightly less brittle when future changes occur,
|
|
223
263
|
* by scrubbing out things that are out of our control and likely to change (such as line/column numbers
|