[canvaskit] Disable dynamic execution

This required an update to emscripten, due to there being
a few bug fixes regarding the non-dynamic code and the
Closure compiler/minifier.

Change-Id: Icc922bd98cdd52a6923a9367da3747dac2b897b3
Bug: skia:12795
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/492916
Reviewed-by: Nathaniel Nifong <nifong@google.com>
diff --git a/experimental/skottiekit/compile.sh b/experimental/skottiekit/compile.sh
index 51a5c1b..b93b9ca 100755
--- a/experimental/skottiekit/compile.sh
+++ b/experimental/skottiekit/compile.sh
@@ -69,7 +69,7 @@
 if [[ $@ == *debug* ]]; then
   echo "Building a *${BUILD_TYPE}* Debug build"
   EXTRA_CFLAGS="\"-DSK_DEBUG\""
-  RELEASE_CONF="-O0 --js-opts 0 -s DEMANGLE_SUPPORT=1 -s ASSERTIONS=1 -s GL_ASSERTIONS=1 -g4 \
+  RELEASE_CONF="-O0 --js-opts 0 -sDEMANGLE_SUPPORT=1 -sASSERTIONS=1 -sGL_ASSERTIONS=1 -g4 \
                 --source-map-base /bin/ -DSK_DEBUG --pre-js $BASE_DIR/debug.js"
   BUILD_DIR=${BUILD_DIR:="out/skottiekit_debug"}
 elif [[ $@ == *profiling* ]]; then
@@ -89,12 +89,12 @@
 GN_GPU_FLAGS="\"-DSK_DISABLE_LEGACY_SHADERCONTEXT\","
 WASM_GPU="-lEGL -lGL -lGLESv2 -DSK_SUPPORT_GPU=1 -DSK_GL \
           -DSK_DISABLE_LEGACY_SHADERCONTEXT --pre-js $BASE_DIR/cpu.js --pre-js $BASE_DIR/gpu.js\
-          -s USE_WEBGL2=1"
+          -sUSE_WEBGL2=1"
 if [[ $@ == *cpu* ]]; then
   echo "Using the CPU backend instead of the GPU backend"
   GN_GPU="skia_enable_gpu=false"
   GN_GPU_FLAGS=""
