-
Notifications
You must be signed in to change notification settings - Fork 96
console.log fails with const object = { __proto__: null } #13
Comments
Unlike Chrome and Firefox, The current implementation of quickjs'
Test under qjs (either the official version or the one that comes with sciter.js: let obj = { prop1: 10, prop2: 20 }
console.log(Object.keys(obj)) // prop1,prop2
console.log(obj.toString()) // [object Object]
console.log(obj) // [object object]
obj = { __proto__: null, prop1: 30, prop2: 40 }
console.log(Object.keys(obj)) // prop1,prop2
console.log(obj.toString()) // TypeError: not a function
// at <eval> (./log_obj_with__proto__null.js:8)
console.log(obj) // TypeError: toPrimitive
// at log (native)
// at <eval> (./log_obj_with__proto__null.js:10) The same test at https://bellard.org/jslinux/vm.html?url=alpine-x86.cfg: Note: I'm not in a position to decide behalf others if console.log should behave differently from the current implementation. I can still write something like console.log({...obj}) or even get rid of |
Why is it so important to console.log an object with |
For now In any case it can be redefined on script side:
with proper checks for |
I don't write
@c-smile Feel free to close this anytime. |
Thanks a lot for digging it. I am using toString() in other places so this finding will help there too. |
Fixed in 4.4.5.5 |
@c-smile Thanks for this link rollup/rollup#3140. I understand that they're sticking to the deprecated
__proto__
for performance reasons to avoid changing object's prototype after it's creation (it's supported by browsers and some other runtimes including quickjs)And according to this rollup/rollup#3096,
__proto__: null
is used to set the prototype of namespace objects tonull
.quickjs has
__proto__
according to these links:What I discovered:
console.log(object_with__proto__null)
__proto__: undefined
(not tested with browsers)console.log
the second reference, you'll receive the same error.console.log
object's properties andObject.keys(object)
.Test Code:
The text was updated successfully, but these errors were encountered: