test-asmjs.cpp (1113B)
1 #include "gdb-tests.h" 2 #include "js/CompilationAndEvaluation.h" 3 #include "js/CompileOptions.h" 4 #include "js/RootingAPI.h" 5 #include "js/SourceText.h" 6 #include "js/Value.h" 7 #include "mozilla/Utf8.h" 8 #include "util/Text.h" 9 10 #include <string.h> 11 12 FRAGMENT(asmjs, segfault) { 13 constexpr unsigned line0 = __LINE__; 14 static const char chars[] = 15 "function f(glob, ffi, heap) {\n" 16 " \"use asm\";\n" 17 " var f32 = new glob.Float32Array(heap);\n" 18 " function g(n) {\n" 19 " n = n | 0;\n" 20 " return +f32[n>>2];\n" 21 " }\n" 22 " return g;\n" 23 "}\n" 24 "\n" 25 "var func = f(this, null, new ArrayBuffer(0x10000));\n" 26 "func(0x10000 << 2);\n" 27 "'ok'\n"; 28 29 JS::CompileOptions opts(cx); 30 opts.setFileAndLine(__FILE__, line0 + 1); 31 opts.setAsmJSOption(JS::AsmJSOption::Enabled); 32 33 JS::SourceText<mozilla::Utf8Unit> srcBuf; 34 JS::Rooted<JS::Value> rval(cx); 35 36 bool ok = 37 srcBuf.init(cx, chars, js_strlen(chars), JS::SourceOwnership::Borrowed) && 38 JS::Evaluate(cx, opts, srcBuf, &rval); 39 40 breakpoint(); 41 42 use(ok); 43 use(rval); 44 }