Skip to content

Object.assign() should copy undefined properties, I think #780

@dcitron

Description

@dcitron

Hi! It looks like Object.assign() should copy undefined properties:

console.log(Object.assign({"a":undefined}, {"b":undefined}))
Object { a: undefined, b: undefined }

However, the Rhino code is skipping undefined values:

          case ConstructorId_assign:
          {
            if (args.length < 1) {
              throw ScriptRuntime.typeError1("msg.incompat.call", "assign");
            }
            Scriptable targetObj = ScriptRuntime.toObject(cx, thisObj, args[0]);
            for (int i = 1; i < args.length; i++) {
              if ((args[i] == null) || Undefined.isUndefined(args[i])) {
                continue;
              }
              Scriptable sourceObj = ScriptRuntime.toObject(cx, thisObj, args[i]);
              Object[] ids = sourceObj.getIds();
              for (Object key : ids) {
                if (key instanceof String) {
                  Object val = sourceObj.get((String) key, sourceObj);
                  if ((val != Scriptable.NOT_FOUND) && !Undefined.isUndefined(val)) { // <=== HERE
                    targetObj.put((String) key, targetObj, val);
                  }
                } else if (key instanceof Number) {
                  int ii = ScriptRuntime.toInt32(key);
                  Object val = sourceObj.get(ii, sourceObj);
                  if ((val != Scriptable.NOT_FOUND) && !Undefined.isUndefined(val)) {  // <=== AND HERE
                    targetObj.put(ii, targetObj, val);
                  }
                }
              }
            }
            return targetObj;
          }

Is there a reason for those !Undefined.isUndefined(val) checks?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Ecma IncompatibilityIssues about Rhino being incompatible with the EcmaScript specbugIssues considered a buggood first issueGreat place to start if you're looking to start an open source "resume"

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions