Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ The basic principle is: **The caller is responsible for disposing all stubs.** T
* Stubs passed in the params of a call remain property of the caller, and must be disposed by the caller, not by the callee.
* Stubs returned in the result of a call have their ownership transferred from the callee to the caller, and must be disposed by the caller.

In practice, though, the callee and caller do not actually share the same stubs. When stubs are passed over RPC, they are _duplicated_, and the the target object is only disposed when all duplicates of the stub are disposed. Thus, to achieve the rule that only the caller needs to dispose stubs, the RPC system implicitly disposes the callee's duplicates of all stubs when the call completes. That is:
In practice, though, the callee and caller do not actually share the same stubs. When stubs are passed over RPC, they are _duplicated_, and the target object is only disposed when all duplicates of the stub are disposed. Thus, to achieve the rule that only the caller needs to dispose stubs, the RPC system implicitly disposes the callee's duplicates of all stubs when the call completes. That is:
* Any stubs the callee receives in the parameters are implicitly disposed when the call completes.
* Any stubs returned in the results are implicitly disposed some time after the call completes. (Specifically, the RPC system will dispose them once it knows there will be no more pipelined calls.)

Expand All @@ -382,7 +382,7 @@ Note that if you pass the same `RpcTarget` instance to RPC multiple times -- thu

### Listening for disconnect

You can monitor any stub for "brokennness" with its `onRpcBroken()` method:
You can monitor any stub for "brokenness" with its `onRpcBroken()` method:

```ts
stub.onRpcBroken((error: any) => {
Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ https://www.cloudflare.com/disclosure
* https://hackerone.com/cloudflare
* All Cloudflare products are in scope for reporting. If you submit a valid report on bounty-eligible assets through our disclosure program, we will transfer your report to our private bug bounty program and invite you as a participant.
* `mailto:[email protected]`
* If you'd like to encrypt your message, please do so within the the body of the message. Our email system doesn't handle PGP-MIME well.
* If you'd like to encrypt your message, please do so within the body of the message. Our email system doesn't handle PGP-MIME well.
* https://www.cloudflare.com/gpg/security-at-cloudflare-pubkey-06A67236.txt

All abuse reports should be submitted to our Trust & Safety team through our dedicated page: https://www.cloudflare.com/abuse/
Expand Down
14 changes: 7 additions & 7 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,20 +270,20 @@ describe("local stub", () => {
expect(await outerStub.innerTarget.square(3)).toBe(9);
});

it("returns undefined when accessing non-existent properties", async () => {
it("returns undefined when accessing nonexistent properties", async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cloudflare is somewhat inconsistent , but it's worth noting that at least some of the time it uses this spelling

let objectStub = new RpcStub({foo: "bar"});
let arrayStub = new RpcStub([1, 2, 3]);
let targetStub = new RpcStub(new TestTarget());

expect(await (objectStub as any).nonExistent).toBe(undefined);
expect(await (arrayStub as any).nonExistent).toBe(undefined);
expect(await (targetStub as any).nonExistent).toBe(undefined);
expect(await (objectStub as any).nonexistent).toBe(undefined);
expect(await (arrayStub as any).nonexistent).toBe(undefined);
expect(await (targetStub as any).nonexistent).toBe(undefined);

// Accessing a property of undefined should throw TypeError (but the error message differs
// across runtimes).
await expect(() => (objectStub as any).nonExistent.foo).rejects.toThrow(TypeError);
await expect(() => (arrayStub as any).nonExistent.foo).rejects.toThrow(TypeError);
await expect(() => (targetStub as any).nonExistent.foo).rejects.toThrow(TypeError);
await expect(() => (objectStub as any).nonexistent.foo).rejects.toThrow(TypeError);
await expect(() => (arrayStub as any).nonexistent.foo).rejects.toThrow(TypeError);
await expect(() => (targetStub as any).nonexistent.foo).rejects.toThrow(TypeError);
});

it("exposes only prototype properties for RpcTarget, not instance properties", async () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/workerd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ describe("workerd compatibility", () => {
}
})

it("can wrap a SerivceStub in an RpcStub", async () => {
it("can wrap a ServiceStub in an RpcStub", async () => {
let result = await new RpcStub((<any>env).testServer).greet("World");
expect(result).toBe("Hello, World!");
});
Expand Down