Switch to malloc/free to be compatible with CanvasKit.Malloc

Inspired by https://skia-review.googlesource.com/c/skia/+/410876

Change-Id: Iaf64f379e74d46b46c795dd5f04db32406b976b4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/411576
Auto-Submit: Mike Reed <reed@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
diff --git a/modules/canvaskit/WasmCommon.h b/modules/canvaskit/WasmCommon.h
index 06e9888..00d9e69 100644
--- a/modules/canvaskit/WasmCommon.h
+++ b/modules/canvaskit/WasmCommon.h
@@ -56,6 +56,9 @@
 
 /**
  *  Gives read access to a JSArray
+ *
+ *  We explicitly use malloc/free (not new/delete) so this can be used with allocations from the JS
+ *  side (ala CanvasKit.Malloc).
  */
 template <typename T> class JSSpan {
 public:
@@ -69,7 +72,7 @@
             data = reinterpret_cast<T*>(src["byteOffset"].as<size_t>());
         } else {
             fOwned = true;
-            data = new T[len];
+            data = static_cast<T*>(sk_malloc_throw(len, sizeof(T)));
 
             // now actually copy into 'data'
             if (src.instanceof(emscripten::val::global(JSArrayType<T>::gName))) {
@@ -86,7 +89,7 @@
 
     ~JSSpan() {
         if (fOwned) {
-            delete[] fSpan.data();
+            sk_free(fSpan.data());
         }
     }