Skip to content

Commit

Permalink
Merge pull request #71 from Gozala/unwrappable-promise-error
Browse files Browse the repository at this point in the history
Resolve non-unwrappable cross-compartment wrapper promise error
  • Loading branch information
Gozala authored Aug 15, 2018
2 parents c30af9f + b0097f2 commit 86a97a3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"test:flow": "flow check",
"test:tcp": "tape-ext test/TCPSocket",
"test:api": "tape-ext test/API",
"test:dns-sd": "tape-ext test/ServiceDiscovery",
"precommit": "lint-staged",
"demo": "cross-env MOZ_DISABLE_CONTENT_SANDBOX=1 web-ext run --firefox=nightly --browser-console --url about:debugging",
"demo:discovery": "cross-env MOZ_DISABLE_CONTENT_SANDBOX=1 web-ext run --firefox=nightly --browser-console --url about:debugging --source-dir demo/discovery",
Expand Down
10 changes: 6 additions & 4 deletions src/ServiceDiscovery/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ interface Host {
}
}

const notFound = new ExtensionError("Host for the object not found")
const notFound = new context.cloneScope.RangeError(
"Host for the object not found"
)
let notFoundPromiseCache = null

const notFoundPromise = () => {
Expand Down Expand Up @@ -159,7 +161,7 @@ interface Host {

resolve(service)
} catch (error) {
reject(new ExtensionError(error))
reject(new cloneScope.Error(error.message))
}
})
}
Expand Down Expand Up @@ -280,14 +282,14 @@ interface Host {
switch (message.type) {
case "onStopDiscoveryFailed": {
return this.throw(
new ExtensionError(
new context.cloneScope.Error(
`Failed to stop discovery ${message.errorCode}`
)
)
}
case "onStartDiscoveryFailed": {
return this.throw(
new ExtensionError(
new context.cloneScope.Error(
`Failed to start discovery ${message.errorCode}`
)
)
Expand Down
16 changes: 16 additions & 0 deletions test/ServiceDiscovery/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,19 @@ test("discovery with attributes", async test => {
await announcement
await discovery
})

test("unwrappable exceptions #67", async test => {
try {
const service = await browser.ServiceDiscovery.announce({
name: "error",
type: "boom",
protocol: "crash"
})
test.fail(`Exception was expected on wrong protocol`)
} catch (error) {
test.ok(
error.message.includes(`must be either "udp" or "tcp"`),
"error is unwrappable"
)
}
})

0 comments on commit 86a97a3

Please sign in to comment.