Bug 1344265 - Fix OOM bug in newExternalString testing function. r=bbouvier a=test-only
authorJan de Mooij <jdemooij@mozilla.com>
Tue, 14 Mar 2017 15:00:43 +0100
changeset 379090 6bd7ff837fdb04cbd40cbcb4eb5439abae86cfc5
parent 379089 b29177eab57933cadcfc09a3c9dad7d3fa67165d
child 379091 5674d54cd39e3b37ae8ab8bcff53981bed292995
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbouvier, test-only
bugs1344265
milestone53.0
Bug 1344265 - Fix OOM bug in newExternalString testing function. r=bbouvier a=test-only
js/src/builtin/TestingFunctions.cpp
js/src/jit-test/tests/basic/bug1344265.js
--- a/js/src/builtin/TestingFunctions.cpp
+++ b/js/src/builtin/TestingFunctions.cpp
@@ -1262,17 +1262,20 @@ NewExternalString(JSContext* cx, unsigne
     if (args.length() != 1 || !args[0].isString()) {
         JS_ReportErrorASCII(cx, "newExternalString takes exactly one string argument.");
         return false;
     }
 
     RootedString str(cx, args[0].toString());
     size_t len = str->length();
 
-    UniqueTwoByteChars buf(js_pod_malloc<char16_t>(len));
+    UniqueTwoByteChars buf(cx->pod_malloc<char16_t>(len));
+    if (!buf)
+        return false;
+
     if (!JS_CopyStringChars(cx, mozilla::Range<char16_t>(buf.get(), len), str))
         return false;
 
     JSString* res = JS_NewExternalString(cx, buf.get(), len, &ExternalStringFinalizer);
     if (!res)
         return false;
 
     mozilla::Unused << buf.release();
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/basic/bug1344265.js
@@ -0,0 +1,5 @@
+// |jit-test| allow-unhandlable-oom; allow-oom
+if (!('oomAfterAllocations' in this))
+    quit();
+oomAfterAllocations(1);
+newExternalString("a");