On Thu, Jul 30, 2020 at 8:21 PM Adrienne Walker <e...@chromium.org> wrote: > Is there any way to know from a v8::Value whether serializing it will have > side effects (at all or on particular properties)?
Apart from checking whether it's primitive (v->IsNullOrUndefined() || v->IsBoolean() || ...), I believe the answer is 'no' . Non-primitive values can have getters and getters execute arbitrary code. Checking for only simple properties recursively is an option but probably not faster and you'll need to handle cycles and a ton of edge cases (what if the property is a pending promise? what if it's a WeakMap? etc.) The debugger has a "side-effect-free evaluate" mode but that operates on functions, not values. You could use it to check getters for side effects (and promises, and...) but the algorithm is conservative (can report side effects when there are none) and runs in O(n) time relative to the function's bytecode size. (It's actually worse than that. It does bytecode analysis + runtime evaluation in a throwaway context. I suspect it hangs on a busy loop. That makes it... O(Infinity)?) The relevant methods are DebugEvaluate::Global() and Debug::PerformSideEffectCheck(). Neither are currently exposed by the public API except indirectly, through the Debugger.evaluate and Debugger.evaluateOnCallFrame inspector protocol commands. -- -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/v8-users/CAHQurc_0bLqJu4SddP%2BOaC9gnJPN322gcc2ZLvBA0BwkwJ1XEw%40mail.gmail.com.