Node: Runtime.evaluate throws error even when there is no side effects.

Created on 28 Aug 2018  路  9Comments  路  Source: nodejs/node

Hello Everyone,

I was just trying to play around with inspector and noticed we have a bug in version : v10.5.0. Here is the sample code:

const inspector = require('inspector');

const session = new inspector.Session();
session.connect();
session.post('Runtime.evaluate',{
    expression : '[1,0,5].sort()',
    generatePreview: true,
    throwOnSideEffect: true,
}, (error, { result }) => console.log(result));

Running this code on version 10.5.0 gives me back:

{ type: 'object',
  subtype: 'error',
  className: 'EvalError',
  description:
   'EvalError: Possible side-effect in debug-evaluate\n    at Session.post (inspector.js:85:28)\n    at Object.<anonymous> (/Users/anto/programs/node/repl/src/test.js:9:9)\n    at Module._compile (internal/modules/cjs/loader.js:702:30)\n    at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)\n    at Module.load (internal/modules/cjs/loader.js:612:32)\n    at tryModuleLoad (internal/modules/cjs/loader.js:551:12)\n    at Function.Module._load (internal/modules/cjs/loader.js:543:3)\n    at Function.Module.runMain (internal/modules/cjs/loader.js:744:10)\n    at startup (internal/bootstrap/node.js:240:19)\n    at bootstrapNodeJSCore (internal/bootstrap/node.js:564:3)',
  objectId: '{"injectedScriptId":1,"id":1}' }

which seems to be wrong. Since the expression [1,0,5].sort() doesn't have any side effects. The same code works on the current version (i.e 10.9.0). Gives the output:

{ type: 'object',
  subtype: 'array',
  className: 'Array',
  description: 'Array(3)',
  objectId: '{"injectedScriptId":1,"id":1}',
  preview: 
   { type: 'object',
     subtype: 'array',
     description: 'Array(3)',
     overflow: false,
     properties: [ [Object], [Object], [Object] ] } }

May be an issue in v8? Thanks for looking into this.

Edit:

Just checked it's even working in v10.0.0.

Most helpful comment

Sorting an ad-hoc defined array has no side effects, since that doesn't change global state observably. That feature has only been implemented fairly recently though.

All 9 comments

Array.prototype.sort sorts the array in place.

@devsnek Yes. But here I'm giving a new array and then sorting on the fly. I feel there is no side-effects here (may be I'm wrong). But then, why does 10.5.0 alone throws this error? Why not 10.9.0 ? 馃

So I have enabled lazy evaluation on chrome and I tried this:

image

So the above case makes sense as the code is not side effect free as it changes the value of a (as you had said .sort changes in place). However looking at the below code (which I posted):

image

seems to be a valid code without any side effect.

May be I'm missing something here? 馃

@antsmartian that looks like a bug in whatever version of v8 your chrome is using.

/cc @nodejs/v8

@devsnek Hmmm, thanks for the response. (Anyways, I'm still confused on this).

But if thats the case, in node 10.9.0 its working without throwing any issues as such which then contradicts with our discussion here.

Can someone tell me if my interpretation of this thread is correct?

  • 10.0.0: works
  • 10.5.0: doesn't work
  • 10.9.0: works

If so (and assuming v11.x works) then I'd move to close this, since older releases in a release branch are not supported.

@timothyGu Yes, you are correct with your interpretation.

Okay. To reiterate, only the latest release in a active release branch is supported.

Sorting an ad-hoc defined array has no side effects, since that doesn't change global state observably. That feature has only been implemented fairly recently though.

Was this page helpful?
0 / 5 - 0 ratings