MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

clean up unused slots

+108 -460
+73 -80
include/common.h
··· 5 5 #include <stdio.h> 6 6 #include <stdlib.h> 7 7 8 + #define ANT_INTERNAL_SLOT_LIST(X) \ 9 + X(SLOT_NONE) \ 10 + X(SLOT_ASYNC) \ 11 + X(SLOT_CODE) \ 12 + X(SLOT_CODE_LEN) \ 13 + X(SLOT_CFUNC) \ 14 + X(SLOT_CORO) \ 15 + X(SLOT_PROTO) \ 16 + X(SLOT_FUNC_PROTO) \ 17 + X(SLOT_ASYNC_PROTO) \ 18 + X(SLOT_AUX) \ 19 + X(SLOT_TARGET_FUNC) \ 20 + X(SLOT_MODULE_CTX) \ 21 + X(SLOT_MODULE_LOADING) \ 22 + X(SLOT_MAP) \ 23 + X(SLOT_SET) \ 24 + X(SLOT_PRIMITIVE) \ 25 + X(SLOT_PROXY_REF) \ 26 + X(SLOT_BUILTIN) \ 27 + X(SLOT_BRAND) \ 28 + X(SLOT_DATA) \ 29 + X(SLOT_CTOR) \ 30 + X(SLOT_FS_FLAGS) \ 31 + X(SLOT_DEFAULT) \ 32 + X(SLOT_ERROR_BRAND) \ 33 + X(SLOT_ERR_TYPE) \ 34 + X(SLOT_OBSERVABLE_SUBSCRIBER) \ 35 + X(SLOT_SUBSCRIPTION_OBSERVER) \ 36 + X(SLOT_SUBSCRIPTION_CLEANUP) \ 37 + X(SLOT_STRICT_ARGS) \ 38 + X(SLOT_ITER_STATE) \ 39 + X(SLOT_ENTRIES) \ 40 + X(SLOT_SETTLED) \ 41 + X(SLOT_WT_ON_MESSAGE) \ 42 + X(SLOT_WT_ONCE_MESSAGE) \ 43 + X(SLOT_WT_ON_EXIT) \ 44 + X(SLOT_WT_ONCE_EXIT) \ 45 + X(SLOT_WT_PORT_TAG) \ 46 + X(SLOT_WT_PORT_QUEUE) \ 47 + X(SLOT_WT_PORT_HEAD) \ 48 + X(SLOT_WT_PORT_PEER) \ 49 + X(SLOT_WT_PORT_CLOSED) \ 50 + X(SLOT_WT_PORT_STARTED) \ 51 + X(SLOT_WT_PORT_ON_MESSAGE) \ 52 + X(SLOT_WT_PORT_ONCE_MESSAGE) \ 53 + X(SLOT_WT_PORT_PROTO) \ 54 + X(SLOT_WT_ENV_STORE) \ 55 + X(SLOT_NAPI_EXTERNAL_ID) \ 56 + X(SLOT_NAPI_WRAP_ID) \ 57 + X(SLOT_RS_PULL) \ 58 + X(SLOT_RS_CANCEL) \ 59 + X(SLOT_RS_SIZE) \ 60 + X(SLOT_RS_CLOSED) \ 61 + X(SLOT_WS_WRITE) \ 62 + X(SLOT_WS_CLOSE) \ 63 + X(SLOT_WS_ABORT) \ 64 + X(SLOT_WS_READY) \ 65 + X(SLOT_WS_SIGNAL) \ 66 + X(SLOT_HEADERS_GUARD) \ 67 + X(SLOT_REQUEST_HEADERS) \ 68 + X(SLOT_REQUEST_SIGNAL) \ 69 + X(SLOT_REQUEST_ABORT_REASON) \ 70 + X(SLOT_REQUEST_BODY_STREAM) \ 71 + X(SLOT_RESPONSE_HEADERS) \ 72 + X(SLOT_RESPONSE_BODY_STREAM) \ 73 + X(SLOT_PIPE_ABORT_LISTENER) \ 74 + X(SLOT_MATCHALL_RX) \ 75 + X(SLOT_MATCHALL_STR) \ 76 + X(SLOT_MATCHALL_DONE) 77 + 78 + #define ANT_DECLARE_INTERNAL_SLOT(name) name, 8 79 typedef enum { 9 - SLOT_NONE = 0, 10 - SLOT_PID, 11 - SLOT_ASYNC, 12 - SLOT_WITH, 13 - SLOT_THIS, 14 - SLOT_NEW_TARGET, 15 - SLOT_FIELD_COUNT, 16 - SLOT_FIELDS, 17 - SLOT_STRICT, 18 - SLOT_CODE, 19 - SLOT_CODE_LEN, 20 - SLOT_CFUNC, 21 - SLOT_CORO, 22 - SLOT_PROTO, 23 - SLOT_FUNC_PROTO, 24 - SLOT_ASYNC_PROTO, 25 - SLOT_AUX, 26 - SLOT_TARGET_FUNC, 27 - SLOT_NAME, 28 - SLOT_MODULE_CTX, 29 - SLOT_MODULE_LOADING, 30 - SLOT_MAP, 31 - SLOT_SET, 32 - SLOT_PRIMITIVE, 33 - SLOT_PROXY_REF, 34 - SLOT_BUILTIN, 35 - SLOT_BRAND, 36 - SLOT_DATA, 37 - SLOT_CTOR, 38 - SLOT_FS_FLAGS, 39 - SLOT_DEFAULT, 40 - SLOT_ERROR_BRAND, 41 - SLOT_ERR_TYPE, 42 - SLOT_OBSERVABLE_SUBSCRIBER, 43 - SLOT_SUBSCRIPTION_OBSERVER, 44 - SLOT_SUBSCRIPTION_CLEANUP, 45 - SLOT_HOISTED_VARS, 46 - SLOT_HOISTED_VARS_LEN, 47 - SLOT_STRICT_ARGS, 48 - SLOT_NO_FUNC_DECLS, 49 - SLOT_ITER_STATE, 50 - SLOT_BYTECODE, 51 - SLOT_ENTRIES, 52 - SLOT_SETTLED, 53 - SLOT_WT_ON_MESSAGE, 54 - SLOT_WT_ONCE_MESSAGE, 55 - SLOT_WT_ON_EXIT, 56 - SLOT_WT_ONCE_EXIT, 57 - SLOT_WT_PORT_TAG, 58 - SLOT_WT_PORT_QUEUE, 59 - SLOT_WT_PORT_HEAD, 60 - SLOT_WT_PORT_PEER, 61 - SLOT_WT_PORT_CLOSED, 62 - SLOT_WT_PORT_STARTED, 63 - SLOT_WT_PORT_ON_MESSAGE, 64 - SLOT_WT_PORT_ONCE_MESSAGE, 65 - SLOT_WT_PORT_PROTO, 66 - SLOT_WT_ENV_STORE, 67 - SLOT_NAPI_EXTERNAL_ID, 68 - SLOT_NAPI_WRAP_ID, 69 - SLOT_RS_PULL, 70 - SLOT_RS_CANCEL, 71 - SLOT_RS_SIZE, 72 - SLOT_RS_CLOSED, 73 - SLOT_WS_WRITE, 74 - SLOT_WS_CLOSE, 75 - SLOT_WS_ABORT, 76 - SLOT_WS_READY, 77 - SLOT_WS_SIGNAL, 78 - SLOT_HEADERS_GUARD, 79 - SLOT_REQUEST_HEADERS, 80 - SLOT_REQUEST_SIGNAL, 81 - SLOT_REQUEST_ABORT_REASON, 82 - SLOT_REQUEST_BODY_STREAM, 83 - SLOT_RESPONSE_HEADERS, 84 - SLOT_RESPONSE_BODY_STREAM, 85 - SLOT_PIPE_ABORT_LISTENER, 86 - SLOT_MATCHALL_RX, 87 - SLOT_MATCHALL_STR, 88 - SLOT_MATCHALL_DONE, 80 + ANT_INTERNAL_SLOT_LIST(ANT_DECLARE_INTERNAL_SLOT) 89 81 SLOT_MAX = 255 90 82 } internal_slot_t; 83 + #undef ANT_DECLARE_INTERNAL_SLOT 91 84 92 85 typedef enum { 93 86 BUILTIN_NONE = 0,
-15
include/oxc.h
··· 18 18 size_t error_output_len 19 19 ); 20 20 21 - char *OXC_get_hoisted_vars( 22 - const char *input, 23 - size_t input_len, 24 - size_t *out_len 25 - ); 26 - 27 - char *OXC_get_func_hoisted_vars( 28 - const char *input, 29 - size_t input_len, 30 - size_t *out_len 31 - ); 32 - 33 - void OXC_free_hoisted_vars(char *ptr, size_t len); 34 - void OXC_free_stripped_output(char *ptr, size_t len); 35 - 36 21 #endif
-11
src/ant.c
··· 32 32 #include "silver/engine.h" 33 33 34 34 #include <uv.h> 35 - #include <oxc.h> 36 35 #include <assert.h> 37 36 #include <pcre2.h> 38 37 #include <stdio.h> ··· 2609 2608 const char *arena_code = code_arena_alloc(code, len); 2610 2609 if (!arena_code) return; 2611 2610 set_func_code_ptr(js, func_obj, arena_code, len); 2612 - 2613 - if (!memmem(code, len, "var", 3)) return; 2614 - 2615 - size_t vars_buf_len; 2616 - char *vars = OXC_get_func_hoisted_vars(code, len, &vars_buf_len); 2617 - 2618 - if (vars) { 2619 - set_slot(func_obj, SLOT_HOISTED_VARS, mkval(T_CFUNC, (size_t)vars)); 2620 - set_slot(func_obj, SLOT_HOISTED_VARS_LEN, tov((double)vars_buf_len)); 2621 - } 2622 2611 } 2623 2612 2624 2613 static const char *get_func_code(ant_t *js, ant_value_t func_obj, ant_offset_t *len) {
+20 -51
src/modules/io.c
··· 570 570 } 571 571 572 572 static const char *get_slot_name(internal_slot_t slot) { 573 + #define ANT_SLOT_NAME(name) [name] = &#name[5], 573 574 static const char *slot_names[] = { 574 - [SLOT_NONE] = "NONE", 575 - [SLOT_PID] = "PID", 576 - [SLOT_ASYNC] = "ASYNC", 577 - [SLOT_WITH] = "WITH", 578 - [SLOT_THIS] = "THIS", 579 - [SLOT_NEW_TARGET] = "NEW_TARGET", 580 - [SLOT_FIELD_COUNT] = "FIELD_COUNT", 581 - [SLOT_FIELDS] = "FIELDS", 582 - [SLOT_STRICT] = "STRICT", 583 - [SLOT_CODE] = "CODE", 584 - [SLOT_CODE_LEN] = "CODE_LEN", 585 - [SLOT_CFUNC] = "CFUNC", 586 - [SLOT_CORO] = "CORO", 587 - [SLOT_PROTO] = "PROTO", 588 - [SLOT_FUNC_PROTO] = "FUNC_PROTO", 589 - [SLOT_ASYNC_PROTO] = "ASYNC_PROTO", 590 - [SLOT_AUX] = "AUX", 591 - [SLOT_TARGET_FUNC] = "TARGET_FUNC", 592 - [SLOT_NAME] = "NAME", 593 - [SLOT_MODULE_CTX] = "MODULE_CTX", 594 - [SLOT_MAP] = "MAP", 595 - [SLOT_SET] = "SET", 596 - [SLOT_PRIMITIVE] = "PRIMITIVE", 597 - [SLOT_PROXY_REF] = "PROXY_REF", 598 - [SLOT_BUILTIN] = "BUILTIN", 599 - [SLOT_DATA] = "DATA", 600 - [SLOT_CTOR] = "CTOR", 601 - [SLOT_DEFAULT] = "DEFAULT", 602 - [SLOT_ERROR_BRAND] = "ERROR_BRAND", 603 - [SLOT_ERR_TYPE] = "ERR_TYPE", 604 - [SLOT_OBSERVABLE_SUBSCRIBER] = "OBSERVABLE_SUBSCRIBER", 605 - [SLOT_SUBSCRIPTION_OBSERVER] = "SUBSCRIPTION_OBSERVER", 606 - [SLOT_SUBSCRIPTION_CLEANUP] = "SUBSCRIPTION_CLEANUP", 607 - [SLOT_HOISTED_VARS] = "HOISTED_VARS", 608 - [SLOT_HOISTED_VARS_LEN] = "HOISTED_VARS_LEN", 609 - [SLOT_STRICT_ARGS] = "STRICT_ARGS", 610 - [SLOT_NO_FUNC_DECLS] = "NO_FUNC_DECLS", 611 - [SLOT_ITER_STATE] = "ITER_STATE", 612 - [SLOT_ENTRIES] = "ENTRIES", 575 + ANT_INTERNAL_SLOT_LIST(ANT_SLOT_NAME) 613 576 }; 614 - 577 + #undef ANT_SLOT_NAME 578 + 615 579 if (slot < sizeof(slot_names) / sizeof(slot_names[0]) && slot_names[slot]) { 616 580 return slot_names[slot]; 617 581 } 582 + 618 583 return "UNKNOWN"; 619 584 } 620 585 ··· 622 587 static const char *type_names[] = { 623 588 [T_OBJ] = "object", 624 589 [T_STR] = "string", 625 - [T_UNDEF] = "undefined", 626 - [T_NULL] = "null", 627 - [T_NUM] = "number", 628 - [T_BOOL] = "boolean", 590 + [T_ARR] = "array", 629 591 [T_FUNC] = "function", 630 592 [T_CFUNC] = "function", 631 - [T_ERR] = "error", 632 - [T_ARR] = "array", 593 + [T_CLOSURE] = "closure", 633 594 [T_PROMISE] = "Promise", 634 - [T_TYPEDARRAY] = "TypedArray", 595 + [T_GENERATOR] = "Generator", 596 + [T_UNDEF] = "undefined", 597 + [T_NULL] = "null", 598 + [T_BOOL] = "boolean", 599 + [T_NUM] = "number", 635 600 [T_BIGINT] = "bigint", 636 601 [T_SYMBOL] = "symbol", 637 - [T_GENERATOR] = "Generator", 638 - [T_FFI] = "ffi" 602 + [T_ERR] = "error", 603 + [T_TYPEDARRAY] = "TypedArray", 604 + [T_FFI] = "ffi", 605 + [T_NTARG] = "ntarg", 606 + [T_MAP] = "map", 607 + [T_SET] = "set", 608 + [T_WEAKMAP] = "weakmap", 609 + [T_WEAKSET] = "weakset" 639 610 }; 640 611 641 612 size_t num_types = sizeof(type_names) / sizeof(type_names[0]); ··· 726 697 switch (slot) { 727 698 case SLOT_CODE: 728 699 case SLOT_CFUNC: 729 - case SLOT_HOISTED_VARS: 730 700 fprintf(stream, "<native ptr 0x%" PRIx64 ">", (uint64_t)vdata(slot_val)); 731 701 break; 732 702 case SLOT_CODE_LEN: 733 - case SLOT_HOISTED_VARS_LEN: 734 703 fprintf(stream, "%.0f", js_getnum(slot_val)); 735 704 break; 736 705 default:
+1 -4
src/silver/glue.c
··· 254 254 ant_value_t func_val = mkval(T_FUNC, (uintptr_t)closure); 255 255 if (!child->is_arrow && !child->is_method) 256 256 sv_setup_function_prototype(js, func_obj, func_val); 257 - 258 - if (child->is_strict) 259 - js_set_slot(func_obj, SLOT_STRICT, js_true); 260 - 257 + 261 258 if (child->is_async) { 262 259 js_set_slot(func_obj, SLOT_ASYNC, js_true); 263 260 ant_value_t async_proto = js_get_slot(js->global, SLOT_ASYNC_PROTO);
+3 -9
src/silver/ops/coercion.h
··· 358 358 } 359 359 360 360 ant_value_t arr = js_mkarr(js); 361 - 362 361 if (frame->bp && frame->argc > 0) { 363 - for (int i = 0; i < frame->argc; i++) 364 - js_arr_push(js, arr, frame->bp[i]); 362 + for (int i = 0; i < frame->argc; i++) js_arr_push(js, arr, frame->bp[i]); 365 363 } 366 - 367 - if (sv_frame_is_strict(frame)) 368 - js_set_slot(arr, SLOT_STRICT_ARGS, tov(1)); 369 - else if (vtype(frame->callee) == T_FUNC) 370 - setprop_cstr(js, arr, "callee", 6, frame->callee); 371 - 364 + if (vtype(frame->callee) == T_FUNC) setprop_cstr(js, arr, "callee", 6, frame->callee); 365 + 372 366 js_set_sym(js, arr, get_toStringTag_sym(), js_mkstr(js, "Arguments", 9)); 373 367 ant_value_t array_proto = js_get_ctor_proto(js, "Array", 5); 374 368
+1 -4
src/silver/ops/upvalues.h
··· 121 121 js_setprop(js, func_obj, js->length_str, tov((double)child->param_count)); 122 122 js_set_descriptor(js, func_obj, "length", 6, JS_DESC_C); 123 123 124 - if (is_object_type(module_ctx)) 125 - js_set_slot_wb(js, func_obj, SLOT_MODULE_CTX, module_ctx); 126 - 124 + if (is_object_type(module_ctx)) js_set_slot_wb(js, func_obj, SLOT_MODULE_CTX, module_ctx); 127 125 if (!child->is_arrow && !child->is_method) sv_setup_function_prototype(js, func_obj, func_val); 128 - if (child->is_strict) js_set_slot(func_obj, SLOT_STRICT, js_true); 129 126 130 127 if (child->is_async) { 131 128 js_set_slot(func_obj, SLOT_ASYNC, js_true);
-45
src/strip/Cargo.lock
··· 27 27 checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" 28 28 29 29 [[package]] 30 - name = "base64-simd" 31 - version = "0.8.0" 32 - source = "registry+https://github.com/rust-lang/crates.io-index" 33 - checksum = "339abbe78e73178762e23bea9dfd08e697eb3f3301cd4be981c0f78ba5859195" 34 - dependencies = [ 35 - "outref", 36 - "vsimd", 37 - ] 38 - 39 - [[package]] 40 30 name = "bitflags" 41 31 version = "2.10.0" 42 32 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 233 223 checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" 234 224 235 225 [[package]] 236 - name = "json-escape-simd" 237 - version = "3.0.1" 238 - source = "registry+https://github.com/rust-lang/crates.io-index" 239 - checksum = "a3c2a6c0b4b5637c41719973ef40c6a1cf564f9db6958350de6193fbee9c23f5" 240 - 241 - [[package]] 242 226 name = "libc" 243 227 version = "0.2.180" 244 228 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 310 294 ] 311 295 312 296 [[package]] 313 - name = "outref" 314 - version = "0.5.2" 315 - source = "registry+https://github.com/rust-lang/crates.io-index" 316 - checksum = "1a80800c0488c3a21695ea981a54918fbb37abf04f4d0720c453632255e2ff0e" 317 - 318 - [[package]] 319 297 name = "owo-colors" 320 298 version = "4.2.3" 321 299 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 326 304 version = "0.0.0" 327 305 dependencies = [ 328 306 "oxc_allocator", 329 - "oxc_ast", 330 - "oxc_ast_visit", 331 307 "oxc_codegen", 332 308 "oxc_parser", 333 309 "oxc_semantic", ··· 445 421 "oxc_data_structures", 446 422 "oxc_index", 447 423 "oxc_semantic", 448 - "oxc_sourcemap", 449 424 "oxc_span", 450 425 "oxc_syntax", 451 426 "rustc-hash", ··· 532 507 "oxc_data_structures", 533 508 "oxc_diagnostics", 534 509 "oxc_ecmascript", 535 - "oxc_regular_expression", 536 510 "oxc_span", 537 511 "oxc_syntax", 538 512 "rustc-hash", ··· 575 549 "rustc-hash", 576 550 "self_cell", 577 551 "smallvec", 578 - ] 579 - 580 - [[package]] 581 - name = "oxc_sourcemap" 582 - version = "6.0.1" 583 - source = "registry+https://github.com/rust-lang/crates.io-index" 584 - checksum = "36801dbbd025f2fa133367494e38eef75a53d334ae6746ba0c889fc4e76fa3a3" 585 - dependencies = [ 586 - "base64-simd", 587 - "json-escape-simd", 588 - "rustc-hash", 589 - "serde", 590 - "serde_json", 591 552 ] 592 553 593 554 [[package]] ··· 990 951 version = "0.9.5" 991 952 source = "registry+https://github.com/rust-lang/crates.io-index" 992 953 checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" 993 - 994 - [[package]] 995 - name = "vsimd" 996 - version = "0.8.0" 997 - source = "registry+https://github.com/rust-lang/crates.io-index" 998 - checksum = "5c3082ca00d5a5ef149bb8b555a72ae84c9c59f7250f013ac822ac2e49b19c64" 999 954 1000 955 [[package]] 1001 956 name = "zmij"
+2 -4
src/strip/Cargo.toml
··· 7 7 8 8 [dependencies] 9 9 oxc_allocator = "0.110.0" 10 - oxc_parser = "0.110.0" 11 10 oxc_span = "0.110.0" 12 - oxc_codegen = "0.110.0" 13 11 oxc_transformer = "0.110.0" 14 12 oxc_semantic = "0.110.0" 15 - oxc_ast = "0.110.0" 16 - oxc_ast_visit = "0.110.0" 13 + oxc_codegen = { version = "0.110.0", default-features = false } 14 + oxc_parser = { version = "0.110.0", default-features = false } 17 15 18 16 [profile.release] 19 17 lto = true
-113
src/strip/src/collector.rs
··· 1 - use oxc_allocator::Allocator; 2 - use oxc_ast::ast::{BindingPattern, VariableDeclarationKind}; 3 - use oxc_ast_visit::{Visit, walk}; 4 - use oxc_parser::Parser; 5 - use oxc_semantic::ScopeFlags; 6 - use oxc_span::SourceType; 7 - 8 - struct VarCollector<'a> { 9 - vars: Vec<&'a str>, 10 - func_depth: usize, 11 - target_depth: usize, 12 - } 13 - 14 - impl<'a> VarCollector<'a> { 15 - fn new() -> Self { 16 - Self { 17 - vars: Vec::new(), 18 - func_depth: 0, 19 - target_depth: 0, 20 - } 21 - } 22 - 23 - fn for_func_body() -> Self { 24 - Self { 25 - vars: Vec::new(), 26 - func_depth: 0, 27 - target_depth: 1, 28 - } 29 - } 30 - 31 - fn extract_binding_names(&mut self, pattern: &BindingPattern<'a>) { 32 - use BindingPattern::*; 33 - match pattern { 34 - BindingIdentifier(id) => self.vars.push(id.name.as_str()), 35 - ObjectPattern(obj) => { 36 - for prop in &obj.properties { 37 - self.extract_binding_names(&prop.value); 38 - } 39 - if let Some(rest) = &obj.rest { 40 - self.extract_binding_names(&rest.argument); 41 - } 42 - } 43 - ArrayPattern(arr) => { 44 - for elem in arr.elements.iter().flatten() { 45 - self.extract_binding_names(elem); 46 - } 47 - if let Some(rest) = &arr.rest { 48 - self.extract_binding_names(&rest.argument); 49 - } 50 - } 51 - AssignmentPattern(assign) => { 52 - self.extract_binding_names(&assign.left); 53 - } 54 - } 55 - } 56 - } 57 - 58 - impl<'a> Visit<'a> for VarCollector<'a> { 59 - fn visit_function(&mut self, func: &oxc_ast::ast::Function<'a>, flags: ScopeFlags) { 60 - self.func_depth += 1; 61 - walk::walk_function(self, func, flags); 62 - self.func_depth -= 1; 63 - } 64 - 65 - fn visit_arrow_function_expression(&mut self, expr: &oxc_ast::ast::ArrowFunctionExpression<'a>) { 66 - self.func_depth += 1; 67 - walk::walk_arrow_function_expression(self, expr); 68 - self.func_depth -= 1; 69 - } 70 - 71 - fn visit_variable_declaration(&mut self, decl: &oxc_ast::ast::VariableDeclaration<'a>) { 72 - if decl.kind == VariableDeclarationKind::Var && self.func_depth == self.target_depth { 73 - for declarator in &decl.declarations { 74 - self.extract_binding_names(&declarator.id); 75 - } 76 - } 77 - walk::walk_variable_declaration(self, decl); 78 - } 79 - } 80 - 81 - pub fn collect_var_names(source: &str) -> Result<Vec<String>, String> { 82 - let allocator = Allocator::default(); 83 - let source_type = SourceType::mjs(); 84 - let parser_ret = Parser::new(&allocator, source, source_type).parse(); 85 - 86 - if !parser_ret.errors.is_empty() { 87 - let errors: Vec<String> = parser_ret.errors.iter().map(|e| e.to_string()).collect(); 88 - return Err(format!("Parse errors: {}", errors.join("; "))); 89 - } 90 - 91 - let mut collector = VarCollector::new(); 92 - collector.visit_program(&parser_ret.program); 93 - 94 - Ok(collector.vars.into_iter().map(String::from).collect()) 95 - } 96 - 97 - pub fn collect_var_names_from_func(source: &str) -> Result<Vec<String>, String> { 98 - let allocator = Allocator::default(); 99 - let source_type = SourceType::mjs(); 100 - 101 - let wrapped = format!("(function{})", source); 102 - let parser_ret = Parser::new(&allocator, &wrapped, source_type).parse(); 103 - 104 - if !parser_ret.errors.is_empty() { 105 - let errors: Vec<String> = parser_ret.errors.iter().map(|e| e.to_string()).collect(); 106 - return Err(format!("Parse errors: {}", errors.join("; "))); 107 - } 108 - 109 - let mut collector = VarCollector::for_func_body(); 110 - collector.visit_program(&parser_ret.program); 111 - 112 - Ok(collector.vars.into_iter().map(String::from).collect()) 113 - }
+5 -119
src/strip/src/ffi.rs
··· 1 - use std::alloc::{Layout, alloc, dealloc}; 2 1 use std::ffi::{CStr, c_char, c_int}; 3 2 use std::ptr; 4 3 5 - use crate::collector::{collect_var_names, collect_var_names_from_func}; 6 4 use crate::strip::strip_types_internal; 7 5 8 6 pub const OXC_ERR_NULL_INPUT: c_int = -1; ··· 16 14 true => OXC_ERR_PARSE_FAILED, 17 15 false => OXC_ERR_TRANSFORM_FAILED, 18 16 } 17 + } 18 + 19 + unsafe extern "C" { 20 + fn malloc(size: usize) -> *mut core::ffi::c_void; 19 21 } 20 22 21 23 unsafe fn write_error(output: *mut c_char, output_len: usize, msg: &str) { ··· 75 77 Ok(result) => { 76 78 let bytes = result.as_bytes(); 77 79 let alloc_len = bytes.len() + 1; 78 - let layout = Layout::from_size_align(alloc_len, 1).unwrap(); 79 - let out_ptr = unsafe { alloc(layout) as *mut c_char }; 80 + let out_ptr = unsafe { malloc(alloc_len) as *mut c_char }; 80 81 if out_ptr.is_null() { 81 82 unsafe { write_error(error_output, error_output_len, "out of memory allocating strip output") }; 82 83 if !out_error.is_null() { ··· 104 105 } 105 106 } 106 107 } 107 - 108 - #[unsafe(no_mangle)] 109 - pub unsafe extern "C" fn OXC_free_stripped_output(ptr: *mut c_char, len: usize) { 110 - if ptr.is_null() { 111 - return; 112 - } 113 - 114 - let alloc_len = len.saturating_add(1); 115 - let layout = Layout::from_size_align(alloc_len, 1).unwrap(); 116 - 117 - unsafe { 118 - dealloc(ptr as *mut u8, layout); 119 - } 120 - } 121 - 122 - #[unsafe(no_mangle)] 123 - pub unsafe extern "C" fn OXC_get_hoisted_vars(input: *const c_char, input_len: usize, out_len: *mut usize) -> *mut c_char { 124 - if input.is_null() || out_len.is_null() { 125 - return ptr::null_mut(); 126 - } 127 - 128 - let input_slice = unsafe { std::slice::from_raw_parts(input as *const u8, input_len) }; 129 - let input_str = match std::str::from_utf8(input_slice) { 130 - Ok(s) => s, 131 - Err(_) => return ptr::null_mut(), 132 - }; 133 - 134 - match collect_var_names(input_str) { 135 - Ok(vars) => { 136 - if vars.is_empty() { 137 - return ptr::null_mut(); 138 - } 139 - let total_len: usize = vars.iter().map(|s| s.len() + 1).sum::<usize>() + 1; 140 - 141 - let layout = std::alloc::Layout::from_size_align(total_len, 1).unwrap(); 142 - let ptr = unsafe { std::alloc::alloc(layout) as *mut c_char }; 143 - if ptr.is_null() { 144 - return ptr::null_mut(); 145 - } 146 - 147 - let mut offset = 0; 148 - for v in &vars { 149 - unsafe { 150 - ptr::copy_nonoverlapping(v.as_ptr(), ptr.add(offset) as *mut u8, v.len()); 151 - *ptr.add(offset + v.len()) = 0; 152 - } 153 - offset += v.len() + 1; 154 - } 155 - unsafe { 156 - *ptr.add(offset) = 0; 157 - *out_len = total_len; 158 - } 159 - 160 - ptr 161 - } 162 - Err(_) => ptr::null_mut(), 163 - } 164 - } 165 - 166 - #[unsafe(no_mangle)] 167 - pub unsafe extern "C" fn OXC_get_func_hoisted_vars(input: *const c_char, input_len: usize, out_len: *mut usize) -> *mut c_char { 168 - if input.is_null() || out_len.is_null() { 169 - return ptr::null_mut(); 170 - } 171 - 172 - let input_slice = unsafe { std::slice::from_raw_parts(input as *const u8, input_len) }; 173 - let input_str = match std::str::from_utf8(input_slice) { 174 - Ok(s) => s, 175 - Err(_) => return ptr::null_mut(), 176 - }; 177 - 178 - match collect_var_names_from_func(input_str) { 179 - Ok(vars) => { 180 - if vars.is_empty() { 181 - return ptr::null_mut(); 182 - } 183 - let total_len: usize = vars.iter().map(|s| s.len() + 1).sum::<usize>() + 1; 184 - 185 - let layout = std::alloc::Layout::from_size_align(total_len, 1).unwrap(); 186 - let ptr = unsafe { std::alloc::alloc(layout) as *mut c_char }; 187 - 188 - if ptr.is_null() { 189 - return ptr::null_mut(); 190 - } 191 - 192 - let mut offset = 0; 193 - for v in &vars { 194 - unsafe { 195 - ptr::copy_nonoverlapping(v.as_ptr(), ptr.add(offset) as *mut u8, v.len()); 196 - *ptr.add(offset + v.len()) = 0; 197 - } 198 - offset += v.len() + 1; 199 - } 200 - 201 - unsafe { 202 - *ptr.add(offset) = 0; 203 - *out_len = total_len; 204 - } 205 - 206 - ptr 207 - } 208 - Err(_) => ptr::null_mut(), 209 - } 210 - } 211 - 212 - #[unsafe(no_mangle)] 213 - pub unsafe extern "C" fn OXC_free_hoisted_vars(ptr: *mut c_char, len: usize) { 214 - if ptr.is_null() || len == 0 { 215 - return; 216 - } 217 - let layout = std::alloc::Layout::from_size_align(len, 1).unwrap(); 218 - unsafe { 219 - std::alloc::dealloc(ptr as *mut u8, layout); 220 - } 221 - }
-2
src/strip/src/lib.rs
··· 1 - mod collector; 2 1 mod ffi; 3 2 mod strip; 4 3 5 - pub use collector::{collect_var_names, collect_var_names_from_func}; 6 4 pub use ffi::*; 7 5 pub use strip::strip_types_internal;
+2 -2
src/utils.c
··· 169 169 170 170 char *next = realloc(input, stripped_len + 1); 171 171 if (!next) { 172 - OXC_free_stripped_output(stripped, stripped_len); 172 + free(stripped); 173 173 if (error_detail) *error_detail = "out of memory while resizing strip output buffer"; 174 174 return OXC_ERR_OUTPUT_TOO_LARGE; 175 175 } 176 176 177 177 memcpy(next, stripped, stripped_len + 1); 178 - OXC_free_stripped_output(stripped, stripped_len); 178 + free(stripped); 179 179 180 180 *buffer = next; 181 181 if (out_len) *out_len = stripped_len;
+1 -1
vendor/packagefiles/wasm-micro-runtime/meson.build
··· 72 72 'core/shared/platform/include', 73 73 'core/shared/platform/common/libc-util', 74 74 'core/shared/platform/common/memory', 75 + 'core/shared/platform/common/posix', 75 76 ) 76 77 77 78 if wamr_platform == 'windows' ··· 90 91 'core/shared/platform/common/memory/mremap.c', 91 92 ) 92 93 else 93 - wamr_inc += include_directories('core/shared/platform/common/posix') 94 94 wamr_sources = files( 95 95 'core/shared/platform/' + wamr_platform + '/platform_init.c', 96 96 'core/shared/platform/common/libc-util/libc_errno.c',