aboutsummaryrefslogtreecommitdiff
path: root/src/ffi.js
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2021-08-29 16:15:15 +0100
committerLouis Pilfold <louis@lpil.uk>2021-08-29 16:15:15 +0100
commit61fd456ecf2763202df299ab92b09adffe2c2c2d (patch)
tree796b113b4b800a92fb94c8db7ea13bc89b600584 /src/ffi.js
parentd7cf6c9a27487b182c1e6d832a58e01d022b97fa (diff)
downloadjavascript-61fd456ecf2763202df299ab92b09adffe2c2c2d.tar.gz
javascript-61fd456ecf2763202df299ab92b09adffe2c2c2d.zip
JavaScript module
Diffstat (limited to 'src/ffi.js')
-rw-r--r--src/ffi.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/ffi.js b/src/ffi.js
index c0b2076..07e7b0f 100644
--- a/src/ffi.js
+++ b/src/ffi.js
@@ -1,4 +1,14 @@
import { Ok, Error } from "./gleam.js";
+import {
+ UndefinedType,
+ ObjectType,
+ BooleanType,
+ NumberType,
+ BigIntType,
+ StringType,
+ SymbolType,
+ FunctionType,
+} from "./gleam/javascript.js";
export function toArray(list) {
return list.toArray();
@@ -23,3 +33,34 @@ export function reduceRight(thing, acc, fn) {
export function index(thing, index) {
return index in thing ? new Ok(thing[index]) : new Error(undefined);
}
+
+export function object_from_entries(entries) {
+ return Object.fromEntries(entries);
+}
+
+export function type_of(value) {
+ switch (typeof value) {
+ case "undefined":
+ return new UndefinedType();
+ case "object":
+ return new ObjectType();
+ case "boolean":
+ return new BooleanType();
+ case "number":
+ return new NumberType();
+ case "bigint":
+ return new BigIntType();
+ case "string":
+ return new StringType();
+ case "symbol":
+ return new SymbolType();
+ case "function":
+ return new FunctionType();
+ default:
+ throw new globalThis.Error(`Unexpected typeof ${typeof value}`);
+ }
+}
+
+export function get_symbol(name) {
+ return Symbol.for(name);
+}