-
Notifications
You must be signed in to change notification settings - Fork 89
Added flag to disable realm binding #111
base: master
Are you sure you want to change the base?
Conversation
Hi @larkin-nz, The goal of cloudworker is to match the behavior of Cloudflare Workers as best as possible. In the example you cited, I am curious what specifically breaks with I'm also hesitant to expose the concept of realms to developers. CF Workers don't surface this concept and I'd argue it's not relevant to the majority of users. That being said, I do appreciate the test for |
Hey @hankjacobs, Cloudflare Worker bindings are currently only able to be When we're doing things with bindings in Cloudworker we naturally allow there to be another custom bindings which goes away from the spec but provides the right flexabilty for a stable development example. For example, within In the tests which we have currently in Cloudworker, we test whether an The prototype of say I don`t believe that this actually has any real relevance to Cloudflare Workers as such because there are no functions as I understand within the current bindings which will change between realms as above and I see the purpose of those enforced bindings as moving away from spec. Take the case where we don't bind // Create a context for testing
const context = new runtime.Context(() => {}, Symbol('factory'), {
checkA (a) { return a instanceof Object },
checkB (a, b) { return a instanceof b },
})
// The result will be `false` as `new Object()` is from a different realm to `Object`
const resultA = vm.runInNewContext('checkA(new Object())', context)
// The result will be `true` as `new Object()` is from the same realm `Object`
const resultB = vm.runInNewContext('checkB(new Object(), Object)', context)
// The result will be `true` as `new Object()` is from the same realm `Object`
const resultC = vm.runInNewContext('new Object() instanceof Object', context) I feel that these bindings should not be made in My other solution to this would be to have a key called I spent a whole bunch of time working through the stack with The package is pretty major and receives over 100k downloads a week so this must naturally cause problems for a number of packages outside Let me know when you've had a think about it, but I think the best course of action if you don't want either of my solutions mentioned would be rolling back those bindings added in 0.1.0. Cheers |
This seems very specific to your use of cloudworker. The reason I added the code to handle objects coming from the runtime realm is that without it using That being said, have you considered running the Cloudworker portion of your package in a VM? That would run in it’s own realm and would allow you to do comparisons like you desire (assuming that it’s even possible — I haven’t tried myself). I’ll give some thought as to how cloudworker could more generally solve this issue but I will not be reverting those changes as of now. Now as far as |
I see, that makes sense, have you considered just having these types passed into the scoped functions like how my example B worked above? If you bound a property to the I'm just about to head out for a hike for 5 days so I'm not able to access my laptop to spin up a simple test case with I'll think more about a custom VM but I'd prefer to stay with Cloudworker as much as possible. |
Hey @hankjacobs, have you put any more thought into this? |
@larkin-nz Turning this on made
I do agree with your concerns about realm binding, though. I think we will want to find a different solution for external IO though |
Hey @hankjacobs
I've added a small bit of functionality which disables the
VM
bindings to the context realm which are used forinstanceof
and other methods as were added in your latest release.Adding the flag
VM_DEFAULT_REALM
like so to the bindings will disable binding the VM realm to the parent node realm which instantiates theVM
:When using the flag
instanceof
between theVM
objecta
and the globalObject
protoype will equal false intentionally as theObject
realms remain different.I believe this flag is a crucial component which should be able to be used in my opinion as a number of packages including
math.js
and others break now when running within the latest version of Cloudworker.I think we should not be modifying the
VM
context unless we give users the option to restore this contextI've added tests which you can see in this in my pull request.
I also added one to validate
no-eval
to reflect the state of Cloudflare Workers as I noticed this was also changed on theVM
.I'd appreciate it if you can merge this and release this ASAP as we're really needing this for Restt and our other projects within my team at work.
Thanks again for all your hard work keeping things up to date :)
(p.s. I won't be available to reply to any questions for the next few days as I'll be on holiday but would appreciate it if this is merged before then)