[pathkit] Add .ready() to initialize
See https://github.com/kripken/emscripten/issues/5820 and
https://skia-review.googlesource.com/c/skia/+/181177 for more context.
(Problem was discovered in CanvasKit, and this ports the same fix to
PathKit).
Bug: skia:
Change-Id: Ic8b2fb399210631a571595a5b3d11d1736c00def
Reviewed-on: https://skia-review.googlesource.com/c/181178
Reviewed-by: Joe Gregorio <jcgregorio@google.com>
diff --git a/modules/pathkit/CHANGELOG.md b/modules/pathkit/CHANGELOG.md
index 4ea69d1..3c13fa8 100644
--- a/modules/pathkit/CHANGELOG.md
+++ b/modules/pathkit/CHANGELOG.md
@@ -1,15 +1,21 @@
+# PathKit Changelog
+All notable changes to this project will be documented in this file.
+The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
+and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
-Trunk
------
+## [Unreleased]
-New Features:
+## [0.5.1] 2019-01-04
+### Changed
+ - `PathKitInit(...).then()` is no longer the recommended way to initialize things.
+It will be removed in 0.6.0. Use `PathKitInit(...).ready()`, which returns a real Promise.
-Bug Fixes:
+## [0.5.0] 2018-12-17
+Updated PathKit to use same FOSS license as Skia proper.
-v0.4.2: 2018-11-07
-------------------
+## [0.4.2] 2018-11-07
Beginning of changelog.
diff --git a/modules/pathkit/compile.sh b/modules/pathkit/compile.sh
index 6f1e0c2..e019de1 100755
--- a/modules/pathkit/compile.sh
+++ b/modules/pathkit/compile.sh
@@ -120,6 +120,7 @@
--bind \
--pre-js $BASE_DIR/helper.js \
--pre-js $BASE_DIR/chaining.js \
+--post-js $BASE_DIR/ready.js \
-DSK_DISABLE_READBUFFER=1 \
-fno-rtti -fno-exceptions -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 \
$WASM_CONF \
diff --git a/modules/pathkit/npm-asmjs/README.md b/modules/pathkit/npm-asmjs/README.md
index a04007f..ff71af1 100644
--- a/modules/pathkit/npm-asmjs/README.md
+++ b/modules/pathkit/npm-asmjs/README.md
@@ -5,7 +5,7 @@
<script src="/node_modules/pathkit-asmjs/bin/pathkit.js"></script>
PathKitInit({
locateFile: (file) => '/node_modules/pathkit-asmjs/bin/'+file,
- }).then((PathKit) => {
+ }).ready().then((PathKit) => {
// Code goes here using PathKit
});
@@ -14,7 +14,7 @@
is used to tell the JS loader where to find the .js.mem file. By default, it will
look for /pathkit.js.mem, so if this is not the case, use `locateFile` to configure
this properly.
-The `PathKit` object returned through the .then() callback is fully loaded and ready to use.
+The `PathKit` object returned upon resolution of the .ready() Promise is fully loaded and ready to use.
See the [API page](https://skia.org/user/modules/pathkit) and
[example.html](https://github.com/google/skia/blob/master/modules/pathkit/npm-asmjs/example.html)
@@ -29,7 +29,7 @@
In the JS code, use require():
const PathKitInit = require('pathkit-asmjs/bin/pathkit.js')
- PathKitInit().then((PathKit) => {
+ PathKitInit().ready().then((PathKit) => {
// Code goes here using PathKit
})
diff --git a/modules/pathkit/npm-asmjs/example.html b/modules/pathkit/npm-asmjs/example.html
index c50c453..a2fc4c1 100644
--- a/modules/pathkit/npm-asmjs/example.html
+++ b/modules/pathkit/npm-asmjs/example.html
@@ -53,7 +53,7 @@
PathKitInit({
locateFile: (file) => '/node_modules/pathkit-asmjs/bin/'+file,
- }).then((PathKit) => {
+ }).ready().then((PathKit) => {
window.PathKit = PathKit;
OutputsExample(PathKit);
Path2DExample(PathKit);
diff --git a/modules/pathkit/npm-asmjs/package.json b/modules/pathkit/npm-asmjs/package.json
index 68b1d81..70f773c 100644
--- a/modules/pathkit/npm-asmjs/package.json
+++ b/modules/pathkit/npm-asmjs/package.json
@@ -1,6 +1,6 @@
{
"name": "pathkit-asmjs",
- "version": "0.5.0",
+ "version": "0.5.1",
"description": "A asm.js version of Skia's PathOps toolkit",
"main": "bin/pathkit.js",
"homepage": "https://github.com/google/skia/tree/master/modules/pathkit",
diff --git a/modules/pathkit/npm-wasm/README.md b/modules/pathkit/npm-wasm/README.md
index 571bcfa..815e417 100644
--- a/modules/pathkit/npm-wasm/README.md
+++ b/modules/pathkit/npm-wasm/README.md
@@ -5,7 +5,7 @@
<script src="/node_modules/pathkit-wasm/bin/pathkit.js"></script>
PathKitInit({
locateFile: (file) => '/node_modules/pathkit-wasm/bin/'+file,
- }).then((PathKit) => {
+ }).ready().then((PathKit) => {
// Code goes here using PathKit
});
@@ -14,7 +14,7 @@
is used to tell the JS loader where to find the .wasm file. By default, it will
look for /pathkit.wasm, so if this is not the case, use `locateFile` to configure
this properly.
-The `PathKit` object returned through the .then() callback is fully loaded and ready to use.
+The `PathKit` object returned upon resolution of the .ready() Promise is fully loaded and ready to use.
See the [API page](https://skia.org/user/modules/pathkit) and
[example.html](https://github.com/google/skia/blob/master/modules/pathkit/npm-wasm/example.html)
@@ -29,7 +29,7 @@
In the JS code, use require():
const PathKitInit = require('pathkit-wasm/bin/pathkit.js')
- PathKitInit().then((PathKit) => {
+ PathKitInit().ready().then((PathKit) => {
// Code goes here using PathKit
})
diff --git a/modules/pathkit/npm-wasm/example.html b/modules/pathkit/npm-wasm/example.html
index 488f6ec..d7c2469 100644
--- a/modules/pathkit/npm-wasm/example.html
+++ b/modules/pathkit/npm-wasm/example.html
@@ -53,7 +53,7 @@
PathKitInit({
locateFile: (file) => '/node_modules/pathkit-wasm/bin/'+file,
- }).then((PathKit) => {
+ }).ready().then((PathKit) => {
window.PathKit = PathKit;
OutputsExample(PathKit);
Path2DExample(PathKit);
diff --git a/modules/pathkit/npm-wasm/package.json b/modules/pathkit/npm-wasm/package.json
index ef70741..a09c0b3 100644
--- a/modules/pathkit/npm-wasm/package.json
+++ b/modules/pathkit/npm-wasm/package.json
@@ -1,6 +1,6 @@
{
"name": "pathkit-wasm",
- "version": "0.5.0",
+ "version": "0.5.1",
"description": "A WASM version of Skia's PathOps toolkit",
"main": "bin/pathkit.js",
"homepage": "https://github.com/google/skia/tree/master/modules/pathkit",
diff --git a/modules/pathkit/ready.js b/modules/pathkit/ready.js
new file mode 100644
index 0000000..6f8d64a
--- /dev/null
+++ b/modules/pathkit/ready.js
@@ -0,0 +1,14 @@
+// See https://github.com/kripken/emscripten/issues/5820#issuecomment-385722568
+// for context on why the .then() that comes with Module breaks things (e.g. infinite loops)
+// and why the below fixes it.
+Module['ready'] = function() {
+ return new Promise(function (resolve, reject) {
+ delete Module['then'];
+ Module['onAbort'] = reject;
+ addOnPostRun(function () {
+ resolve(Module)
+ });
+ });
+}
+// TODO(kjlubick): Shut .then() entirely off in 0.6.0 by uncommenting below.
+// delete Module['then'];
\ No newline at end of file
diff --git a/modules/pathkit/tests/effects.spec.js b/modules/pathkit/tests/effects.spec.js
index cf1e1d5..1ba372b 100644
--- a/modules/pathkit/tests/effects.spec.js
+++ b/modules/pathkit/tests/effects.spec.js
@@ -8,7 +8,7 @@
} else {
PathKitInit({
locateFile: (file) => '/pathkit/'+file,
- }).then((_PathKit) => {
+ }).ready().then((_PathKit) => {
PathKit = _PathKit;
resolve();
});
diff --git a/modules/pathkit/tests/path.spec.js b/modules/pathkit/tests/path.spec.js
index 7ee1aad..66bff79 100644
--- a/modules/pathkit/tests/path.spec.js
+++ b/modules/pathkit/tests/path.spec.js
@@ -8,7 +8,7 @@
} else {
PathKitInit({
locateFile: (file) => '/pathkit/'+file,
- }).then((_PathKit) => {
+ }).ready().then((_PathKit) => {
PathKit = _PathKit;
resolve();
});
diff --git a/modules/pathkit/tests/path2d.spec.js b/modules/pathkit/tests/path2d.spec.js
index a1bc763..6d505b7 100644
--- a/modules/pathkit/tests/path2d.spec.js
+++ b/modules/pathkit/tests/path2d.spec.js
@@ -9,7 +9,7 @@
} else {
PathKitInit({
locateFile: (file) => '/pathkit/'+file,
- }).then((_PathKit) => {
+ }).ready().then((_PathKit) => {
PathKit = _PathKit;
resolve();
});
diff --git a/modules/pathkit/tests/pathops.spec.js b/modules/pathkit/tests/pathops.spec.js
index 927719a..55371b0 100644
--- a/modules/pathkit/tests/pathops.spec.js
+++ b/modules/pathkit/tests/pathops.spec.js
@@ -84,7 +84,7 @@
} else {
PathKitInit({
locateFile: (file) => '/pathkit/'+file,
- }).then((_PathKit) => {
+ }).ready().then((_PathKit) => {
PathKit = _PathKit;
PATHOP_MAP = {
'kIntersect_SkPathOp': PathKit.PathOp.INTERSECT,
diff --git a/modules/pathkit/tests/svg.spec.js b/modules/pathkit/tests/svg.spec.js
index ad9e6df..577d41b 100644
--- a/modules/pathkit/tests/svg.spec.js
+++ b/modules/pathkit/tests/svg.spec.js
@@ -8,7 +8,7 @@
} else {
PathKitInit({
locateFile: (file) => '/pathkit/'+file,
- }).then((_PathKit) => {
+ }).ready().then((_PathKit) => {
PathKit = _PathKit;
resolve();
});
diff --git a/modules/pathkit/tests/util.spec.js b/modules/pathkit/tests/util.spec.js
index 92981b3..1423d9f 100644
--- a/modules/pathkit/tests/util.spec.js
+++ b/modules/pathkit/tests/util.spec.js
@@ -9,7 +9,7 @@
} else {
PathKitInit({
locateFile: (file) => '/pathkit/'+file,
- }).then((_PathKit) => {
+ }).ready().then((_PathKit) => {
PathKit = _PathKit;
resolve();
});