-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSRPC: Support "serializing" functions by turning them into stubs #1756
Commits on Mar 5, 2024
-
JSRPC: Don't allow serializing application class instances.
The default behavior of V8 serialization (and structured clone, I guess) is to serialize a class instance as if it were a plain object, completely ignoring the prototype. This is probably not useful in real use cases since it is lossy. So, we'd prefer that this just fails, both because it's not useful and because we might want to introduce better behavior in the future.
Configuration menu - View commit details
-
Copy full SHA for 96afb24 - Browse repository at this point
Copy the full SHA 96afb24View commit details -
JSRPC: Improve the error message when failing to serialize host objects.
V8's default implementation of `WriteHostObject()` is pretty bad. It does NOT call `ThrowDataCloneError()`; instead it throws a regular old `Error`. The error message is also very weird, it puts the characters `#<>` around the type name. This commit changes to throwing a DataCloneError with a nicer error message.
Configuration menu - View commit details
-
Copy full SHA for 4079859 - Browse repository at this point
Copy the full SHA 4079859View commit details -
JSRPC: Serialize functions as RPC stubs.
This required a V8 patch to allow functions to be treated as host objects. This commit constructs the RpcStubs but they are not actually callable yet -- there is more work to be done in subsequent commits.
Configuration menu - View commit details
-
Copy full SHA for e5601d9 - Browse repository at this point
Copy the full SHA e5601d9View commit details -
JSRPC: Refactor: Pull callImpl() out as standalone function.
We need to make RpcStub itself callable, so having this as a private method of JsRpcProperty no longer works.
Configuration menu - View commit details
-
Copy full SHA for 35d4886 - Browse repository at this point
Copy the full SHA 35d4886View commit details -
JSRPC: Refactor: Don't template callImpl().
We can just use an old fashion if statement here.
Configuration menu - View commit details
-
Copy full SHA for 05a19ec - Browse repository at this point
Copy the full SHA 05a19ecView commit details -
Configuration menu - View commit details
-
Copy full SHA for 012ac44 - Browse repository at this point
Copy the full SHA 012ac44View commit details -
JSRPC: Monkeypatch assert.rejects to not be confused by callable then…
…ables. We're about to make JsRpcPromise be callable, which makes it a function. But `isValidThenable()` in `internal_asserts.ts` thinks that thenables cannot be callable, which means `assert.rejects` doesn't our promises. This commit monkey-patches it to solve the problem, but maybe `isValidThenable()` itself should change...
Configuration menu - View commit details
-
Copy full SHA for 6c05025 - Browse repository at this point
Copy the full SHA 6c05025View commit details -
JSRPC: Change internal_thenable.js isValidThenable() to accept callab…
…le thenables. This lets us get rid of the monkey-patch in js-rpc-test.js, but I'm not completely sure if it's correct. It does seem that V8 itself accepts callable thenables, but the check here looks very explicit so I'm not sure if it has a reason. `isValidThenable()` was also requiring the presence of a `catch` method, but this is not actually a requirement of thenables, so I removed that check as well.
Configuration menu - View commit details
-
Copy full SHA for 8d0b411 - Browse repository at this point
Copy the full SHA 8d0b411View commit details -
JSRPC: Make JsRpcStub and JsRpcPromise callable.
This allows a stub to point to a bare function, and allows an RPC to directly return a bare function.
Configuration menu - View commit details
-
Copy full SHA for 16fa442 - Browse repository at this point
Copy the full SHA 16fa442View commit details -
JSRPC: Allow accessing properties of functions.
Sometimes people make a "callable object" by creating a function and then giving it properties. We should support this. I had originally wanted to disallow this if the function's prototype had been tampered with, like: ``` let func = () => {}; func.__proto__ = SomeClass.prototype; ``` This technique allows you to create a "callable class instance". In theory we ought to treat it like a user-defined class, i.e., don't support it, unless it extends JsRpcTarget. Unfortunately, it's sort of hard to distinguish "plain functions". There are multiple prototypes to check for: Function, AsyncFunction, and maybe others. I decided to give up and say that we treat all callable objects as functions.
Configuration menu - View commit details
-
Copy full SHA for ca221dd - Browse repository at this point
Copy the full SHA ca221ddView commit details -
JSRPC: Make sure JsRpcPromise and JsRpcProperty aren't treated as fun…
…ctions. Since these types are callable, `IsFunction()` returns true, but if we want to actually handle "serializing" these, we need it to work very differently. So, make sure we don't count them, and add some tests. In the future we might decide to actually support these.
Configuration menu - View commit details
-
Copy full SHA for 3cdedb6 - Browse repository at this point
Copy the full SHA 3cdedb6View commit details -
Configuration menu - View commit details
-
Copy full SHA for 0bb6c64 - Browse repository at this point
Copy the full SHA 0bb6c64View commit details -
Configuration menu - View commit details
-
Copy full SHA for 9709be1 - Browse repository at this point
Copy the full SHA 9709be1View commit details -
JSRPC: Test that objects with null prototypes are not accessible.
This should be the same as a class instance of application-defined type.
Configuration menu - View commit details
-
Copy full SHA for cfd3d79 - Browse repository at this point
Copy the full SHA cfd3d79View commit details