phptest 0.0.7 → 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: [12.x, 14.x, 16.x]
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.7",
2
+ "version": "0.0.8",
3
3
  "name": "phptest",
4
4
  "description": "Test helper library for PHP core runtime components",
5
5
  "keywords": [
@@ -25,7 +25,7 @@
25
25
  "dependencies": {
26
26
  "es6-weak-map": "^2.0.3",
27
27
  "is-promise": "^4.0.0",
28
- "jshint": "^2.13.4",
28
+ "jshint": "^2.13.6",
29
29
  "lie": "^3.3.0",
30
30
  "microdash": "^1.4.2",
31
31
  "regexp.escape": "^1.1.0",
@@ -35,7 +35,6 @@
35
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'),
@@ -126,6 +127,93 @@ module.exports = function (phpCorePath, initRuntime) {
126
127
  return module;
127
128
  },
128
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
+
129
217
  // Create isolated runtimes to be shared by all tests that don't create their own,
130
218
  // to avoid modifying the singleton module exports.
131
219
  asyncRuntime = createAsyncRuntime(),
@@ -141,61 +229,9 @@ module.exports = function (phpCorePath, initRuntime) {
141
229
  )()
142
230
  .match(/<anonymous>:(\d+):\d+/)[1] - 1;
143
231
 
144
- // Force all opcodes to be async for all async mode tests, to help ensure async handling is in place.
145
- asyncRuntime.install({
146
- serviceGroups: [
147
- function (internals) {
148
- var get = internals.getServiceFetcher();
149
-
150
- // As we'll be overriding the "opcode_executor" service.
151
- internals.allowServiceOverride();
152
-
153
- return {
154
- 'opcode_executor': function () {
155
- var referenceFactory = get('reference_factory'),
156
- valueFactory = get('value_factory');
157
-
158
- function AsyncOpcodeExecutor() {
159
- }
160
-
161
- util.inherits(AsyncOpcodeExecutor, OpcodeExecutor);
162
-
163
- AsyncOpcodeExecutor.prototype.execute = function (opcode) {
164
- var result = opcode.handle();
165
-
166
- if (!opcode.isTraced()) {
167
- // Don't attempt to make any untraced opcodes pause,
168
- // as resuming from inside them is not possible.
169
- return result;
170
- }
171
-
172
- if (result instanceof Value) {
173
- return valueFactory.createAsyncPresent(result);
174
- }
175
-
176
- if (result instanceof Reference || result instanceof Variable) {
177
- return referenceFactory.createAccessor(function () {
178
- // Defer returning the value of the reference.
179
- return valueFactory.createAsyncPresent(result.getValue());
180
- }, function (value) {
181
- // Defer assignment in a microtask to test for async handling.
182
- return valueFactory.createAsyncMicrotaskFuture(function (resolve, reject) {
183
- result.setValue(value).next(resolve, reject);
184
- });
185
- }, function (reference) {
186
- return result.setReference(reference.getReference());
187
- });
188
- }
189
-
190
- return result;
191
- };
192
-
193
- return new AsyncOpcodeExecutor();
194
- }
195
- };
196
- }
197
- ]
198
- });
232
+ if (forceOpcodesAsync !== false) {
233
+ installForcedAsyncOpcodeHook(asyncRuntime);
234
+ }
199
235
 
200
236
  return {
201
237
  asyncRuntime: asyncRuntime,
@@ -220,6 +256,8 @@ module.exports = function (phpCorePath, initRuntime) {
220
256
 
221
257
  createSyncRuntime: createSyncRuntime,
222
258
 
259
+ installForcedAsyncOpcodeHook: installForcedAsyncOpcodeHook,
260
+
223
261
  /**
224
262
  * Attempts to make this integration test slightly less brittle when future changes occur,
225
263
  * by scrubbing out things that are out of our control and likely to change (such as line/column numbers