-  WASM_GPU="-DSK_SUPPORT_GPU=0 --pre-js $BASE_DIR/cpu.js -s USE_WEBGL2=0"
+  WASM_GPU="-DSK_SUPPORT_GPU=0 --pre-js $BASE_DIR/cpu.js -sUSE_WEBGL2=0"
 fi
 
 SKOTTIE_LIB="$BUILD_DIR/libskottie.a \
@@ -129,7 +129,7 @@
   cxx=\"${EMCXX}\" \
   ar=\"${EMAR}\" \
   extra_cflags_cc=[\"-frtti\"] \
-  extra_cflags=[\"-s\", \"WARN_UNALIGNED=1\", \"-s\", \"MAIN_MODULE=1\",
+  extra_cflags=[\"-sMAIN_MODULE=1\",
     \"-DSKNX_NO_SIMD\", \"-DSK_DISABLE_AAA\",
     \"-DSK_DISABLE_EFFECT_DESERIALIZATION\",
     \"-DSK_FORCE_8_BYTE_ALIGNMENT\",
@@ -196,14 +196,13 @@
     $BUILD_DIR/libsksg.a \
     $BUILD_DIR/libskshaper.a \
     $BUILD_DIR/libskia.a \
-    -s ALLOW_MEMORY_GROWTH=1 \
-    -s EXPORT_NAME="SkottieKitInit" \
-    -s FORCE_FILESYSTEM=0 \
-    -s FILESYSTEM=0 \
-    -s MODULARIZE=1 \
-    -s NO_EXIT_RUNTIME=1 \
-    -s STRICT=1 \
-    -s INITIAL_MEMORY=128MB \
-    -s WARN_UNALIGNED=1 \
-    -s WASM=1 \
+    -sALLOW_MEMORY_GROWTH=1 \
+    -sEXPORT_NAME="SkottieKitInit" \
+    -sFORCE_FILESYSTEM=0 \
+    -sFILESYSTEM=0 \
+    -sMODULARIZE=1 \
+    -sNO_EXIT_RUNTIME=1 \
+    -sSTRICT=1 \
+    -sINITIAL_MEMORY=128MB \
+    -sWASM=1 \
     -o $BUILD_DIR/skottiekit.js
diff --git a/experimental/wasm-skp-debugger/compile.sh b/experimental/wasm-skp-debugger/compile.sh
index 478d291..afa69be 100755
--- a/experimental/wasm-skp-debugger/compile.sh
+++ b/experimental/wasm-skp-debugger/compile.sh
@@ -25,7 +25,7 @@
 if [[ $@ == *debug* ]]; then
   echo "Building a Debug build"
   EXTRA_CFLAGS="\"-DSK_DEBUG\","
-  RELEASE_CONF="-O0 --js-opts 0 -s DEMANGLE_SUPPORT=1 -s ASSERTIONS=1 -s GL_ASSERTIONS=1 -g3 \
+  RELEASE_CONF="-O0 --js-opts 0 -sDEMANGLE_SUPPORT=1 -sASSERTIONS=1 -sGL_ASSERTIONS=1 -g3 \
                 --source-map-base /node_modules/debugger/bin/ -DSK_DEBUG"
   BUILD_DIR=${BUILD_DIR:="out/debugger_wasm_debug"}
 else
@@ -70,7 +70,7 @@
   cxx=\"${EMCXX}\" \
   ar=\"${EMAR}\" \
   extra_cflags_cc=[\"-frtti\"] \
-  extra_cflags=[\"-s\", \"MAIN_MODULE=1\",
+  extra_cflags=[\"-sMAIN_MODULE=1\",
     \"-DSKNX_NO_SIMD\", \"-DSK_DISABLE_AAA\",
     \"-DSK_FORCE_8_BYTE_ALIGNMENT\",
     \"-DSK_ENABLE_DUMP_GPU\", \"-DSK_DISABLE_LEGACY_SHADERCONTEXT\",
@@ -140,14 +140,14 @@
     $BASE_DIR/debugger_bindings.cpp \
     $BUILD_DIR/libdebugcanvas.a \
     $BUILD_DIR/libskia.a \
-    -s ALLOW_MEMORY_GROWTH=1 \
-    -s EXPORT_NAME="DebuggerInit" \
-    -s FORCE_FILESYSTEM=0 \
-    -s FILESYSTEM=0 \
-    -s MODULARIZE=1 \
-    -s NO_EXIT_RUNTIME=1 \
-    -s STRICT=1 \
-    -s INITIAL_MEMORY=128MB \
-    -s WASM=1 \
-    -s USE_WEBGL2=1 \
+    -sALLOW_MEMORY_GROWTH=1 \
+    -sEXPORT_NAME="DebuggerInit" \
+    -sFORCE_FILESYSTEM=0 \
+    -sFILESYSTEM=0 \
+    -sMODULARIZE=1 \
+    -sNO_EXIT_RUNTIME=1 \
+    -sSTRICT=1 \
+    -sINITIAL_MEMORY=128MB \
+    -sWASM=1 \
+    -sUSE_WEBGL2=1 \
     -o $BUILD_DIR/debugger.js
diff --git a/infra/bots/recipe_modules/build/canvaskit.py b/infra/bots/recipe_modules/build/canvaskit.py
index dba17a7..eb8dca9 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:2.0.20_v1'
+DOCKER_IMAGE = 'gcr.io/skia-public/canvaskit-emsdk:3.1.3_v1'
 INNER_BUILD_SCRIPT = '/SRC/skia/infra/canvaskit/build_canvaskit.sh'
 
 
diff --git a/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian10-EMCC-asmjs-Debug-PathKit.json b/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian10-EMCC-asmjs-Debug-PathKit.json
index 760760b..0f40821 100644
--- a/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian10-EMCC-asmjs-Debug-PathKit.json
+++ b/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian10-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-base:2.0.20_v1",
+      "gcr.io/skia-public/emsdk-base:3.1.3_v1",
       "/SRC/skia/infra/pathkit/build_pathkit.sh",
       "debug",
       "asm.js"
diff --git a/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian10-EMCC-asmjs-Release-PathKit.json b/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian10-EMCC-asmjs-Release-PathKit.json
index c35f9bc..40c9cb0 100644
--- a/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian10-EMCC-asmjs-Release-PathKit.json
+++ b/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian10-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-base:2.0.20_v1",
+      "gcr.io/skia-public/emsdk-base:3.1.3_v1",
       "/SRC/skia/infra/pathkit/build_pathkit.sh",
       "asm.js"
     ],
diff --git a/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian10-EMCC-wasm-Debug-CanvasKit.json b/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian10-EMCC-wasm-Debug-CanvasKit.json
index 3eb5b89..9b3fd77 100644
--- a/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian10-EMCC-wasm-Debug-CanvasKit.json
+++ b/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian10-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:2.0.20_v1",
+      "gcr.io/skia-public/canvaskit-emsdk:3.1.3_v1",
       "/SRC/skia/infra/canvaskit/build_canvaskit.sh",
       "debug"
     ],
