Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue with passing objcet, recursion and null value #146

Open
antxxxx opened this issue Feb 12, 2016 · 2 comments
Open

issue with passing objcet, recursion and null value #146

antxxxx opened this issue Feb 12, 2016 · 2 comments

Comments

@antxxxx
Copy link

antxxxx commented Feb 12, 2016

There seems to be a problem with passing an object using recursion where the value passed is null.

This code

function clone (obj) {
  var cloned;
  if (isType(obj, 'Object') ) {
    cloned = {};
    Object.keys(obj).forEach(function (key) {
      cloned[key] = clone(obj[key]);
    });
  } else {
    cloned = obj;
  }
  return cloned;
}

function isType (obj, type) {
  if (type === 'Undefined') {
    return typeof obj === 'undefined';
  } else {
    return Object.prototype.toString.call(obj) === '[object ' + type + ']';
  }
}

var obj = {a: {b: {c: {d: 1}}, e: {f: 2}}}
obj.a.b.c.d = null
var b = clone(obj)

works fine using node 0.10.32 but fails with the following error when run using triereme

TypeError: Expected argument of type object, but instead had type object
TypeError: Expected argument of type object, but instead had type object
    at clone (C:\git\Source\Repos\jlapigee\api\test-api\test.js:7)
    at C:\git\Source\Repos\jlapigee\api\test-api\test.js:8
    at clone (C:\git\Source\Repos\jlapigee\api\test-api\test.js:7)
    at C:\git\Source\Repos\jlapigee\api\test-api\test.js:8
    at clone (C:\git\Source\Repos\jlapigee\api\test-api\test.js:7)
    at C:\git\Source\Repos\jlapigee\api\test-api\test.js:8
    at clone (C:\git\Source\Repos\jlapigee\api\test-api\test.js:7)
    at C:\git\Source\Repos\jlapigee\api\test-api\test.js:8
    at clone (C:\git\Source\Repos\jlapigee\api\test-api\test.js:7)
    at C:\git\Source\Repos\jlapigee\api\test-api\test.js:28
    at module.js:456
    at module.js:474
    at module.js:356
    at module.js:312
    at module.js:497
    at startup (trireme.js:142)
    at trireme.js:923
@gbrail
Copy link
Contributor

gbrail commented Feb 12, 2016

Thank you for pulling together this nice reproducer. It breaks the same way for me.

The weird thing is that the code works fine in Rhino. It's just Trireme that is causing this behavior, by somehow doing something to the value of "null."

I don't know what is going on there yet unfortunately.

@whitlockjc
Copy link
Member

I just tried to reproduce this and the sample script above runs without issue, as in no error produced. I do think this is related to #157 since any function called with null as the sole argument would end up with the argument being replaced with the global object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants