maekawatoshiki / rapidus

ECMAScript implementation in Rust
MIT License
519 stars 21 forks source link

implement catch parameter. #22

Closed sisshiki1969 closed 5 years ago

sisshiki1969 commented 5 years ago

Now, catch parameter and block scope in catch clause are available.

limitations: In catch clause, function arguments can be get, but can not be changed through arguments[].

here is a test code.

function func(a, b, c) {
  var str = "arguments = [ "
  for (var i = 0; i < 3; i++) {
    str += arguments[i] + " "
  }
  str += "]"
  console.log("[a, b, c] = [", a, b, c, "]")
  console.log(str)
  try {
    arguments[0] = 100
    throw "error"
  } catch(ex) {
    arguments[1] = 200
  } finally {
    var str = "arguments = [ "
    for (var i = 0; i < 3; i++) {
      str += arguments[i] + " "
    }
    str += "]"
    console.log("[a, b, c] = [", a, b, c, "]")
    console.log(str)
  }
}

function p(ary) {
  var str = ""
  for (var i = 0; i < 3; i++) {
    str += arguments[i] + " "
  }
  console.log(str)
}

func(0, 1, 2)
(node.js)
[a, b, c] = [ 0 1 2 ]
arguments = [ 0 1 2 ]
[a, b, c] = [ 100 200 2 ]
arguments = [ 100 200 2 ]

(current implementation of rapidus)
[a, b, c] = [ 0 1 2 ]
arguments = [ 0 1 2 ]
[a, b, c] = [ 100 1 2 ]
arguments = [ 100 1 2 ]
maekawatoshiki commented 5 years ago

Looks great.

maekawatoshiki commented 5 years ago

This code doesn't work well:

function fail() { throw "something went wrong" }

function a() { throw 123 }

try {
  try {
    a()
  } catch (x) {
    console.log('-->', x);
  };
  fail()
} catch (e) {
  console.log("->", e);
} 
sisshiki1969 commented 5 years ago

Sorry, I checked your reply now. I send PR for bug fix last night, but I don't know if it works for the bug you reported. I will check it tonight.