diff --git a/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian10-EMCC-wasm-Debug-PathKit.json b/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian10-EMCC-wasm-Debug-PathKit.json
index b8c9d5f..8c1c20d 100644
--- a/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian10-EMCC-wasm-Debug-PathKit.json
+++ b/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian10-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-base:2.0.20_v1",
+      "gcr.io/skia-public/emsdk-base:3.1.3_v1",
       "/SRC/skia/infra/pathkit/build_pathkit.sh",
       "debug"
     ],
diff --git a/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian10-EMCC-wasm-Release-CanvasKit_CPU.json b/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian10-EMCC-wasm-Release-CanvasKit_CPU.json
index 3c0a9a0..8ca865e 100644
--- a/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian10-EMCC-wasm-Release-CanvasKit_CPU.json
+++ b/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian10-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:2.0.20_v1",
+      "gcr.io/skia-public/canvaskit-emsdk:3.1.3_v1",
       "/SRC/skia/infra/canvaskit/build_canvaskit.sh",
       "cpu"
     ],
diff --git a/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian10-EMCC-wasm-Release-PathKit.json b/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian10-EMCC-wasm-Release-PathKit.json
index 79354aa..1431b07 100644
--- a/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian10-EMCC-wasm-Release-PathKit.json
+++ b/infra/bots/recipe_modules/build/examples/full.expected/Build-Debian10-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-base:2.0.20_v1",
+      "gcr.io/skia-public/emsdk-base:3.1.3_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 513fc8d..a3a20a6 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-base:2.0.20_v1'
+DOCKER_IMAGE = 'gcr.io/skia-public/emsdk-base:3.1.3_v1'
 INNER_BUILD_SCRIPT = '/SRC/skia/infra/pathkit/build_pathkit.sh'
 
 def compile_fn(api, checkout_root, _ignore):
diff --git a/infra/bots/task_drivers/compile_wasm_gm_tests/compile_wasm_gm_tests.go b/infra/bots/task_drivers/compile_wasm_gm_tests/compile_wasm_gm_tests.go
index 4704fa4..ae9badc 100644
--- a/infra/bots/task_drivers/compile_wasm_gm_tests/compile_wasm_gm_tests.go
+++ b/infra/bots/task_drivers/compile_wasm_gm_tests/compile_wasm_gm_tests.go
@@ -20,7 +20,7 @@
 	"go.skia.org/infra/task_driver/go/td"
 )
 
