mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 05:50:30 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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: "(!#)".}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user