-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHP: Ensures that ExitStatus error thrown my Emscripten has a stack t…
…race attached (#470) ## Description Overrides Emscripten's default ExitStatus object which gets thrown on failure. Unfortunately, the default object is not a subclass of Error and does not provide any stack trace. This is a deliberate behavior on Emscripten's end to prevent memory leaks after the program exits. See: emscripten-core/emscripten#9108 In case of WordPress Playground, the worker in which the PHP runs will typically exit after the PHP program finishes, so we don't have to worry about memory leaks. As for assigning to a previously undeclared ExitStatus variable here, the Emscripten module declares `ExitStatus` as `function ExitStatus` which means it gets hoisted to the top of the scope and can be reassigned here – before the actual declaration is reached. If that sounds weird, try this example: ```js ExitStatus = () => { console.log("reassigned"); } function ExitStatus() {} ExitStatus(); // logs "reassigned" ``` ## Testing instructions Confirm the CI tests passed Related: #416 cc @wojtekn
- Loading branch information
Showing
39 changed files
with
912 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
export function init(RuntimeName, PHPLoader) { | ||
/** | ||
* Overrides Emscripten's default ExitStatus object which gets | ||
* thrown on failure. Unfortunately, the default object is not | ||
* a subclass of Error and does not provide any stack trace. | ||
* | ||
* This is a deliberate behavior on Emscripten's end to prevent | ||
* memory leaks after the program exits. See: | ||
* | ||
* https://github.com/emscripten-core/emscripten/pull/9108 | ||
* | ||
* In case of WordPress Playground, the worker in which the PHP | ||
* runs will typically exit after the PHP program finishes, so | ||
* we don't have to worry about memory leaks. | ||
* | ||
* As for assigning to a previously undeclared ExitStatus variable here, | ||
* the Emscripten module declares `ExitStatus` as `function ExitStatus` | ||
* which means it gets hoisted to the top of the scope and can be | ||
* reassigned here – before the actual declaration is reached. | ||
* | ||
* If that sounds weird, try this example: | ||
* | ||
* ExitStatus = () => { console.log("reassigned"); } | ||
* function ExitStatus() {} | ||
* ExitStatus(); | ||
* // logs "reassigned" | ||
*/ | ||
ExitStatus = class PHPExitStatus extends Error { | ||
constructor(status) { | ||
super(status); | ||
this.name = "ExitStatus"; | ||
this.message = "Program terminated with exit(" + status + ")"; | ||
this.status = status; | ||
} | ||
} | ||
|
||
// The rest of the code comes from the built php.js file and esm-suffix.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.