-const dockerImage = "gcr.io/skia-public/canvaskit-emsdk:2.0.10_v2"
+const dockerImage = "gcr.io/skia-public/canvaskit-emsdk:3.1.3_v1"
 const innerBuildScript = "/SRC/infra/canvaskit/build_gmtests.sh"
 
 func main() {
diff --git a/infra/canvaskit/docker/Makefile b/infra/canvaskit/docker/Makefile
index d0840fc..926746d 100644
--- a/infra/canvaskit/docker/Makefile
+++ b/infra/canvaskit/docker/Makefile
@@ -1,4 +1,4 @@
-EMSDK_VERSION=2.0.20_v1
+EMSDK_VERSION=3.1.3_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 93b80f2..df73f1e 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
+# with anything needed to build CanvasKit
 
-FROM gcr.io/skia-public/emsdk-base:2.0.20_v1
+FROM gcr.io/skia-public/emsdk-base:3.1.3_v1
 
 RUN apt-get update && apt-get upgrade -y && apt-get install -y \
   libfreetype6-dev
diff --git a/infra/wasm-common/docker/Makefile b/infra/wasm-common/docker/Makefile
index 0cd0be8..8e01d5a 100644
--- a/infra/wasm-common/docker/Makefile
+++ b/infra/wasm-common/docker/Makefile
@@ -1,4 +1,4 @@
-EMSDK_VERSION=2.0.20_v1
+EMSDK_VERSION=3.1.3_v1
 
 # Can check CHROME_VERSION with
 # docker run karma-chrome-tests /usr/bin/google-chrome-stable --version
diff --git a/infra/wasm-common/docker/emsdk-base/Dockerfile b/infra/wasm-common/docker/emsdk-base/Dockerfile
index 15e7b08..3e15d12 100644
--- a/infra/wasm-common/docker/emsdk-base/Dockerfile
+++ b/infra/wasm-common/docker/emsdk-base/Dockerfile
@@ -1,4 +1,4 @@
-FROM emscripten/emsdk:2.0.20
+FROM emscripten/emsdk:3.1.3
 
 RUN apt update && apt install -y python
 
diff --git a/modules/canvaskit/BUILD.bazel b/modules/canvaskit/BUILD.bazel
index 3020c4f..4165028 100644
--- a/modules/canvaskit/BUILD.bazel
+++ b/modules/canvaskit/BUILD.bazel
@@ -16,6 +16,7 @@
     "-sWASM",
     "-sMAX_WEBGL_VERSION=2",
     "-sFORCE_FILESYSTEM=0",
+    "-sDYNAMIC_EXECUTION=0",
     "-sFILESYSTEM=0",
 ]
 
diff --git a/modules/canvaskit/CHANGELOG.md b/modules/canvaskit/CHANGELOG.md
index 6ee88c1..346d556 100644
--- a/modules/canvaskit/CHANGELOG.md
+++ b/modules/canvaskit/CHANGELOG.md
@@ -15,6 +15,8 @@
  - Surface factories always produce a surface with an attached color space. Specifying `null` to
    `CanvasKit.MakeWebGLCanvasSurface` or calling any factory that does not take a color space
    will now create a surface with a color space of `CanvasKit.ColorSpace.SRGB`.
+ - We now build/ship with emscripten 3.1.3.
+ - Internal calls no longer use dynamic dispatch (skbug.com/12795).
 
 ### Fixed
  - Supplying textures via `Surface.makeImageFromTextureSource` should not cause issues with
diff --git a/modules/canvaskit/README.md b/modules/canvaskit/README.md
index 3d5495c..dfc5226 100644
--- a/modules/canvaskit/README.md
+++ b/modules/canvaskit/README.md
@@ -15,8 +15,8 @@
 
 Be sure to both install **and** activate the correct version. For example:
 ```
-    ./emsdk install 2.0.20
-    ./emsdk activate 2.0.20
+    ./emsdk install 3.1.3
+    ./emsdk activate 3.1.3
 ```
 
 This document also assumes you have followed the instructions to download Skia and its deps
