[canvaskit] Update to build with emscripten 1.38.47

Bug: skia:9052
Change-Id: Ic1aec2c9b8ace556f5b77862582894f59fd26b64
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/247302
Reviewed-by: Kevin Lubick <kjlubick@google.com>
diff --git a/docker/skia-wasm-release/Dockerfile b/docker/skia-wasm-release/Dockerfile
index cd133e1..5dac8fc 100644
--- a/docker/skia-wasm-release/Dockerfile
+++ b/docker/skia-wasm-release/Dockerfile
@@ -1,5 +1,5 @@
 # Dockerfile for building the WASM libraries used by jsfiddle.skia.org and debugger.skia.org
-FROM gcr.io/skia-public/emsdk-release:prod as builder
+FROM gcr.io/skia-public/emsdk-base:prod as builder
 
 RUN cd /tmp \
   && git clone 'https://chromium.googlesource.com/chromium/tools/depot_tools.git' \
diff --git a/infra/bots/recipe_modules/build/canvaskit.py b/infra/bots/recipe_modules/build/canvaskit.py
index d93634d..0a8f186 100644
--- a/infra/bots/recipe_modules/build/canvaskit.py
+++ b/infra/bots/recipe_modules/build/canvaskit.py
@@ -2,7 +2,7 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
-DOCKER_IMAGE = 'gcr.io/skia-public/canvaskit-emsdk:1.38.27_v1'
+DOCKER_IMAGE = 'gcr.io/skia-public/canvaskit-emsdk:1.38.47_v1'
 INNER_BUILD_SCRIPT = '/SRC/skia/infra/canvaskit/build_canvaskit.sh'
 
 
diff --git a/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian9-EMCC-asmjs-Debug-PathKit.json b/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian9-EMCC-asmjs-Debug-PathKit.json
index f29a476..261f879 100644
--- a/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian9-EMCC-asmjs-Debug-PathKit.json
+++ b/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian9-EMCC-asmjs-Debug-PathKit.json
@@ -23,7 +23,7 @@
       "[START_DIR]/cache/work:/SRC",
       "--volume",
       "[START_DIR]/cache/docker/pathkit:/OUT",
-      "gcr.io/skia-public/emsdk-release:1.38.27_v1",
+      "gcr.io/skia-public/emsdk-base:1.38.47_v1",
       "/SRC/skia/infra/pathkit/build_pathkit.sh",
       "debug",
       "asm.js"
diff --git a/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian9-EMCC-asmjs-Release-PathKit.json b/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian9-EMCC-asmjs-Release-PathKit.json
index f3f601f..f02b193 100644
--- a/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian9-EMCC-asmjs-Release-PathKit.json
+++ b/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian9-EMCC-asmjs-Release-PathKit.json
@@ -23,7 +23,7 @@
       "[START_DIR]/cache/work:/SRC",
       "--volume",
       "[START_DIR]/cache/docker/pathkit:/OUT",
-      "gcr.io/skia-public/emsdk-release:1.38.27_v1",
+      "gcr.io/skia-public/emsdk-base:1.38.47_v1",
       "/SRC/skia/infra/pathkit/build_pathkit.sh",
       "asm.js"
     ],
diff --git a/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian9-EMCC-wasm-Debug-CanvasKit.json b/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian9-EMCC-wasm-Debug-CanvasKit.json
index fd5b351..99b6fea 100644
--- a/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian9-EMCC-wasm-Debug-CanvasKit.json
+++ b/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian9-EMCC-wasm-Debug-CanvasKit.json
@@ -23,7 +23,7 @@
       "[START_DIR]/cache/work:/SRC",
       "--volume",
       "[START_DIR]/cache/docker/canvaskit:/OUT",
-      "gcr.io/skia-public/canvaskit-emsdk:1.38.27_v1",
+      "gcr.io/skia-public/canvaskit-emsdk:1.38.47_v1",
       "/SRC/skia/infra/canvaskit/build_canvaskit.sh",
       "debug"
     ],
diff --git a/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian9-EMCC-wasm-Debug-PathKit.json b/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian9-EMCC-wasm-Debug-PathKit.json
index fb2ad4d..432e6e7 100644
--- a/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian9-EMCC-wasm-Debug-PathKit.json
+++ b/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian9-EMCC-wasm-Debug-PathKit.json
@@ -23,7 +23,7 @@
       "[START_DIR]/cache/work:/SRC",
       "--volume",
       "[START_DIR]/cache/docker/pathkit:/OUT",
