Skip to content

Instantly share code, notes, and snippets.

@caitp
Created May 1, 2015 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caitp/889d1c39728d4556f43b to your computer and use it in GitHub Desktop.
Save caitp/889d1c39728d4556f43b to your computer and use it in GitHub Desktop.
CL#1104223002 difficulties
(function() {
// Totally fine, no problem resolving function declarations:
"use strict";
function A() { return "hi!"; }
function B() { return C(A); }
function C(F) { return F(); }
return B();
})() // "hi!"
(function() {
"use strict";
// Totally fine, even with the default param in A, no FunctionDeclaration needs to be resolved, works great
function A(s = "HI") { return s; }
function B() { return C(A); }
function C(F) { return F(); }
return B();
})() // "HI"
(function(x = 1) {
"use strict";
function A() { return "HI"; }
function B() { return C(A); }
function C(F) { return F(); }
// Problem: `B` resolves to undefined. It's a maze trying to figure out why,
// because non-function declarations resolve just fine
return B();
})() // TypeError: B is not a function
@caitp
Copy link
Author

caitp commented May 1, 2015

Mystery solved, my Scope::AddDeclaration() hack doesn't deal with this in strict mode, because the declaration type isLET there.

@caitp
Copy link
Author

caitp commented May 1, 2015

with the adjustment above, there's a new problem :(

(function(x = 1) {
  "use strict";
  function A() { return "HI"; }
  // Problem: `C` apparently doesn't resolve. It's a maze trying to figure out why,
  // because non-function declarations resolve just fine, and calling `B` worked
  // just fine too. -_____-------- Walking through in the debugger, it looks like it does
  // actually resolve :|
  function B() { return C(A); }
  function C(F) { return F(); }
  return B();
})() // ReferenceError: C is not defined

;____; --- there's got to be a better way

@caitp
Copy link
Author

caitp commented May 1, 2015

The DeclareDynamicGlobal() path gets taken sometimes, and C isn't declared in the global scope normally, so... :((

@caitp
Copy link
Author

caitp commented May 1, 2015

Bug occurs when Compiler::GetLazyCode() is used, it makes sense because the scope hierarchy is totally messed up (which would be why it gets this wrong). I'm not sure why this worked before

@caitp
Copy link
Author

caitp commented May 4, 2015

# --no-lazy
(lldb) r  --test --random-seed=1337758917 --nocrankshaft --nohard-abort --nodead-code-elimination --nofold-constants --enable-slow-asserts --debug-code --verify-heap /Users/caitp/v8/test/mjsunit/mjsunit.js /Users/caitp/v8/test/mjsunit/harmony/optional-arguments.js --no-lazy
Process 73551 launched: '/Users/caitp/v8/out/x64.debug/d8' (x86_64)
Process 73551 exited with status = 0 (0x00000000)

# not --no-lazy
(lldb) r  --test --random-seed=1337758917 --nocrankshaft --nohard-abort --nodead-code-elimination --nofold-constants --enable-slow-asserts --debug-code --verify-heap /Users/caitp/v8/test/mjsunit/mjsunit.js /Users/caitp/v8/test/mjsunit/harmony/optional-arguments.js
Process 73517 launched: '/Users/caitp/v8/out/x64.debug/d8' (x86_64)
/Users/caitp/v8/test/mjsunit/mjsunit.js:178: Failure: expected <Object <Error()> is not an instance of <ReferenceError> but of < SyntaxError>> found <undefined>
    throw new MjsUnitAssertionError(message);
    ^
Error
    at new MjsUnitAssertionError (/Users/caitp/v8/test/mjsunit/mjsunit.js:31:16)
    at fail (/Users/caitp/v8/test/mjsunit/mjsunit.js:178:11)
    at assertInstanceof (/Users/caitp/v8/test/mjsunit/mjsunit.js:345:7)
    at assertThrows (/Users/caitp/v8/test/mjsunit/mjsunit.js:326:9)
    at /Users/caitp/v8/test/mjsunit/harmony/optional-arguments.js:58:4

Process 73517 exited with status = 1 (0x00000001) 
(lldb) 

I'm gonna cry /).(\

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment