add ** to jsffi (#16141)

* fix rope index

* add testcase

* fix ropes format

* add `**` to jsffi

* add testcase

* changelog

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
flywind
2020-11-27 03:30:19 +08:00
committed by GitHub
parent 4fdaded227
commit 70a1c42542
3 changed files with 35 additions and 1 deletions

View File

@@ -47,6 +47,7 @@
- `repr` now doesn't insert trailing newline; previous behavior was very inconsistent,
see #16034. Use `-d:nimLegacyReprWithNewline` for previous behavior.
- Added `**` to jsffi.
- `writeStackTrace` is available in JS backend now.
## Language changes

View File

@@ -180,6 +180,7 @@ proc `>` *(x, y: JsObject): JsObject {.importcpp: "(# > #)".}
proc `<` *(x, y: JsObject): JsObject {.importcpp: "(# < #)".}
proc `>=` *(x, y: JsObject): JsObject {.importcpp: "(# >= #)".}
proc `<=` *(x, y: JsObject): JsObject {.importcpp: "(# <= #)".}
proc `**` *(x, y: JsObject): JsObject {.importcpp: "((#) ** #)".}
proc `and`*(x, y: JsObject): JsObject {.importcpp: "(# && #)".}
proc `or` *(x, y: JsObject): JsObject {.importcpp: "(# || #)".}
proc `not`*(x: JsObject): JsObject {.importcpp: "(!#)".}

View File

@@ -323,7 +323,6 @@ block:
console.log jsarguments[0]
block:
echo jsUndefined == jsNull
echo jsUndefined == nil
echo jsNull == nil
@@ -331,3 +330,36 @@ block:
echo jsNull.isNil
echo jsNull.isNull
echo jsUndefined.isUndefined
block: # test **
var a = toJs(0)
var b = toJs(0)
doAssert to(a ** b, int) == 1
a = toJs(1)
b = toJs(1)
doAssert to(a ** b, int) == 1
a = toJs(-1)
b = toJs(-1)
doAssert to(a ** b, int) == -1
a = toJs(6)
b = toJs(6)
doAssert to(a ** b, int) == 46656
a = toJs(5.5)
b = toJs(3)
doAssert to(a ** b, float) == 166.375
a = toJs(5)
b = toJs(3.0)
doAssert to(a ** b, float) == 125.0
a = toJs(7.0)
b = toJS(6.0)
doAssert to(a ** b, float) == 117649.0
a = toJs(8)
b = toJS(-2)
doAssert to(a ** b, float) == 0.015625
a = toJs(1)
b = toJs(1)
doAssert to(`**`(a + a, b), int) == 2
doAssert to(`**`(toJs(1) + toJs(1), toJs(2)), int) == 4