Skip to content

Fix some primitives usage #7114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/es6/Error.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@


import * as Primitive_option from "./Primitive_option.js";

function fromException(exn) {
if (exn.TAG === "Ok") {
return;
} else {
return Primitive_option.some(exn._0);
}
}

let $$EvalError = {};

Expand All @@ -18,6 +27,7 @@ function panic(msg) {
}

export {
fromException,
$$EvalError,
$$RangeError,
$$ReferenceError,
Expand Down
10 changes: 10 additions & 0 deletions lib/js/Error.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
'use strict';

let Primitive_option = require("./Primitive_option.js");

function fromException(exn) {
if (exn.TAG === "Ok") {
return;
} else {
return Primitive_option.some(exn._0);
}
}

let $$EvalError = {};

Expand All @@ -17,6 +26,7 @@ function panic(msg) {
throw new Error("Panic! " + msg);
}

exports.fromException = fromException;
exports.$$EvalError = $$EvalError;
exports.$$RangeError = $$RangeError;
exports.$$ReferenceError = $$ReferenceError;
Expand Down
6 changes: 5 additions & 1 deletion runtime/Error.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
type t = Js.Exn.t

external fromException: exn => option<t> = "?as_js_exn"
let fromException: exn => option<t> = exn =>
switch Obj.magic(exn) {
| Error(t) => Some(t)
| _ => None
}
external toException: t => exn = "%identity"

@get external stack: t => option<string> = "stack"
Expand Down
2 changes: 1 addition & 1 deletion runtime/Error.resi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ See [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/
/** Represents a JavaScript exception. */
type t = Js.Exn.t

external fromException: exn => option<t> = "?as_js_exn"
let fromException: exn => option<t>

/**
Turns an `Error.t` into an `exn`.
Expand Down
2 changes: 1 addition & 1 deletion runtime/Float.res
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ let fromString = i =>
external toInt: float => int = "%intoffloat"
external fromInt: int => float = "%identity"

@unboxed @noalloc external mod: (float, float) => float = "?fmod_float"
external mod: (float, float) => float = "%modfloat"

let clamp = (~min=?, ~max=?, value): float => {
let value = switch max {
Expand Down
2 changes: 1 addition & 1 deletion runtime/Float.resi
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ external fromInt: int => float = "%identity"
Float.mod(7.0, 4.0) == 3.0
```
*/
external mod: (float, float) => float = "?fmod_float"
external mod: (float, float) => float = "%modfloat"

/**
`clamp(~min=?, ~max=?, value)` returns `value`, optionally bounded by `min` and `max`.
Expand Down
4 changes: 2 additions & 2 deletions runtime/Pervasives.res
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ external floor: float => float = "floor"
external abs_float: float => float = "abs"

@deprecated("Use Core instead. This will be removed in v13")
external mod_float: float => float = "%modfloat"
external mod_float: (float, float) => float = "%modfloat"

@deprecated("Use Core instead. This will be removed in v13")
external float: int => float = "%floatofint"
Expand Down Expand Up @@ -549,7 +549,7 @@ async function main() {
}
```
*/
external import: 'a => promise<'a> = "#import"
external import: 'a => promise<'a> = "%import"

type null<+'a> = Js.null<'a>

Expand Down