Skip to content

Commit

Permalink
Merge inbound to mozilla-central. a=merge
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianbrindusan committed Mar 26, 2019
2 parents 139cb1e + 676cfa3 commit c4f15a4
Show file tree
Hide file tree
Showing 23 changed files with 359 additions and 201 deletions.
1 change: 1 addition & 0 deletions devtools/client/debugger/new/src/actions/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export function willNavigate(event: Object) {
clearASTs();
clearScopes();
clearSources();
client.detachWorkers();
dispatch(navigate(event.url));
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const threadClient = {
source: "function foo1() {\n const foo = 5; return foo;\n}",
contentType: "text/javascript"
}),
getBreakpointPositions: async () => ({})
getBreakpointPositions: async () => ({}),
detachWorkers: () => {}
};

describe("navigation", () => {
Expand Down Expand Up @@ -67,7 +68,7 @@ describe("navigation", () => {
});

it("navigation removes activeSearch 'project' value", async () => {
const { dispatch, getState } = createStore();
const { dispatch, getState } = createStore(threadClient);
dispatch(actions.setActiveSearch("project"));
expect(getActiveSearch(getState())).toBe("project");

Expand All @@ -76,7 +77,7 @@ describe("navigation", () => {
});

it("navigation clears the file-search query", async () => {
const { dispatch, getState } = createStore();
const { dispatch, getState } = createStore(threadClient);

dispatch(actions.setFileSearchQuery("foobar"));
expect(getFileSearchQuery(getState())).toBe("foobar");
Expand All @@ -87,7 +88,7 @@ describe("navigation", () => {
});

it("navigation clears the file-search results", async () => {
const { dispatch, getState } = createStore();
const { dispatch, getState } = createStore(threadClient);

const searchResults = [{ line: 1, ch: 3 }, { line: 3, ch: 2 }];
dispatch(actions.updateSearchResults(2, 3, searchResults));
Expand All @@ -109,7 +110,7 @@ describe("navigation", () => {
});

it("navigation removes activeSearch 'file' value", async () => {
const { dispatch, getState } = createStore();
const { dispatch, getState } = createStore(threadClient);
dispatch(actions.setActiveSearch("file"));
expect(getActiveSearch(getState())).toBe("file");

Expand Down
9 changes: 8 additions & 1 deletion devtools/client/debugger/new/src/client/firefox/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ function waitForWorkers(shouldWait: boolean) {
shouldWaitForWorkers = shouldWait;
}

function detachWorkers() {
for (const thread of listWorkerThreadClients()) {
thread.detach();
}
}

function maybeGenerateLogGroupId(options) {
if (options.logValue && tabTarget.traits && tabTarget.traits.canRewind) {
return { ...options, logGroupId: `logGroup-${Math.random()}` };
Expand Down Expand Up @@ -485,7 +491,8 @@ const clientCommands = {
sendPacket,
setSkipPausing,
setEventListenerBreakpoints,
waitForWorkers
waitForWorkers,
detachWorkers
};

export { setupCommands, clientCommands };
9 changes: 9 additions & 0 deletions js/src/builtin/Promise.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,15 @@ class OffThreadPromiseRuntimeState;
// OffThreadPromiseTask for the promise, and let the embedding's network I/O
// threads call dispatchResolveAndDestroy.
//
// OffThreadPromiseTask may also be used purely on the main thread, as a way to
// "queue a task" in HTML terms. Note that a "task" is not the same as a
// "microtask" and there are separate queues for tasks and microtasks that are
// drained at separate times in the browser. The task queue is implemented by
// the browser's main event loop. The microtask queue is implemented
// by JS::JobQueue, used for promises and gets drained before returning to
// the event loop. Thus OffThreadPromiseTask can only be used when the spec
// says "queue a task", as the WebAssembly APIs do.
//
// An OffThreadPromiseTask has a JSContext, and must be constructed and have its
// 'init' method called on that JSContext's thread. Once initialized, its
// dispatchResolveAndDestroy method may be called from any thread. This is the
Expand Down
47 changes: 47 additions & 0 deletions js/src/jit-test/tests/wasm/async-instantiate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const { Module, Instance, Global, instantiate, instantiateStreaming } = WebAssembly;

const g = new Global({value: "i32", mutable:true}, 0);

const code = wasmTextToBinary(`(module
(global $g (import "" "g") (mut i32))
(func $start (set_global $g (i32.add (get_global $g) (i32.const 1))))
(start $start)
)`);
const module = new Module(code);

const importObj = { '': { get g() { g.value++; return g } } };

g.value = 0;
new Instance(module, importObj);
assertEq(g.value, 2);

g.value = 0;
instantiate(module, importObj).then(i => {
assertEq(i instanceof Instance, true);
assertEq(g.value, 2);
g.value++;
});
assertEq(g.value, 1);
drainJobQueue();
assertEq(g.value, 3);

g.value = 0;
instantiate(code, importObj).then(({module,instance}) => {
assertEq(module instanceof Module, true);
assertEq(instance instanceof Instance, true);
assertEq(g.value, 2); g.value++; }
);
drainJobQueue();
assertEq(g.value, 3);

if (wasmStreamingIsSupported()) {
g.value = 0;
instantiateStreaming(code, importObj).then(({module,instance}) => {
assertEq(module instanceof Module, true);
assertEq(instance instanceof Instance, true);
assertEq(g.value, 2);
g.value++;
});
drainJobQueue();
assertEq(g.value, 3);
}
5 changes: 4 additions & 1 deletion js/src/jsapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -2147,6 +2147,9 @@ namespace JS {
* as when it is later consumed.
*/

using OptimizedEncodingBytes = js::Vector<uint8_t, 0, js::SystemAllocPolicy>;
using UniqueOptimizedEncodingBytes = js::UniquePtr<OptimizedEncodingBytes>;

class OptimizedEncodingListener {
protected:
virtual ~OptimizedEncodingListener() {}
Expand All @@ -2159,7 +2162,7 @@ class OptimizedEncodingListener {

// SpiderMonkey may optionally call storeOptimizedEncoding() after it has
// finished processing a streamed resource.
virtual void storeOptimizedEncoding(const uint8_t* bytes, size_t length) = 0;
virtual void storeOptimizedEncoding(UniqueOptimizedEncodingBytes bytes) = 0;
};

class JS_PUBLIC_API StreamConsumer {
Expand Down
9 changes: 4 additions & 5 deletions js/src/shell/js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6909,9 +6909,8 @@ class StreamCacheEntry : public AtomicRefCounted<StreamCacheEntry>,

const Uint8Vector& bytes() const { return bytes_; }

void storeOptimizedEncoding(const uint8_t* srcBytes,
size_t srcLength) override {
MOZ_ASSERT(srcLength > 0);
void storeOptimizedEncoding(JS::UniqueOptimizedEncodingBytes src) override {
MOZ_ASSERT(src->length() > 0);

// Tolerate races since a single StreamCacheEntry object can be used as
// the source of multiple streaming compilations.
Expand All @@ -6920,10 +6919,10 @@ class StreamCacheEntry : public AtomicRefCounted<StreamCacheEntry>,
return;
}

if (!dstBytes->resize(srcLength)) {
if (!dstBytes->resize(src->length())) {
return;
}
memcpy(dstBytes->begin(), srcBytes, srcLength);
memcpy(dstBytes->begin(), src->begin(), src->length());
}

bool hasOptimizedEncoding() const { return !optimized_.lock()->empty(); }
Expand Down
26 changes: 11 additions & 15 deletions js/src/wasm/AsmJS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6779,8 +6779,7 @@ static bool CheckBuffer(JSContext* cx, const AsmJSMetadata& metadata,

static bool GetImports(JSContext* cx, const AsmJSMetadata& metadata,
HandleValue globalVal, HandleValue importVal,
MutableHandle<FunctionVector> funcImports,
MutableHandleValVector valImports) {
ImportValues* imports) {
Rooted<FunctionVector> ffis(cx, FunctionVector(cx));
if (!ffis.resize(metadata.numFFIs)) {
return false;
Expand All @@ -6793,7 +6792,7 @@ static bool GetImports(JSContext* cx, const AsmJSMetadata& metadata,
if (!ValidateGlobalVariable(cx, global, importVal, &litVal)) {
return false;
}
if (!valImports.append(Val(litVal->asLitVal()))) {
if (!imports->globalValues.append(Val(litVal->asLitVal()))) {
return false;
}
break;
Expand Down Expand Up @@ -6823,7 +6822,7 @@ static bool GetImports(JSContext* cx, const AsmJSMetadata& metadata,
}

for (const AsmJSImport& import : metadata.asmJSImports) {
if (!funcImports.append(ffis[import.ffiIndex()])) {
if (!imports->funcs.append(ffis[import.ffiIndex()])) {
return false;
}
}
Expand All @@ -6845,30 +6844,27 @@ static bool TryInstantiate(JSContext* cx, CallArgs args, const Module& module,
return LinkFail(cx, "no compiler support");
}

RootedArrayBufferObjectMaybeShared buffer(cx);
RootedWasmMemoryObject memory(cx);
Rooted<ImportValues> imports(cx);

if (module.metadata().usesMemory()) {
RootedArrayBufferObjectMaybeShared buffer(cx);
if (!CheckBuffer(cx, metadata, bufferVal, &buffer)) {
return false;
}

memory = WasmMemoryObject::create(cx, buffer, nullptr);
if (!memory) {
imports.get().memory = WasmMemoryObject::create(cx, buffer, nullptr);
if (!imports.get().memory) {
return false;
}
}

RootedValVector valImports(cx);
Rooted<FunctionVector> funcs(cx, FunctionVector(cx));
if (!GetImports(cx, metadata, globalVal, importVal, &funcs, &valImports)) {
if (!GetImports(cx, metadata, globalVal, importVal, imports.address())) {
return false;
}

Rooted<WasmGlobalObjectVector> globalObjs(cx);
Rooted<WasmTableObjectVector> tables(cx);
if (!module.instantiate(cx, funcs, tables.get(), memory, valImports,
globalObjs.get(), nullptr, instanceObj))
if (!module.instantiate(cx, imports.get(), nullptr, instanceObj)) {
return false;
}

exportObj.set(&instanceObj->exportsObj());
return true;
Expand Down
2 changes: 1 addition & 1 deletion js/src/wasm/WasmBuiltins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ static Maybe<ABIFunctionType> ToBuiltinABIFunctionType(
return Some(ABIFunctionType(abiType));
}

void* wasm::MaybeGetBuiltinThunk(HandleFunction f, const FuncType& funcType) {
void* wasm::MaybeGetBuiltinThunk(JSFunction* f, const FuncType& funcType) {
MOZ_ASSERT(builtinThunks);

if (!f->isNative() || !f->hasJitInfo() ||
Expand Down
2 changes: 1 addition & 1 deletion js/src/wasm/WasmBuiltins.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void* HandleThrow(JSContext* cx, WasmFrameIter& iter);

void* SymbolicAddressTarget(SymbolicAddress sym);

void* MaybeGetBuiltinThunk(HandleFunction f, const FuncType& funcType);
void* MaybeGetBuiltinThunk(JSFunction* f, const FuncType& funcType);

void ReleaseBuiltinThunks();

Expand Down
11 changes: 5 additions & 6 deletions js/src/wasm/WasmInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1078,8 +1078,8 @@ Instance::Instance(JSContext* cx, Handle<WasmInstanceObject*> object,
SharedCode code, UniqueTlsData tlsDataIn,
HandleWasmMemoryObject memory, SharedTableVector&& tables,
StructTypeDescrVector&& structTypeDescrs,
Handle<FunctionVector> funcImports,
HandleValVector globalImportValues,
const JSFunctionVector& funcImports,
const ValVector& globalImportValues,
const WasmGlobalObjectVector& globalObjs,
UniqueDebugState maybeDebug)
: realm_(cx->realm()),
Expand Down Expand Up @@ -1120,7 +1120,7 @@ Instance::Instance(JSContext* cx, Handle<WasmInstanceObject*> object,

Tier callerTier = code_->bestTier();
for (size_t i = 0; i < metadata(callerTier).funcImports.length(); i++) {
HandleFunction f = funcImports[i];
JSFunction* f = funcImports[i];
const FuncImport& fi = metadata(callerTier).funcImports[i];
FuncImportTls& import = funcImportTls(fi);
import.fun = f;
Expand Down Expand Up @@ -1171,7 +1171,7 @@ Instance::Instance(JSContext* cx, Handle<WasmInstanceObject*> object,
if (global.isIndirect()) {
*(void**)globalAddr = globalObjs[imported]->cell();
} else {
CopyValPostBarriered(globalAddr, globalImportValues[imported].get());
CopyValPostBarriered(globalAddr, globalImportValues[imported]);
}
break;
}
Expand All @@ -1193,8 +1193,7 @@ Instance::Instance(JSContext* cx, Handle<WasmInstanceObject*> object,
// the source global should never be indirect.
MOZ_ASSERT(!imported.isIndirect());

RootedVal dest(cx,
globalImportValues[imported.importIndex()].get());
RootedVal dest(cx, globalImportValues[imported.importIndex()]);
if (global.isIndirect()) {
void* address = globalObjs[i]->cell();
*(void**)globalAddr = address;
Expand Down
4 changes: 2 additions & 2 deletions js/src/wasm/WasmInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class Instance {
Instance(JSContext* cx, HandleWasmInstanceObject object, SharedCode code,
UniqueTlsData tlsData, HandleWasmMemoryObject memory,
SharedTableVector&& tables, StructTypeDescrVector&& structTypeDescrs,
Handle<FunctionVector> funcImports,
HandleValVector globalImportValues,
const JSFunctionVector& funcImports,
const ValVector& globalImportValues,
const WasmGlobalObjectVector& globalObjs,
UniqueDebugState maybeDebug);
~Instance();
Expand Down

0 comments on commit c4f15a4

Please sign in to comment.