-      "gcr.io/skia-public/emsdk-release:1.38.27_v1",
+      "gcr.io/skia-public/emsdk-base:1.38.47_v1",
       "/SRC/skia/infra/pathkit/build_pathkit.sh",
       "debug"
     ],
diff --git a/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian9-EMCC-wasm-Release-CanvasKit_CPU.json b/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian9-EMCC-wasm-Release-CanvasKit_CPU.json
index 6880252..29e50b5 100644
--- a/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian9-EMCC-wasm-Release-CanvasKit_CPU.json
+++ b/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian9-EMCC-wasm-Release-CanvasKit_CPU.json
@@ -23,7 +23,7 @@
       "[START_DIR]/cache/work:/SRC",
       "--volume",
       "[START_DIR]/cache/docker/canvaskit:/OUT",
-      "gcr.io/skia-public/canvaskit-emsdk:1.38.27_v1",
+      "gcr.io/skia-public/canvaskit-emsdk:1.38.47_v1",
       "/SRC/skia/infra/canvaskit/build_canvaskit.sh",
       "cpu"
     ],
diff --git a/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian9-EMCC-wasm-Release-PathKit.json b/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian9-EMCC-wasm-Release-PathKit.json
index aaf19e2..b9c0071 100644
--- a/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian9-EMCC-wasm-Release-PathKit.json
+++ b/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian9-EMCC-wasm-Release-PathKit.json
@@ -23,7 +23,7 @@
       "[START_DIR]/cache/work:/SRC",
       "--volume",
       "[START_DIR]/cache/docker/pathkit:/OUT",
