Skip to content

explodes if Object deep frozen: Object.keys polyfill modifies global Object.keys #62

Description

@kumavis

When running in strict mode within a context with deep-frozen primordials, things like Object.keys cannot be modified. This is the situation when running in Secure EcmaScript (SES) containers

in lib/keys.js

exports = module.exports = typeof Object.keys === 'function'
  ? Object.keys : shim;

exports.shim = shim;
function shim (obj) {
  var keys = [];
  for (var key in obj) keys.push(key);
  return keys;
}

if Obect.keys is present, it will have shim appended to it. if Object.keys is frozen, this will throw an Error.

node -p "'use strict'; Object.freeze(Object.keys); Object.keys.shim = () => {};"                 
[eval]:1
'use strict'; Object.freeze(Object.keys); Object.keys.shim = () => {};
                                                           ^

TypeError: Cannot add property shim, object is not extensible
    at [eval]:1:60
    at Script.runInThisContext (vm.js:122:20)
    at Object.runInThisContext (vm.js:329:38)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at evalScript (internal/bootstrap/node.js:589:27)
    at startup (internal/bootstrap/node.js:265:9)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions