1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. GTA Network forum is now in archive mode.

Closed ClearScript AddHostObject overwrite not erroring

Discussion in 'Solved & Closed' started by Katalina, May 27, 2017.

  1. Katalina

    Katalina Member Developer

    Likes Received:
    May 14, 2017
    ClearScript AddHostObject overwrite not erroring
    What's wrong?:
    (This is intended for devs to pass on to ClearScript issues, just to be clear. I can't build a reproduction case without a lot of effort. Sorry if this is in the wrong place. This is also something you can solve without a ClearScript patch.)

    So, in Node.js and.. well.. every other V8 implementation, trying to create variables via let/const that match ones in global scope will return a SyntaxError at runtime.

    module.exports = { stuff() {} }
    const module = 'aaaa'
    Uncaught SyntaxError: Identifier 'module' has already been declared
    This is exactly the same thing that happens when you do
    function test(someValue) {
      const someValue = true // SyntaxError
    So given that, we can assume 'module' is passed outside of the view of the file like the file is inside a function, being passed arguments (which it is.)

    function doGlobalScopeThing(exported) {
      return (function(exported) {
        // i can't see anything above this, inside 'file.js'
       exported.something() // this shouldn't be undefined (but it is)
       const exported = { yes: true } // this should syntaxerror
        // i can't see anything below this, end of 'file.js'
    But in the way your ClearScript runner is set up, this isn't the case. the AddHostObject call isn't magically creating something V8 sees as defined, but exists when it's called.

    So, if you do...
    API.onResourceStart.connect(() => {
      let aThing = resource.aThing
    const resource = { yes: true }
    the const clobbers the 'resource' object, and makes it undefined until it's defined at the end, a.k.a. completely useless.

    You can just tell me, "don't do that, that's really dumb." but it should error. In some way, shape, or form, this should error. Not destroy objects.​
    What should normally happen?:
    see what's wrong
    How to reproduce the issue:
    see what's wrong

Share This Page