mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-31 19:47:32 +09:00
import FIREFOX_52_6_0esr_RELEASE from mozilla-esr52 hg repo
This commit is contained in:
commit
dcd9973243
150858 changed files with 23884658 additions and 0 deletions
1935
dom/asmjscache/AsmJSCache.cpp
Normal file
1935
dom/asmjscache/AsmJSCache.cpp
Normal file
File diff suppressed because it is too large
Load diff
194
dom/asmjscache/AsmJSCache.h
Normal file
194
dom/asmjscache/AsmJSCache.h
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_dom_asmjscache_asmjscache_h
|
||||
#define mozilla_dom_asmjscache_asmjscache_h
|
||||
|
||||
#include "ipc/IPCMessageUtils.h"
|
||||
#include "js/TypeDecls.h"
|
||||
#include "js/Vector.h"
|
||||
#include "jsapi.h"
|
||||
|
||||
class nsIPrincipal;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
namespace ipc {
|
||||
|
||||
class PrincipalInfo;
|
||||
|
||||
} // namespace ipc
|
||||
|
||||
namespace dom {
|
||||
|
||||
namespace quota {
|
||||
class Client;
|
||||
} // namespace quota
|
||||
|
||||
namespace asmjscache {
|
||||
|
||||
class PAsmJSCacheEntryChild;
|
||||
class PAsmJSCacheEntryParent;
|
||||
|
||||
enum OpenMode
|
||||
{
|
||||
eOpenForRead,
|
||||
eOpenForWrite,
|
||||
NUM_OPEN_MODES
|
||||
};
|
||||
|
||||
// Each origin stores a fixed size (kNumEntries) LRU cache of compiled asm.js
|
||||
// modules. Each compiled asm.js module is stored in a separate file with one
|
||||
// extra metadata file that stores the LRU cache and enough information for a
|
||||
// client to pick which cached module's file to open.
|
||||
struct Metadata
|
||||
{
|
||||
static const unsigned kNumEntries = 16;
|
||||
static const unsigned kLastEntry = kNumEntries - 1;
|
||||
|
||||
struct Entry
|
||||
{
|
||||
uint32_t mFastHash;
|
||||
uint32_t mNumChars;
|
||||
uint32_t mFullHash;
|
||||
unsigned mModuleIndex;
|
||||
|
||||
void clear() {
|
||||
mFastHash = -1;
|
||||
mNumChars = -1;
|
||||
mFullHash = -1;
|
||||
}
|
||||
};
|
||||
|
||||
Entry mEntries[kNumEntries];
|
||||
};
|
||||
|
||||
// Parameters specific to opening a cache entry for writing
|
||||
struct WriteParams
|
||||
{
|
||||
int64_t mSize;
|
||||
int64_t mFastHash;
|
||||
int64_t mNumChars;
|
||||
int64_t mFullHash;
|
||||
bool mInstalled;
|
||||
|
||||
WriteParams()
|
||||
: mSize(0),
|
||||
mFastHash(0),
|
||||
mNumChars(0),
|
||||
mFullHash(0),
|
||||
mInstalled(false)
|
||||
{ }
|
||||
};
|
||||
|
||||
// Parameters specific to opening a cache entry for reading
|
||||
struct ReadParams
|
||||
{
|
||||
const char16_t* mBegin;
|
||||
const char16_t* mLimit;
|
||||
|
||||
ReadParams()
|
||||
: mBegin(nullptr),
|
||||
mLimit(nullptr)
|
||||
{ }
|
||||
};
|
||||
|
||||
// Implementation of AsmJSCacheOps, installed for the main JSRuntime by
|
||||
// nsJSEnvironment.cpp and DOM Worker JSRuntimes in RuntimeService.cpp.
|
||||
//
|
||||
// The Open* functions cannot be called directly from AsmJSCacheOps: they take
|
||||
// an nsIPrincipal as the first argument instead of a Handle<JSObject*>. The
|
||||
// caller must map the object to an nsIPrincipal.
|
||||
//
|
||||
// These methods may be called off the main thread and guarantee not to
|
||||
// access the given aPrincipal except on the main thread. In exchange, the
|
||||
// caller must ensure the given principal is alive from when OpenEntryForX is
|
||||
// called to when CloseEntryForX returns.
|
||||
|
||||
bool
|
||||
OpenEntryForRead(nsIPrincipal* aPrincipal,
|
||||
const char16_t* aBegin,
|
||||
const char16_t* aLimit,
|
||||
size_t* aSize,
|
||||
const uint8_t** aMemory,
|
||||
intptr_t *aHandle);
|
||||
void
|
||||
CloseEntryForRead(size_t aSize,
|
||||
const uint8_t* aMemory,
|
||||
intptr_t aHandle);
|
||||
JS::AsmJSCacheResult
|
||||
OpenEntryForWrite(nsIPrincipal* aPrincipal,
|
||||
bool aInstalled,
|
||||
const char16_t* aBegin,
|
||||
const char16_t* aEnd,
|
||||
size_t aSize,
|
||||
uint8_t** aMemory,
|
||||
intptr_t* aHandle);
|
||||
void
|
||||
CloseEntryForWrite(size_t aSize,
|
||||
uint8_t* aMemory,
|
||||
intptr_t aHandle);
|
||||
|
||||
// Called from QuotaManager.cpp:
|
||||
|
||||
quota::Client*
|
||||
CreateClient();
|
||||
|
||||
// Called from ipc/ContentParent.cpp:
|
||||
|
||||
PAsmJSCacheEntryParent*
|
||||
AllocEntryParent(OpenMode aOpenMode, WriteParams aWriteParams,
|
||||
const mozilla::ipc::PrincipalInfo& aPrincipalInfo);
|
||||
|
||||
void
|
||||
DeallocEntryParent(PAsmJSCacheEntryParent* aActor);
|
||||
|
||||
// Called from ipc/ContentChild.cpp:
|
||||
|
||||
void
|
||||
DeallocEntryChild(PAsmJSCacheEntryChild* aActor);
|
||||
|
||||
} // namespace asmjscache
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
namespace IPC {
|
||||
|
||||
template <>
|
||||
struct ParamTraits<mozilla::dom::asmjscache::OpenMode> :
|
||||
public ContiguousEnumSerializer<mozilla::dom::asmjscache::OpenMode,
|
||||
mozilla::dom::asmjscache::eOpenForRead,
|
||||
mozilla::dom::asmjscache::NUM_OPEN_MODES>
|
||||
{ };
|
||||
|
||||
template <>
|
||||
struct ParamTraits<mozilla::dom::asmjscache::Metadata>
|
||||
{
|
||||
typedef mozilla::dom::asmjscache::Metadata paramType;
|
||||
static void Write(Message* aMsg, const paramType& aParam);
|
||||
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult);
|
||||
static void Log(const paramType& aParam, std::wstring* aLog);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ParamTraits<mozilla::dom::asmjscache::WriteParams>
|
||||
{
|
||||
typedef mozilla::dom::asmjscache::WriteParams paramType;
|
||||
static void Write(Message* aMsg, const paramType& aParam);
|
||||
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult);
|
||||
static void Log(const paramType& aParam, std::wstring* aLog);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ParamTraits<JS::AsmJSCacheResult> :
|
||||
public ContiguousEnumSerializer<JS::AsmJSCacheResult,
|
||||
JS::AsmJSCache_MIN,
|
||||
JS::AsmJSCache_LIMIT>
|
||||
{ };
|
||||
|
||||
} // namespace IPC
|
||||
|
||||
#endif // mozilla_dom_asmjscache_asmjscache_h
|
||||
38
dom/asmjscache/PAsmJSCacheEntry.ipdl
Normal file
38
dom/asmjscache/PAsmJSCacheEntry.ipdl
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
include protocol PBackground;
|
||||
|
||||
using mozilla::dom::asmjscache::Metadata from "mozilla/dom/asmjscache/AsmJSCache.h";
|
||||
using JS::AsmJSCacheResult from "mozilla/dom/asmjscache/AsmJSCache.h";
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace asmjscache {
|
||||
|
||||
protocol PAsmJSCacheEntry
|
||||
{
|
||||
manager PBackground;
|
||||
|
||||
// When the cache is opened to read, the parent process sends over the
|
||||
// origin's Metadata so the child process can select the cache entry to open
|
||||
// (based on hash) and notify the parent (via SelectCacheFileToRead).
|
||||
child:
|
||||
async OnOpenMetadataForRead(Metadata metadata);
|
||||
parent:
|
||||
async SelectCacheFileToRead(uint32_t moduleIndex);
|
||||
async CacheMiss();
|
||||
|
||||
child:
|
||||
// Once the cache file has been opened, the child is notified and sent an
|
||||
// open file descriptor.
|
||||
async OnOpenCacheFile(int64_t fileSize, FileDescriptor fileDesc);
|
||||
|
||||
both:
|
||||
async __delete__(AsmJSCacheResult result);
|
||||
};
|
||||
|
||||
} // namespace asmjscache
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
23
dom/asmjscache/moz.build
Normal file
23
dom/asmjscache/moz.build
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
EXPORTS.mozilla.dom.asmjscache += [
|
||||
'AsmJSCache.h'
|
||||
]
|
||||
|
||||
SOURCES += [
|
||||
'AsmJSCache.cpp'
|
||||
]
|
||||
|
||||
IPDL_SOURCES += [
|
||||
'PAsmJSCacheEntry.ipdl'
|
||||
]
|
||||
|
||||
include('/ipc/chromium/chromium-config.mozbuild')
|
||||
|
||||
FINAL_LIBRARY = 'xul'
|
||||
|
||||
MOCHITEST_MANIFESTS += ['test/mochitest.ini']
|
||||
73
dom/asmjscache/test/file_slow.js
Normal file
73
dom/asmjscache/test/file_slow.js
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
function f1() { "use asm"; function g() {} return g }
|
||||
if (this.jsFuns) {
|
||||
ok(jsFuns.isAsmJSModule(f1), "f1 is an asm.js module");
|
||||
ok(jsFuns.isAsmJSFunction(f1()), "f1.g is an asm.js function");
|
||||
}
|
||||
|
||||
function f2(stdlib, foreign, buffer) {
|
||||
"use asm";
|
||||
var i32 = new stdlib.Int32Array(buffer);
|
||||
function main(n) {
|
||||
n = n|0;
|
||||
var i = 0, sum = 0;
|
||||
for (; (i|0) < (n|0); i=(i+1)|0)
|
||||
sum = (sum + (i32[(i<<2)>>2]|0))|0;
|
||||
return sum|0;
|
||||
}
|
||||
return main;
|
||||
}
|
||||
if (this.jsFuns)
|
||||
ok(jsFuns.isAsmJSModule(f2), "f2 is an asm.js module");
|
||||
var i32 = new Int32Array(16384); // Smallest allowed buffer size is 64KBy
|
||||
for (var i = 0; i < i32.length; i++)
|
||||
i32[i] = i;
|
||||
var f2Main = f2(this, null, i32.buffer);
|
||||
if (this.jsFuns)
|
||||
ok(jsFuns.isAsmJSFunction(f2Main), "f2.main is an asm.js function");
|
||||
if (f2Main(4) !== 6)
|
||||
throw "f2Main(4)";
|
||||
if (f2Main(100) !== 4950)
|
||||
throw "f2.main(100)";
|
||||
var sum = (((i32.length - 1) * i32.length) / 2);
|
||||
if (f2Main(i32.length) !== sum)
|
||||
throw "f2.main(" + i32.length + ")";
|
||||
if (f2Main(i32.length + 100) !== sum)
|
||||
throw "f2.main(" + i32.length + ")";
|
||||
|
||||
function f3(stdlib, foreign, buffer) {
|
||||
"use asm";
|
||||
var done = foreign.done;
|
||||
var i32 = new stdlib.Int32Array(buffer);
|
||||
function main() {
|
||||
var i = 0, sum = 0;
|
||||
while (1) {
|
||||
for (i = 0; (i|0) < 1000; i=(i+1)|0)
|
||||
sum = (sum + i)|0;
|
||||
if (done(sum|0)|0)
|
||||
break;
|
||||
}
|
||||
return sum|0;
|
||||
}
|
||||
return main;
|
||||
}
|
||||
var begin;
|
||||
var lastSum;
|
||||
function done(sum) {
|
||||
if (sum !== ((lastSum + 499500)|0))
|
||||
throw "bad sum: " + sum + ", " + lastSum + ", " + ((lastSum + 499500)|0);
|
||||
lastSum = sum;
|
||||
return (Date.now() - begin) > 3000;
|
||||
}
|
||||
var f3Main = f3(this, {done:done}, i32.buffer);
|
||||
if (this.jsFuns)
|
||||
ok(jsFuns.isAsmJSFunction(f3Main), "f3.main is an asm.js function");
|
||||
|
||||
begin = Date.now();
|
||||
lastSum = 0;
|
||||
if (f3Main() !== lastSum)
|
||||
throw "f3.main()";
|
||||
|
||||
if (!this.jsFuns)
|
||||
postMessage("ok");
|
||||
else
|
||||
complete();
|
||||
10
dom/asmjscache/test/mochitest.ini
Normal file
10
dom/asmjscache/test/mochitest.ini
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
[DEFAULT]
|
||||
support-files =
|
||||
file_slow.js
|
||||
|
||||
[test_cachingBasic.html]
|
||||
[test_workers.html]
|
||||
[test_cachingMulti.html]
|
||||
[test_slow.html]
|
||||
# bug 929498
|
||||
skip-if = os == 'android'
|
||||
70
dom/asmjscache/test/test_cachingBasic.html
Normal file
70
dom/asmjscache/test/test_cachingBasic.html
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=929236
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>asm.js browser tests</title>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=929236">asm.js browser tests</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none"></div>
|
||||
<pre id="test"></pre>
|
||||
|
||||
<script>
|
||||
var jsFuns = SpecialPowers.Cu.getJSTestingFunctions();
|
||||
|
||||
var code = "function f() { 'use asm';\n";
|
||||
for (var i = 0; i < 5000; i++)
|
||||
code += "function g" + i + "() { return " + i + "}\n";
|
||||
code += "return g42 }\n";
|
||||
code += "ok(jsFuns.isAsmJSModule(f), 'f is an asm.js module')\n";
|
||||
code += "var g42 = f();\n";
|
||||
code += "ok(jsFuns.isAsmJSFunction(g42), 'g42 is an asm.js function')\n";
|
||||
code += "ok(g42() === 42, 'g42 returns the correct result')\n";
|
||||
code += "finishedEvalAsync(f);";
|
||||
ok(code.length > 100000, "code is long enough to definitely hit the cache");
|
||||
|
||||
function evalAsync(code) {
|
||||
var blob = new Blob([code], {type:"application/javascript"});
|
||||
var script = document.createElement('script');
|
||||
script.src = URL.createObjectURL(blob);
|
||||
document.body.appendChild(script);
|
||||
}
|
||||
|
||||
var state = 0;
|
||||
function finishedEvalAsync(module) {
|
||||
switch (state) {
|
||||
case 0:
|
||||
state++;
|
||||
evalAsync(code);
|
||||
break;
|
||||
case 1:
|
||||
ok(!jsFuns.isAsmJSModuleLoadedFromCache(module), 'module not loaded from cache');
|
||||
SimpleTest.finish();
|
||||
break;
|
||||
default:
|
||||
throw "huh?";
|
||||
}
|
||||
}
|
||||
|
||||
function runTest() {
|
||||
// generate a big ol asm.js module and compile it async so that we can hit
|
||||
// the asm.js cache.
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
evalAsync(code);
|
||||
}
|
||||
|
||||
if (!jsFuns.isAsmJSCompilationAvailable()) {
|
||||
ok(true, "isAsmJSCompilationAvailable is false, skipping this test!");
|
||||
} else {
|
||||
runTest();
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
85
dom/asmjscache/test/test_cachingMulti.html
Normal file
85
dom/asmjscache/test/test_cachingMulti.html
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=944821
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>asm.js browser tests</title>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=944821">asm.js browser tests</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none"></div>
|
||||
<pre id="test"></pre>
|
||||
|
||||
<script>
|
||||
var jsFuns = SpecialPowers.Cu.getJSTestingFunctions();
|
||||
|
||||
var assertCacheHit = false;
|
||||
|
||||
// generate four slightly different big asm.js modules and compile them async
|
||||
// so that we can hit the asm.js cache.
|
||||
|
||||
var code = "function f() { 'use asm';\n";
|
||||
for (var i = 0; i < 5000; i++)
|
||||
code += "function g" + i + "() { return " + i + "}\n";
|
||||
ok(code.length > 100000, "code is long enough to definitely hit the cache");
|
||||
|
||||
const N = 4;
|
||||
|
||||
var codes = [];
|
||||
for (var i = 0; i < N; i++) {
|
||||
var code2 = code;
|
||||
code2 += "return g" + i + ";\n";
|
||||
code2 += "}\n";
|
||||
code2 += "ok(jsFuns.isAsmJSModule(f), 'f is an asm.js module')\n";
|
||||
code2 += "if (assertCacheHit) ok(!jsFuns.isAsmJSModuleLoadedFromCache(f), 'cache disabled');\n";
|
||||
code2 += "var gX = f();\n";
|
||||
code2 += "ok(jsFuns.isAsmJSFunction(gX), 'gX is an asm.js function')\n";
|
||||
code2 += "ok(gX() === " + i + ", 'gX returns the correct result')\n";
|
||||
code2 += "finishedEvalAsync();\n";
|
||||
codes.push(code2);
|
||||
}
|
||||
|
||||
function evalAsync(code) {
|
||||
var blob = new Blob([code], {type:"application/javascript"});
|
||||
var script = document.createElement('script');
|
||||
script.src = URL.createObjectURL(blob);
|
||||
document.body.appendChild(script);
|
||||
}
|
||||
|
||||
var finishedCount = 0;
|
||||
function finishedEvalAsync() {
|
||||
finishedCount++;
|
||||
|
||||
if (finishedCount < 1 || finishedCount > 2*N) {
|
||||
throw "Huh?!";
|
||||
} else if (finishedCount == N) {
|
||||
assertCacheHit = true;
|
||||
for (var i = 0; i < N; i++)
|
||||
evalAsync(codes[i]);
|
||||
} else if (finishedCount == 2*N) {
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}
|
||||
|
||||
function runTest() {
|
||||
for (var i = 0; i < N; i++)
|
||||
evalAsync(codes[i]);
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
}
|
||||
|
||||
if (!jsFuns.isAsmJSCompilationAvailable()) {
|
||||
ok(true, "isAsmJSCompilationAvailable is false, skipping this test!");
|
||||
} else {
|
||||
runTest();
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
48
dom/asmjscache/test/test_slow.html
Normal file
48
dom/asmjscache/test/test_slow.html
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=854209
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>asm.js browser tests</title>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=854209">asm.js browser tests</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none"></div>
|
||||
<pre id="test"></pre>
|
||||
|
||||
<script>
|
||||
var jsFuns = SpecialPowers.Cu.getJSTestingFunctions();
|
||||
|
||||
var completed = 0;
|
||||
function complete() {
|
||||
if (++completed == 2)
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
if (!jsFuns.isAsmJSCompilationAvailable()) {
|
||||
ok(true, "isAsmJSCompilationAvailable is false, skipping this test!");
|
||||
} else {
|
||||
var script = document.createElement("script");
|
||||
script.src = "http://mochi.test:8888/tests/dom/asmjscache/test/file_slow.js";
|
||||
document.body.appendChild(script);
|
||||
|
||||
var w = new Worker('http://mochi.test:8888/tests/dom/asmjscache/test/file_slow.js');
|
||||
w.onmessage = function(e) {
|
||||
ok(e.data === "ok", "Worker asm.js tests");
|
||||
complete();
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
74
dom/asmjscache/test/test_workers.html
Normal file
74
dom/asmjscache/test/test_workers.html
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=941830
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>asm.js browser tests</title>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=941830">asm.js browser tests</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none"></div>
|
||||
<pre id="test"></pre>
|
||||
|
||||
<script>
|
||||
var jsFuns = SpecialPowers.Cu.getJSTestingFunctions();
|
||||
|
||||
function runTest() {
|
||||
var asmjsCode = "function f() { 'use asm';";
|
||||
for (var i = 0; i < 5000; i++)
|
||||
asmjsCode += "function g" + i + "() { return " + i + "}";
|
||||
asmjsCode += "return g42 }";
|
||||
ok(asmjsCode.length > 100000, "code is long enough to definitely hit the cache");
|
||||
|
||||
var workerCode = asmjsCode;
|
||||
workerCode += "if (f()() !== 42) postMessage('fail'); else postMessage('ok');";
|
||||
workerCode = 'var code = "' + workerCode + '"; eval(code); eval(code)';
|
||||
var workerBlob = new Blob([workerCode], {type:"application/javascript"});
|
||||
|
||||
var mainCode = asmjsCode;
|
||||
mainCode += "ok(!jsFuns.isAsmJSModuleLoadedFromCache(f), 'f is not a cache hit')\n";
|
||||
mainCode += "var g42 = f();\n";
|
||||
mainCode += "ok(jsFuns.isAsmJSFunction(g42), 'g42 is an asm.js function');\n";
|
||||
mainCode += "ok(g42() === 42, 'g42 returns the correct result');\n";
|
||||
mainCode += "SimpleTest.finish();\n";
|
||||
var mainBlob = new Blob([mainCode], {type:"application/javascript"});
|
||||
|
||||
var w = new Worker(URL.createObjectURL(workerBlob));
|
||||
|
||||
var received = 0;
|
||||
w.onmessage = function(e) {
|
||||
switch (received) {
|
||||
case 0:
|
||||
ok(e.data === "ok", "Received first message");
|
||||
received = 1;
|
||||
break;
|
||||
case 1:
|
||||
ok(e.data === "ok", "Received second message");
|
||||
received = 2;
|
||||
|
||||
var script = document.createElement('script');
|
||||
script.src = URL.createObjectURL(mainBlob);
|
||||
document.body.appendChild(script);
|
||||
break;
|
||||
default:
|
||||
throw "Huh?";
|
||||
}
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
}
|
||||
|
||||
if (!jsFuns.isAsmJSCompilationAvailable()) {
|
||||
ok(true, "isAsmJSCompilationAvailable is false, skipping this test!");
|
||||
} else {
|
||||
runTest();
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue