Skip to content

Creating an object without a prototype #572

@nabetti1720

Description

@nabetti1720

We are working on improving the console namespace in the LLRT project, a runtime powered by rquickjs.
awslabs/llrt#1258

For historical reasons, the console namespace must be an object without a prototype.

For historical web-compatibility reasons, the namespace object for console must have as its [[Prototype]] an empty object, created as if by ObjectCreate(%ObjectPrototype%), instead of %ObjectPrototype%.

Object::new() does not meet our requirements because it creates a prototype by default.

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.

let console = ctx.eval::<Object, &str>("Object.create({})")?;
% llrt ./reproduction.cjs
[]

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind:featureA request, idea or new functionalitytopic:interfaceRelated to safe abstractions over the primitives

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions