ljharb / object.assign

ES6 spec-compliant Object.assign shim. From https://github.com/es-shims/es6-shim
https://tc39.es/ecma262/#sec-object.assign
MIT License
107 stars 22 forks source link

Running object.assign under SES #82

Closed katelynsills closed 3 years ago

katelynsills commented 3 years ago

Hi @ljharb, I'm trying to use Enzyme under SES, and I'm running into an issue that involves the object.assign package and define-properties package, although it may be solved by something lower down in the dependency tree.

Here's what I'm seeing:

TypeError: Cannot define property getPolyfill, object is not extensible
    at defineProperty (<anonymous>)
    at defineProperty (/Users/katesills/code/agoric-sdk/node_modules/define-properties/index.js:34:3)
    at defineProperties (/Users/katesills/code/agoric-sdk/node_modules/define-properties/index.js:52:3)
    at Object.<anonymous> (/Users/katesills/code/agoric-sdk/node_modules/object.assign/index.js:11:1)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Object.<anonymous> (/Users/katesills/code/agoric-sdk/node_modules/enzyme/build/ReactWrapper.js:11:15)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Object.<anonymous> (/Users/katesills/code/agoric-sdk/node_modules/enzyme/build/index.js:3:21)
    at Generator.next (<anonymous>)
    at Object.<anonymous> (/Users/katesills/code/agoric-sdk/packages/ui-components/compiled/test/_setup-enzyme-adapter.js:1)
    at Generator.next (<anonymous>)
    at load (/Users/katesills/code/agoric-sdk/packages/ui-components/node_modules/ava/lib/worker/subprocess.js:213:10)
    at /Users/katesills/code/agoric-sdk/packages/ui-components/node_modules/ava/lib/worker/subprocess.js:218:22
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

  › TypeError: Cannot define property getPolyfill, object is not extensible
  › defineProperty (<anonymous>)
  › defineProperty (/Users/katesills/code/agoric-sdk/node_modules/define-properties/index.js:34:3)
  › defineProperties (/Users/katesills/code/agoric-sdk/node_modules/define-properties/index.js:52:3)
  › Object.<anonymous> (/Users/katesills/code/agoric-sdk/node_modules/object.assign/index.js:11:1)
  › Object.<anonymous> (/Users/katesills/code/agoric-sdk/node_modules/enzyme/build/ReactWrapper.js:11:15)
  › Object.<anonymous> (/Users/katesills/code/agoric-sdk/node_modules/enzyme/build/index.js:3:21)
  › Generator.next (<anonymous>)
  › Object.<anonymous> (compiled/test/_setup-enzyme-adapter.js:1)
  › Generator.next (<anonymous>)

It seems like the most obvious solution is to change define-property to return early if the object is frozen, but I'm not sure this is the right approach.

var defineProperty = function (object, name, value, predicate) {
    if (Object.isFrozen(object)) {
        return;
    }
    if (name in object && (!isFunction(predicate) || !predicate())) {
        return;
    }
    ...

Thanks!

ljharb commented 3 years ago

hmm - how could the object be frozen? it's a function created inside that file (not the one that gets shimmed to Object, either). What version of object.assign do you have installed?

katelynsills commented 3 years ago

Enzyme seems to be using define-properties v1.1.3 and object.assign v4.1.0.

Object.assign is frozen by SES before this code runs. If I change the define-properties code to include a console.log, I get the following:

var defineProperty = function (object, name, value, predicate) {
    console.log('is object frozen', Object.isFrozen(object), object);
is object frozen true [Function: assign] Function <Function <[Object: null prototype] {}>>
is object frozen true [Function: assign] Function <Function <[Object: null prototype] {}>>
is object frozen true [Function: assign] Function <Function <[Object: null prototype] {}>>
is object frozen true [Function: assign] Function <Function <[Object: null prototype] {}>>
is object frozen true [Function: assign] Function <Function <[Object: null prototype] {}>>
is object frozen true [Function: assign] Function <Function <[Object: null prototype] {}>>
ljharb commented 3 years ago

Ah, that bug was fixed in https://github.com/ljharb/object.assign/commit/fc41c80451738e91c4126075aafd12ebb3e0c25e, which is available in v4.1.1 and higher :-) feel free to update!

katelynsills commented 3 years ago

Ah, that bug was fixed in https://github.com/ljharb/object.assign/commit/fc41c80451738e91c4126075aafd12ebb3e0c25e, which is available in v4.1.1 and higher :-) feel free to update!

Great! Thank you!