-      "gcr.io/skia-public/emsdk-release:1.38.27_v1",
+      "gcr.io/skia-public/emsdk-base:1.38.47_v1",
       "/SRC/skia/infra/pathkit/build_pathkit.sh"
     ],
     "env": {
diff --git a/infra/bots/recipe_modules/build/pathkit.py b/infra/bots/recipe_modules/build/pathkit.py
index 72e8acc..01acae8 100644
--- a/infra/bots/recipe_modules/build/pathkit.py
+++ b/infra/bots/recipe_modules/build/pathkit.py
@@ -2,7 +2,7 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
-DOCKER_IMAGE = 'gcr.io/skia-public/emsdk-release:1.38.27_v1'
+DOCKER_IMAGE = 'gcr.io/skia-public/emsdk-base:1.38.47_v1'
 INNER_BUILD_SCRIPT = '/SRC/skia/infra/pathkit/build_pathkit.sh'
 
 def compile_fn(api, checkout_root, _ignore):
diff --git a/infra/canvaskit/build_canvaskit.sh b/infra/canvaskit/build_canvaskit.sh
index 74b8a6d..c7dadde 100755
--- a/infra/canvaskit/build_canvaskit.sh
+++ b/infra/canvaskit/build_canvaskit.sh
@@ -4,12 +4,12 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
-# This assumes it is being run inside a docker container of emsdk-release
+# This assumes it is being run inside a docker container of emsdk-base
 # and a Skia checkout has been mounted at /SRC and the output directory
 # is mounted at /OUT
 
 # For example:
-# docker run -v $SKIA_ROOT:/SRC -v $SKIA_ROOT/out/canvaskit:/OUT gcr.io/skia-public/emsdk-release:1.38.16_v1 /SRC/infra/canvaskit/build_canvaskit.sh
+# docker run -v $SKIA_ROOT:/SRC -v $SKIA_ROOT/out/canvaskit:/OUT gcr.io/skia-public/emsdk-base:1.38.47_v1 /SRC/infra/canvaskit/build_canvaskit.sh
 
 set +e
 set -x
diff --git a/infra/canvaskit/docker/Makefile b/infra/canvaskit/docker/Makefile
index 9245d21..453230e 100644
--- a/infra/canvaskit/docker/Makefile
+++ b/infra/canvaskit/docker/Makefile
@@ -1,4 +1,4 @@
-EMSDK_VERSION=1.38.27_v1
+EMSDK_VERSION=1.38.47_v1
 
 publish_canvaskit_emsdk:
 	docker build -t canvaskit-emsdk ./canvaskit-emsdk/
diff --git a/infra/canvaskit/docker/canvaskit-emsdk/Dockerfile b/infra/canvaskit/docker/canvaskit-emsdk/Dockerfile
index 0e3467f..6abd49f 100644
--- a/infra/canvaskit/docker/canvaskit-emsdk/Dockerfile
+++ b/infra/canvaskit/docker/canvaskit-emsdk/Dockerfile
@@ -1,7 +1,7 @@
 # A Docker image that augments the Emscripten SDK Docker image
 # with anything needed to build Canvaskit
 
-FROM gcr.io/skia-public/emsdk-release:1.38.27_v1
+FROM gcr.io/skia-public/emsdk-base:1.38.47_v1
 
 RUN apt-get update && apt-get upgrade -y && apt-get install -y \
   libfreetype6-dev
\ No newline at end of file
diff --git a/infra/cmake/build_skia.sh b/infra/cmake/build_skia.sh
index 6e78dfa..dbd50dc 100755
--- a/infra/cmake/build_skia.sh
+++ b/infra/cmake/build_skia.sh
@@ -4,7 +4,7 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
-# This assumes it is being run inside a docker container of emsdk-release
+# This assumes it is being run inside a docker container of cmake-release
 # and a Skia checkout has been mounted at /SRC and the output directory
 # has been mounted at /OUT
 
diff --git a/infra/pathkit/build_pathkit.sh b/infra/pathkit/build_pathkit.sh
index cb4adb1..ad9ee73 100755
--- a/infra/pathkit/build_pathkit.sh
+++ b/infra/pathkit/build_pathkit.sh
@@ -4,12 +4,12 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
-# This assumes it is being run inside a docker container of emsdk-release
+# This assumes it is being run inside a docker container of emsdk-base
 # and a Skia checkout has been mounted at /SRC and the output directory
 # is mounted at /OUT
 
 # For example:
-# docker run -v $SKIA_ROOT:/SRC -v $SKIA_ROOT/out/dockerpathkit:/OUT gcr.io/skia-public/emsdk-release:1.38.16_v1 /SRC/infra/pathkit/build_pathkit.sh
+# docker run -v $SKIA_ROOT:/SRC -v $SKIA_ROOT/out/dockerpathkit:/OUT gcr.io/skia-public/emsdk-base:1.38.47_v1 /SRC/infra/pathkit/build_pathkit.sh
 
 set +e
 set -x
diff --git a/infra/wasm-common/README.md b/infra/wasm-common/README.md
index 4e7ff25..b2d30b0 100644
--- a/infra/wasm-common/README.md
+++ b/infra/wasm-common/README.md
@@ -1,4 +1,4 @@
 This directory contains docker images that will be run on swarming to
 build/test/perf WASM code.
 
-For docker images that run on Cloud Build, see $SKIA_ROOT/docker.
\ No newline at end of file
+For docker images that run on Cloud Build, see $SKIA_ROOT/docker.
diff --git a/infra/wasm-common/docker/Makefile b/infra/wasm-common/docker/Makefile
index 2af691e..cbdddc8 100644
--- a/infra/wasm-common/docker/Makefile
+++ b/infra/wasm-common/docker/Makefile
@@ -1,15 +1,15 @@
-EMSDK_VERSION=1.38.27_v1
+EMSDK_VERSION=1.38.47_v1
 
 # Can check CHROME_VERSION with
 # docker run karma-chrome-tests /usr/bin/google-chrome-stable --version
 CHROME_VERSION=72.0.3626.121_v1
 
 publish_emsdk_base:
-	docker build --no-cache -t emsdk-release ./emsdk-release/
-	docker tag emsdk-release gcr.io/skia-public/emsdk-release:${EMSDK_VERSION}
-	docker push gcr.io/skia-public/emsdk-release:${EMSDK_VERSION}
-	docker tag emsdk-release gcr.io/skia-public/emsdk-release:prod
-	docker push gcr.io/skia-public/emsdk-release:prod
+	docker build --no-cache -t emsdk-base ./emsdk-base/
+	docker tag emsdk-base gcr.io/skia-public/emsdk-base:${EMSDK_VERSION}
+	docker push gcr.io/skia-public/emsdk-base:${EMSDK_VERSION}
+	docker tag emsdk-base gcr.io/skia-public/emsdk-base:prod
+	docker push gcr.io/skia-public/emsdk-base:prod
 
 publish_karma_chrome_tests:
 	docker build --no-cache -t karma-chrome-tests ./karma-chrome-tests/
diff --git a/infra/wasm-common/docker/README.md b/infra/wasm-common/docker/README.md
index 008eb4b..c2af508 100644
--- a/infra/wasm-common/docker/README.md
+++ b/infra/wasm-common/docker/README.md
@@ -3,7 +3,7 @@
 
 Docker files to ease working with PathKit and WASM.
 
-emsdk-release
+emsdk-base
 ----------
 
 This image has an Emscripten SDK environment that can be used for
@@ -19,11 +19,11 @@
 
 For testing the image locally, the following flow can be helpful:
 
-    docker build -t emsdk-release ./emsdk-release/
+    docker build -t emsdk-base ./emsdk-base/
     # Run bash in it to poke around and make sure things are properly installed
-    docker run -it emsdk-release /bin/bash
+    docker run -it emsdk-base /bin/bash
     # Compile PathKit with the local image
-    docker run -v $SKIA_ROOT:/SRC -v $SKIA_ROOT/out/dockerpathkit:/OUT emsdk-release /SRC/infra/pathkit/build_pathkit.sh
+    docker run -v $SKIA_ROOT:/SRC -v $SKIA_ROOT/out/dockerpathkit:/OUT emsdk-base /SRC/infra/pathkit/build_pathkit.sh
 
 karma-chrome-tests
 ------------------
diff --git a/infra/wasm-common/docker/emsdk-base/Dockerfile b/infra/wasm-common/docker/emsdk-base/Dockerfile
index 592a10c..360691b 100644
--- a/infra/wasm-common/docker/emsdk-base/Dockerfile
+++ b/infra/wasm-common/docker/emsdk-base/Dockerfile
@@ -9,16 +9,15 @@
   default-jre
 
 RUN cd /opt \
-  && git clone https://github.com/juj/emsdk.git
+  && git clone https://github.com/emscripten-core/emsdk.git
 
 WORKDIR /opt/emsdk
 
 RUN ./emsdk update-tags
 
-# These versions were available and worked on my local desktop as of Nov 6 2018.
-RUN ./emsdk install sdk-1.38.27-64bit
+RUN ./emsdk install sdk-1.38.47-64bit
 
-RUN ./emsdk activate sdk-1.38.27-64bit
+RUN ./emsdk activate sdk-1.38.47-64bit
 
 RUN /bin/bash -c "source ./emsdk_env.sh"
 
diff --git a/modules/canvaskit/CHANGELOG.md b/modules/canvaskit/CHANGELOG.md
index 3de0e06..a6d52a5 100644
--- a/modules/canvaskit/CHANGELOG.md
+++ b/modules/canvaskit/CHANGELOG.md
@@ -16,6 +16,7 @@
  - The `no_font` compile option should strip out more dead code related to fonts.
  - and `no_embedded_font` option now allows creating a `SkFontMgr.FromData` instead of
    always having an empty one.
+ - Updated to emscripten 1.38.47
 
 ### Fixed
  - Null terminator bug in draw text - skbug.com/9314
diff --git a/modules/canvaskit/externs.js b/modules/canvaskit/externs.js
index f8419ae..88c4276 100644
--- a/modules/canvaskit/externs.js
+++ b/modules/canvaskit/externs.js
@@ -573,15 +573,15 @@
 
 	// Things Enscriptem adds for us
 
-	/** Represents the heap of the WASM code
-	 * @type {ArrayBuffer}
-	 */
-	buffer: {},
 	/**
 	 * @type {Float32Array}
 	 */
 	HEAPF32: {},
 	/**
+	 * @type {Float64Array}
+	 */
+	HEAPF64: {},
+	/**
 	 * @type {Uint8Array}
 	 */
 	HEAPU8: {},
@@ -590,13 +590,22 @@
 	 */
 	HEAPU16: {},
 	/**
-	 * @type {Int32Array}
-	 */
-	HEAP32: {},
-	/**
 	 * @type {Uint32Array}
 	 */
 	HEAPU32: {},
+	/**
+	 * @type {Int8Array}
+	 */
+	HEAP8: {},
+	/**
+	 * @type {Int16Array}
+	 */
+	HEAP16: {},
+	/**
+	 * @type {Int32Array}
+	 */
+	HEAP32: {},
+
 	_malloc: function() {},
 	_free: function() {},
 	onRuntimeInitialized: function() {},
diff --git a/modules/canvaskit/interface.js b/modules/canvaskit/interface.js
index 4a1cc54..7eea323 100644
--- a/modules/canvaskit/interface.js
+++ b/modules/canvaskit/interface.js
@@ -8,6 +8,11 @@
 CanvasKit.onRuntimeInitialized = function() {
   // All calls to 'this' need to go in externs.js so closure doesn't minify them away.
 
+  // buffer is the underlying ArrayBuffer that is the WASM memory blob.
+  // It was removed from Emscripten proper in https://github.com/emscripten-core/emscripten/pull/8277
+  // but it is convenient to have a reference to, so we add it back in.
+  CanvasKit.buffer = CanvasKit.HEAPU8.buffer;
+
   // Add some helpers for matrices. This is ported from SkMatrix.cpp
   // to save complexity and overhead of going back and forth between
   // C++ and JS layers.
@@ -629,7 +634,7 @@
 
     // The first typed array is just a view into memory. Because we will
     // be free-ing that, we call slice to make a persistent copy.
-    var pixels = new Uint8Array(CanvasKit.HEAPU8.buffer, pptr, len).slice();
+    var pixels = new Uint8Array(CanvasKit.buffer, pptr, len).slice();
     CanvasKit._free(pptr);
     return pixels;
   }
diff --git a/modules/pathkit/CHANGELOG.md b/modules/pathkit/CHANGELOG.md
index 1867982..9a9ff50 100644
--- a/modules/pathkit/CHANGELOG.md
+++ b/modules/pathkit/CHANGELOG.md
@@ -6,7 +6,8 @@
 
 ## [Unreleased]
 
-
+### Changed
+ - Updated to emscripten 1.38.47
 
 ## [0.6.0] 2019-02-25
 
diff --git a/modules/pathkit/Makefile b/modules/pathkit/Makefile
index 31e5f86..be6568c 100644
--- a/modules/pathkit/Makefile
+++ b/modules/pathkit/Makefile
@@ -57,12 +57,12 @@
 	mkdir -p $$SKIA_ROOT/out/dockerbuild
 
 	docker run --rm -v $$SKIA_ROOT:/SRC -v $$SKIA_ROOT/out/dockerbuild:/OUT \
-gcr.io/skia-public/emsdk-release:prod /SRC/infra/pathkit/build_pathkit.sh
+gcr.io/skia-public/emsdk-base:prod /SRC/infra/pathkit/build_pathkit.sh
 	cp ../../out/dockerbuild/pathkit.js   ./npm-wasm/bin/test/pathkit.js
 	cp ../../out/dockerbuild/pathkit.wasm ./npm-wasm/bin/test/pathkit.wasm
 
 	docker run --rm -v $$SKIA_ROOT:/SRC -v $$SKIA_ROOT/out/dockerbuild:/OUT \
-gcr.io/skia-public/emsdk-release:prod /SRC/infra/pathkit/build_pathkit.sh asm.js
+gcr.io/skia-public/emsdk-base:prod /SRC/infra/pathkit/build_pathkit.sh asm.js
 	cp ../../out/dockerbuild/pathkit.js     ./npm-asmjs/bin/test/pathkit.js
 	cp ../../out/dockerbuild/pathkit.js.mem ./npm-asmjs/bin/test/pathkit.js.mem
 
diff --git a/modules/pathkit/compile.sh b/modules/pathkit/compile.sh
index 0f77cad..9f1bdbb 100755
--- a/modules/pathkit/compile.sh
+++ b/modules/pathkit/compile.sh
@@ -115,7 +115,6 @@
 -DSK_DISABLE_READBUFFER=1 \
 -fno-rtti -fno-exceptions -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 \
 $WASM_CONF \
--s ERROR_ON_MISSING_LIBRARIES=1 \
 -s ERROR_ON_UNDEFINED_SYMBOLS=1 \
 -s EXPORT_NAME="PathKitInit" \
 -s MODULARIZE=1 \