Skip to content

Commit fadd073

Browse files
committed
Runtime: bigstring_destroy_stub
1 parent 40d6863 commit fadd073

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

runtime/bigstring.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,24 @@ function bigstring_alloc(_,size){
66
}
77

88
//Provides: bigstring_destroy_stub
9-
function bigstring_destroy_stub(_v) {
10-
return 0; // noop
9+
//Requires: caml_invalid_argument, caml_ba_create_from
10+
function bigstring_destroy_stub(v_bstr) {
11+
if (v_bstr.data2 != null) {
12+
caml_invalid_argument("bigstring_destroy: unsupported kind");
13+
}
14+
15+
if (v_bstr.hasOwnProperty('__is_deallocated')) {
16+
caml_invalid_argument("bigstring_destroy: bigstring is already deallocated");
17+
}
18+
19+
var destroyed_data = new v_bstr.data.__proto__.constructor(0);
20+
var destroyed_bigstring =
21+
caml_ba_create_from(destroyed_data, null, v_bstr.data_type, v_bstr.kind,
22+
v_bstr.layout, [0]);
23+
destroyed_bigstring.__is_deallocated = true;
24+
25+
// Mutate the original bigstring in-place, to simulate what the C version does
26+
Object.assign(v_bstr, destroyed_bigstring);
1127
}
1228

1329
//Provides: bigstring_blit_bigstring_bytes_stub

0 commit comments

Comments
 (0)