Skip to content

Assignment to const results in panic #622

Closed

Description

@elasmojs

Hi

Assignment to const causes panic instead of expected TypeError

const number = 42;

try {
    number = 99;
} catch (err) {
    console.log(err);
    // expected output: TypeError: invalid assignment to const `number'
    // Note - error messages will vary depending on browser
}

console.log(number);
// expected output: 42

thanks

Activity

  1. added
    A-Bug
    on Aug 9, 2020
  2. 54k1 commented on Aug 11, 2020

    @54k1
    Contributor

    There's a TODO mark for many of the methods in environment module. Are they supposed return ResultValue to indicate success or a failure so that the call sites can be notified upon errors and can handle them appropriately?

    @HalidOdat could you verify this? Thanks.

  3. HalidOdat commented on Aug 11, 2020

    @HalidOdat
    Member

    There's a TODO mark for many of the methods in environment module. Are they supposed return ResultValue to indicate success or a failure so that the call sites can be notified upon errors and can handle them appropriately?

    @HalidOdat could you verify this? Thanks.

    Yes. the environments were set up before exceptions (TypeError, ReferenceError, etc), one way of solving this is to use ResultValue this would require the Interpreter to be passed to every call. Another way is to create a Error enum, that contains, the error type and message and return Result<TheNormalReturntype, Error>, and when we call those function when we need to throw we convert them to a javascript Error (TypeError, RangeError, etc) type. This has the advantage that we dont need to introduce the interpreter to the environments

  4. 54k1 commented on Aug 11, 2020

    @54k1
    Contributor

    Thanks for confirming this and suggesting the approach. Could I take this up?

  5. HalidOdat commented on Aug 11, 2020

    @HalidOdat
    Member

    Thanks for confirming this and suggesting the approach. Could I take this up?

    sure! :)

  6. added
    A-Execution
    on Aug 11, 2020
  7. Razican commented on Oct 8, 2020

    @Razican
    Member

    @54k1 let us know if you need any further guidance.

  8. added this to the v0.11.0 milestone on Oct 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-BugA-Execution

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions