Skip to content

Commit 48938c3

Browse files
committed
Beginnings of implementing binary_to_term
1 parent cc874f3 commit 48938c3

File tree

1 file changed

+18
-6
lines changed
  • src/javascript/lib/core/erlang_compat

1 file changed

+18
-6
lines changed

src/javascript/lib/core/erlang_compat/erlang.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,7 @@ function is_atom(value) {
105105
return true;
106106
}
107107

108-
return (
109-
typeof value === 'symbol' ||
110-
value instanceof Symbol ||
111-
value.__MODULE__ != null
112-
);
108+
return typeof value === 'symbol' || value instanceof Symbol || value.__MODULE__ != null;
113109
}
114110

115111
function is_bitstring(value) {
@@ -407,6 +403,22 @@ function function_exported(module, _function) {
407403
return module[_function] != null;
408404
}
409405

406+
function binary_to_term(binary) {
407+
let data = null;
408+
409+
if (is_binary(binary)) {
410+
const buf = new ArrayBuffer(binary.length);
411+
const bufView = new Uint16Array(buf);
412+
for (const i = 0, strLen = str.length; i < strLen; i++) {
413+
bufView[i] = binary.charCodeAt(i);
414+
}
415+
416+
data = bufView;
417+
} else {
418+
data = Uint8Array.of(...binary);
419+
}
420+
}
421+
410422
export default {
411423
atom_to_binary,
412424
binary_to_atom,
@@ -472,5 +484,5 @@ export default {
472484
exit,
473485
raise,
474486
list_to_binary,
475-
nodes
487+
nodes,
476488
};

0 commit comments

Comments
 (0)