@@ -61,13 +61,13 @@
 make test-continuous
 ```
 
-This reads karma.conf.js, and opens a chrome browser and begins running all the test
+This reads karma.conf.js, and opens a Chrome browser and begins running all the test
 in `test/` it will detect changes to the tests in that directory and automatically
-run again, however it will automatically rebuild and reload canvaskit. Closing the
+run again, however it will automatically rebuild and reload CanvasKit. Closing the
 chrome window will just cause it to re-opened. Kill the karma process to stop continuous
 monitoring for changes.
 
-The tests are run with whichever build of canvaskit you last made. be sure to also
+The tests are run with whichever build of CanvasKit you last made. be sure to also
 test with `release`, `debug_cpu`, and `release_cpu`. testing with release builds will
 expose problems in closure compilation and usually forgotten externs.
 
@@ -95,7 +95,7 @@
 
 ## Testing from Gerrit
 
-When submitting a CL in gerrit, click "choose tryjobs" and type canvaskit to filter them.
+When submitting a CL in gerrit, click "choose tryjobs" and type CanvasKit to filter them.
 select all of them, which at the time of this writing is four jobs, for each combination
 of perf/test gpu/cpu.
 
diff --git a/modules/canvaskit/compile.sh b/modules/canvaskit/compile.sh
index 8932b5e..30ccd77 100755
--- a/modules/canvaskit/compile.sh
+++ b/modules/canvaskit/compile.sh
@@ -39,7 +39,7 @@
 if [[ $@ == *debug* ]]; then
   echo "Building a Debug build"
   EXTRA_CFLAGS="\"-DSK_DEBUG\","
-  RELEASE_CONF="-O0 --js-opts 0 -s DEMANGLE_SUPPORT=1 -s ASSERTIONS=1 -s GL_ASSERTIONS=1 -g3 \
+  RELEASE_CONF="-O0 --js-opts 0 -sDEMANGLE_SUPPORT=1 -sASSERTIONS=1 -sGL_ASSERTIONS=1 -g3 \
                 --source-map-base /node_modules/canvaskit/bin/ -DSK_DEBUG --pre-js $BASE_DIR/debug.js"
   BUILD_DIR=${BUILD_DIR:="out/canvaskit_wasm_debug"}
 elif [[ $@ == *profiling* ]]; then
@@ -67,12 +67,12 @@
 GN_GPU_FLAGS="\"-DSK_DISABLE_LEGACY_SHADERCONTEXT\","
 WASM_GPU="-lGL -DSK_SUPPORT_GPU=1 -DSK_GL \
           -DSK_DISABLE_LEGACY_SHADERCONTEXT --pre-js $BASE_DIR/cpu.js --pre-js $BASE_DIR/gpu.js\
-          -s USE_WEBGL2=1"
+          -sUSE_WEBGL2=1"
 if [[ $@ == *cpu* ]]; then
   echo "Using the CPU backend instead of the GPU backend"
   GN_GPU="skia_enable_gpu=false"
   GN_GPU_FLAGS=""
-  WASM_GPU="-DSK_SUPPORT_GPU=0 -DSK_ENABLE_SKSL --pre-js $BASE_DIR/cpu.js -s USE_WEBGL2=0"
+  WASM_GPU="-DSK_SUPPORT_GPU=0 -DSK_ENABLE_SKSL --pre-js $BASE_DIR/cpu.js -sUSE_WEBGL2=0"
 fi
 
 SKP_JS="--pre-js $BASE_DIR/skp.js"
@@ -285,7 +285,7 @@
   --args="cc=\"${EMCC}\" \
   cxx=\"${EMCXX}\" \
   ar=\"${EMAR}\" \
-  extra_cflags=[\"-s\", \"WARN_UNALIGNED=1\", \"-s\", \"MAIN_MODULE=1\",
+  extra_cflags=[\"-s\", \"MAIN_MODULE=1\",
     \"-DSKNX_NO_SIMD\", \"-DSK_DISABLE_AAA\",
     \"-DSK_FORCE_8_BYTE_ALIGNMENT\",
     ${GN_GPU_FLAGS}
@@ -344,14 +344,6 @@
 
 echo "Generating final wasm"
 
-# Disable '-s STRICT=1' outside of Linux until
-# https://github.com/emscripten-core/emscripten/issues/12118 is resovled.
-STRICTNESS="-s STRICT=1"
-if [[ `uname` != "Linux" ]]; then
-  echo "Disabling '-s STRICT=1'. See: https://github.com/emscripten-core/emscripten/issues/12118"
-  STRICTNESS=""
-fi
-
 # Emscripten prefers that the .a files go last in order, otherwise, it
 # may drop symbols that it incorrectly thinks aren't used. One day,
 # Emscripten will use LLD, which may relax this requirement.
@@ -403,15 +395,16 @@
     $SHAPER_LIB \
     $BUILD_DIR/libskia.a \
     $BUILTIN_FONT \
-    -s LLD_REPORT_UNDEFINED \
-    -s ALLOW_MEMORY_GROWTH=1 \
-    -s EXPORT_NAME="CanvasKitInit" \
-    -s EXPORTED_FUNCTIONS=['_malloc','_free'] \
-    -s FORCE_FILESYSTEM=0 \
-    -s FILESYSTEM=0 \
-    -s MODULARIZE=1 \
-    -s NO_EXIT_RUNTIME=1 \
-    -s INITIAL_MEMORY=128MB \
-    -s WASM=1 \
-    $STRICTNESS \
+    -sLLD_REPORT_UNDEFINED \
+    -sALLOW_MEMORY_GROWTH=1 \
+    -sEXPORT_NAME="CanvasKitInit" \
+    -sEXPORTED_FUNCTIONS=['_malloc','_free'] \
+    -sFORCE_FILESYSTEM=0 \
+    -sFILESYSTEM=0 \
+    -sMODULARIZE=1 \
+    -sNO_EXIT_RUNTIME=1 \
+    -sDYNAMIC_EXECUTION=0 \
+    -sINITIAL_MEMORY=128MB \
+    -sWASM=1 \
+    -sSTRICT=1 \
     -o $BUILD_DIR/canvaskit.js
diff --git a/modules/canvaskit/compile_gm.sh b/modules/canvaskit/compile_gm.sh
index 820152a..656b484 100755
--- a/modules/canvaskit/compile_gm.sh
+++ b/modules/canvaskit/compile_gm.sh
@@ -29,7 +29,7 @@
   echo "Building a Debug build"
   DEBUG=true
   EXTRA_CFLAGS="\"-DSK_DEBUG\", \"-DGR_TEST_UTILS\", "
-  RELEASE_CONF="-O1 --js-opts 0 -s DEMANGLE_SUPPORT=1 -frtti -s ASSERTIONS=1 -s GL_ASSERTIONS=1 -g \
+  RELEASE_CONF="-O1 --js-opts 0 -sDEMANGLE_SUPPORT=1 -frtti -sASSERTIONS=1 -sGL_ASSERTIONS=1 -g \
                 -DSK_DEBUG --pre-js $BASE_DIR/debug.js"
   BUILD_DIR=${BUILD_DIR:="out/wasm_gm_tests_debug"}
 else
@@ -52,7 +52,7 @@
 GN_GPU_FLAGS="\"-DSK_DISABLE_LEGACY_SHADERCONTEXT\","
 WASM_GPU="-lGL -DSK_SUPPORT_GPU=1 -DSK_GL \
           -DSK_DISABLE_LEGACY_SHADERCONTEXT --pre-js $BASE_DIR/cpu.js --pre-js $BASE_DIR/gpu.js\
-          -s USE_WEBGL2=1"
+          -sUSE_WEBGL2=1"
 
 GM_LIB="$BUILD_DIR/libgm_wasm.a"
 
@@ -89,7 +89,7 @@
   cxx=\"${EMCXX}\" \
   ar=\"${EMAR}\" \
   extra_cflags_cc=[\"-frtti\"] \
-  extra_cflags=[\"-s\", \"WARN_UNALIGNED=1\", \"-s\", \"MAIN_MODULE=1\",
+  extra_cflags=[\"-sMAIN_MODULE=1\",
     \"-DSKNX_NO_SIMD\", \"-DSK_DISABLE_AAA\",
     \"-DSK_FORCE_8_BYTE_ALIGNMENT\",
     ${GN_GPU_FLAGS}
@@ -161,14 +161,6 @@
 -DSK_UNICODE_AVAILABLE \
 -DSK_ENABLE_SVG"
 
-# Disable '-s STRICT=1' outside of Linux until
-# https://github.com/emscripten-core/emscripten/issues/12118 is resovled.
-STRICTNESS="-s STRICT=1"
-if [[ `uname` != "Linux" ]]; then
-  echo "Disabling '-s STRICT=1'. See: https://github.com/emscripten-core/emscripten/issues/12118"
-  STRICTNESS=""
-fi
-
 GMS_TO_BUILD="gm/*.cpp"
 TESTS_TO_BUILD="tests/*.cpp"
 
@@ -234,15 +226,15 @@
     $BUILD_DIR/libsvg.a \
     $BUILD_DIR/libskia.a \
     $BUILTIN_FONT \
-    -s LLD_REPORT_UNDEFINED \
-    -s ALLOW_MEMORY_GROWTH=1 \
-    -s EXPORT_NAME="InitWasmGMTests" \
-    -s EXPORTED_FUNCTIONS=['_malloc','_free'] \
-    -s FORCE_FILESYSTEM=1 \
-    -s FILESYSTEM=1 \
-    -s MODULARIZE=1 \
-    -s NO_EXIT_RUNTIME=1 \
-    -s INITIAL_MEMORY=256MB \
-    -s WASM=1 \
-    $STRICTNESS \
+    -sLLD_REPORT_UNDEFINED \
+    -sALLOW_MEMORY_GROWTH=1 \
+    -sEXPORT_NAME="InitWasmGMTests" \
+    -sEXPORTED_FUNCTIONS=['_malloc','_free'] \
+    -sFORCE_FILESYSTEM=1 \
+    -sFILESYSTEM=1 \
+    -sMODULARIZE=1 \
+    -sNO_EXIT_RUNTIME=1 \
+    -sINITIAL_MEMORY=256MB \
+    -sWASM=1 \
+    -sSTRICT=1 \
     -o $BUILD_DIR/wasm_gm_tests.js
diff --git a/modules/pathkit/CHANGELOG.md b/modules/pathkit/CHANGELOG.md
index ce93034..44b84a8 100644
--- a/modules/pathkit/CHANGELOG.md
+++ b/modules/pathkit/CHANGELOG.md
@@ -7,7 +7,8 @@
 ## [Unreleased]
 
 ### Changed
- - Now compile with emsdk 2.0.20
+ - Now compile with emsdk 3.1.3
+ - Internal calls no longer use dynamic dispatch (skbug.com/12795)
 
 ## [0.7.0] 2019-07-20
 
diff --git a/modules/pathkit/compile.sh b/modules/pathkit/compile.sh
index d454966..0e97a81 100755
--- a/modules/pathkit/compile.sh
+++ b/modules/pathkit/compile.sh
@@ -49,7 +49,7 @@
 # Use -O0 for larger builds (but generally quicker)
 # Use -Oz for (much slower, but smaller/faster) production builds
 export EMCC_CLOSURE_ARGS="--externs $BASE_DIR/externs.js "
-RELEASE_CONF="-Oz --closure 1 -s EVAL_CTORS=1 -DSK_RELEASE"
+RELEASE_CONF="-Oz --closure 1 -DSK_RELEASE"
 # It is very important for the -DSK_RELEASE/-DSK_DEBUG to match on the libskia.a, otherwise
 # things like SKDEBUGCODE are sometimes compiled in and sometimes not, which can cause headaches
 # like sizeof() mismatching between .cpp files and .h files.
@@ -60,13 +60,13 @@
 elif [[ $@ == *debug* ]]; then
   echo "Building a Debug build"
   EXTRA_CFLAGS="\"-DSK_DEBUG\""
-  RELEASE_CONF="-O0 --js-opts 0 -s SAFE_HEAP=1 -s ASSERTIONS=1 -g3 -DPATHKIT_TESTING -DSK_DEBUG"
+  RELEASE_CONF="-O0 --js-opts 0 -sSAFE_HEAP=1 -sASSERTIONS=1 -g3 -DPATHKIT_TESTING -DSK_DEBUG"
 fi
 
-WASM_CONF="-s WASM=1"
+WASM_CONF="-sWASM=1"
 if [[ $@ == *asm.js* ]]; then
   echo "Building with asm.js instead of WASM"
-  WASM_CONF="-s WASM=0 -s ALLOW_MEMORY_GROWTH=1"
+  WASM_CONF="-sWASM=0 -sALLOW_MEMORY_GROWTH=1"
 fi
 
 OUTPUT="-o $BUILD_DIR/pathkit.js"
@@ -93,8 +93,8 @@
   --args="cc=\"${EMCC}\" \
   cxx=\"${EMCXX}\" \
   ar=\"${EMAR}\" \
-  extra_cflags=[\"-s\", \"WARN_UNALIGNED=1\",
-    \"-s\", \"MAIN_MODULE=1\",
+  extra_cflags=[
+    \"-sMAIN_MODULE=1\",
     ${EXTRA_CFLAGS}
   ] \
   is_debug=false \
@@ -115,12 +115,13 @@
 --pre-js $BASE_DIR/chaining.js \
 -fno-rtti -fno-exceptions -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 \
 $WASM_CONF \
--s ERROR_ON_UNDEFINED_SYMBOLS=1 \
--s EXPORT_NAME="PathKitInit" \
--s MODULARIZE=1 \
--s NO_EXIT_RUNTIME=1 \
--s NO_FILESYSTEM=1 \
--s STRICT=1 \
+-sERROR_ON_UNDEFINED_SYMBOLS=1 \
+-sEXPORT_NAME="PathKitInit" \
+-sMODULARIZE=1 \
+-sNO_EXIT_RUNTIME=1 \
+-sNO_FILESYSTEM=1 \
+-sDYNAMIC_EXECUTION=0 \
+-sSTRICT=1 \
 $OUTPUT \
 $BASE_DIR/pathkit_wasm_bindings.cpp \
 ${BUILD_DIR}/libpathkit.a