ITADN

Creating an object without a prototype

#572Opennabetti1720 创建于 2025-12-06
kind:featuretopic:interface
N
nabetti1720commented
We are working on improving the console namespace in the LLRT project, a runtime powered by rquickjs. https://github.com/awslabs/llrt/pull/1258 For historical reasons, the [console namespace](https://console.spec.whatwg.org/#console-namespace) must be an object without a prototype. > For historical web-compatibility reasons, the [namespace object](https://webidl.spec.whatwg.org/#dfn-namespace-object) for [console](https://console.spec.whatwg.org/#namespacedef-console) must have as its [[Prototype]] an empty object, created as if by [ObjectCreate](https://tc39.github.io/ecma262/#sec-objectcreate)([%ObjectPrototype%](https://tc39.github.io/ecma262/#sec-properties-of-the-object-prototype-object)), instead of [%ObjectPrototype%](https://tc39.github.io/ecma262/#sec-properties-of-the-object-prototype-object). `Object::new()` does not meet our requirements because it creates a prototype by default. ```rust let console = Object::new(ctx.clone())?; ``` ``` % cat ./reproduction.cjs let prop = Object.getPrototypeOf(console); console.log(Object.getOwnPropertyNames(prop)); % llrt ./reproduction.cjs [ 'constructor', 'toString', 'toLocaleString', 'valueOf', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', '__proto__', '__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__' ] % node ./reproduction.cjs [] ``` We found the implementation below to meet our requirements, but it would be nice to have a higher level API available. ```rust let console = ctx.eval::<Object, &str>("Object.create({})")?; ``` ``` % llrt ./reproduction.cjs [] ```
0 条评论