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.

improve annexb string compatibility

+133 -3
+3 -3
examples/results.txt
··· 716 716 compat-table/es6/WeakSet.prototype.delete.js: OK 717 717 compat-table/es6/annex-b.RegExp.prototype.compile.js: OK 718 718 compat-table/es6/annex-b.RegExp.prototype.compile.returns-this.js: OK 719 - compat-table/es6/annex-b.String.prototype.html.existence.js: failed 720 - compat-table/es6/annex-b.String.prototype.html.lowercase.js: TypeError: undefined is not a function 721 - compat-table/es6/annex-b.String.prototype.html.quotes-escaped.js: TypeError: undefined is not a function 719 + compat-table/es6/annex-b.String.prototype.html.existence.js: OK 720 + compat-table/es6/annex-b.String.prototype.html.lowercase.js: OK 721 + compat-table/es6/annex-b.String.prototype.html.quotes-escaped.js: OK 722 722 compat-table/es6/annex-b.function.hoisted-block-level.js: ReferenceError: 'g' is not defined 723 723 compat-table/es6/annex-b.function.if-statement.js: OK 724 724 compat-table/es6/annex-b.function.labeled.js: OK
+130
src/ant.c
··· 10855 10855 #undef ENSURE_CAP 10856 10856 } 10857 10857 10858 + static size_t html_attr_escaped_len(const char *s, ant_offset_t len) { 10859 + size_t out = 0; 10860 + for (ant_offset_t i = 0; i < len; i++) out += (s[i] == '"') ? 6 : 1; 10861 + return out; 10862 + } 10863 + 10864 + static void html_attr_append_escaped(char *out, size_t *pos, const char *s, ant_offset_t len) { 10865 + for (ant_offset_t i = 0; i < len; i++) if (s[i] == '"') { 10866 + memcpy(out + *pos, "&quot;", 6); 10867 + *pos += 6; 10868 + } else out[(*pos)++] = s[i]; 10869 + } 10870 + 10871 + static ant_value_t builtin_string_html(ant_t *js, ant_value_t *args, int nargs, const char *tag, const char *attr) { 10872 + ant_value_t str = js_tostring_val(js, unwrap_primitive(js, js->this_val)); 10873 + if (is_err(str)) return str; 10874 + 10875 + ant_offset_t str_len, str_off = vstr(js, str, &str_len); 10876 + const char *str_ptr = (const char *)(uintptr_t)str_off; 10877 + 10878 + size_t tag_len = strlen(tag); 10879 + size_t attr_len = attr ? strlen(attr) : 0; 10880 + 10881 + ant_value_t attr_val = js_mkundef(); 10882 + ant_offset_t value_len = 0; 10883 + 10884 + const char *value_ptr = NULL; 10885 + size_t escaped_len = 0; 10886 + 10887 + if (attr) { 10888 + attr_val = nargs > 0 ? js_tostring_val(js, args[0]) : js_mkstr(js, "undefined", 9); 10889 + if (is_err(attr_val)) return attr_val; 10890 + ant_offset_t value_off = vstr(js, attr_val, &value_len); 10891 + value_ptr = (const char *)(uintptr_t)value_off; 10892 + escaped_len = html_attr_escaped_len(value_ptr, value_len); 10893 + } 10894 + 10895 + size_t total = 1 + tag_len + (attr 10896 + ? (1 + attr_len + 2 + escaped_len + 1) 10897 + : 0) + 1 + (size_t)str_len + 2 + tag_len + 1; 10898 + 10899 + char *buf = (char *)ant_calloc(total); 10900 + if (!buf) return js_mkerr(js, "oom"); 10901 + 10902 + size_t pos = 0; 10903 + buf[pos++] = '<'; 10904 + memcpy(buf + pos, tag, tag_len); pos += tag_len; 10905 + 10906 + if (attr) { 10907 + buf[pos++] = ' '; 10908 + memcpy(buf + pos, attr, attr_len); pos += attr_len; 10909 + buf[pos++] = '='; 10910 + buf[pos++] = '"'; 10911 + html_attr_append_escaped(buf, &pos, value_ptr, value_len); 10912 + buf[pos++] = '"'; 10913 + } 10914 + 10915 + buf[pos++] = '>'; 10916 + memcpy(buf + pos, str_ptr, (size_t)str_len); pos += (size_t)str_len; 10917 + buf[pos++] = '<'; 10918 + buf[pos++] = '/'; 10919 + memcpy(buf + pos, tag, tag_len); pos += tag_len; 10920 + buf[pos++] = '>'; 10921 + 10922 + ant_value_t out = js_mkstr(js, buf, pos); 10923 + free(buf); 10924 + 10925 + return out; 10926 + } 10927 + 10928 + static ant_value_t builtin_string_anchor(ant_t *js, ant_value_t *args, int nargs) { 10929 + return builtin_string_html(js, args, nargs, "a", "name"); 10930 + } 10931 + 10932 + static ant_value_t builtin_string_big(ant_t *js, ant_value_t *args, int nargs) { 10933 + return builtin_string_html(js, args, nargs, "big", NULL); 10934 + } 10935 + 10936 + static ant_value_t builtin_string_bold(ant_t *js, ant_value_t *args, int nargs) { 10937 + return builtin_string_html(js, args, nargs, "b", NULL); 10938 + } 10939 + 10940 + static ant_value_t builtin_string_fixed(ant_t *js, ant_value_t *args, int nargs) { 10941 + return builtin_string_html(js, args, nargs, "tt", NULL); 10942 + } 10943 + 10944 + static ant_value_t builtin_string_fontcolor(ant_t *js, ant_value_t *args, int nargs) { 10945 + return builtin_string_html(js, args, nargs, "font", "color"); 10946 + } 10947 + 10948 + static ant_value_t builtin_string_fontsize(ant_t *js, ant_value_t *args, int nargs) { 10949 + return builtin_string_html(js, args, nargs, "font", "size"); 10950 + } 10951 + 10952 + static ant_value_t builtin_string_italics(ant_t *js, ant_value_t *args, int nargs) { 10953 + return builtin_string_html(js, args, nargs, "i", NULL); 10954 + } 10955 + 10956 + static ant_value_t builtin_string_link(ant_t *js, ant_value_t *args, int nargs) { 10957 + return builtin_string_html(js, args, nargs, "a", "href"); 10958 + } 10959 + 10960 + static ant_value_t builtin_string_small(ant_t *js, ant_value_t *args, int nargs) { 10961 + return builtin_string_html(js, args, nargs, "small", NULL); 10962 + } 10963 + 10964 + static ant_value_t builtin_string_strike(ant_t *js, ant_value_t *args, int nargs) { 10965 + return builtin_string_html(js, args, nargs, "strike", NULL); 10966 + } 10967 + 10968 + static ant_value_t builtin_string_sub(ant_t *js, ant_value_t *args, int nargs) { 10969 + return builtin_string_html(js, args, nargs, "sub", NULL); 10970 + } 10971 + 10972 + static ant_value_t builtin_string_sup(ant_t *js, ant_value_t *args, int nargs) { 10973 + return builtin_string_html(js, args, nargs, "sup", NULL); 10974 + } 10975 + 10858 10976 static ant_value_t builtin_string_charCodeAt(ant_t *js, ant_value_t *args, int nargs) { 10859 10977 ant_value_t str = to_string_val(js, js->this_val); 10860 10978 if (vtype(str) != T_STR) return js_mkerr(js, "charCodeAt called on non-string"); ··· 14620 14738 defmethod(js, string_proto, "normalize", 9, js_mkfun(builtin_string_normalize)); 14621 14739 defmethod(js, string_proto, "valueOf", 7, js_mkfun(builtin_string_valueOf)); 14622 14740 defmethod(js, string_proto, "toString", 8, js_mkfun(builtin_string_toString)); 14741 + defmethod(js, string_proto, "anchor", 6, js_mkfun(builtin_string_anchor)); 14742 + defmethod(js, string_proto, "big", 3, js_mkfun(builtin_string_big)); 14743 + defmethod(js, string_proto, "bold", 4, js_mkfun(builtin_string_bold)); 14744 + defmethod(js, string_proto, "fixed", 5, js_mkfun(builtin_string_fixed)); 14745 + defmethod(js, string_proto, "fontcolor", 9, js_mkfun(builtin_string_fontcolor)); 14746 + defmethod(js, string_proto, "fontsize", 8, js_mkfun(builtin_string_fontsize)); 14747 + defmethod(js, string_proto, "italics", 7, js_mkfun(builtin_string_italics)); 14748 + defmethod(js, string_proto, "link", 4, js_mkfun(builtin_string_link)); 14749 + defmethod(js, string_proto, "small", 5, js_mkfun(builtin_string_small)); 14750 + defmethod(js, string_proto, "strike", 6, js_mkfun(builtin_string_strike)); 14751 + defmethod(js, string_proto, "sub", 3, js_mkfun(builtin_string_sub)); 14752 + defmethod(js, string_proto, "sup", 3, js_mkfun(builtin_string_sup)); 14623 14753 14624 14754 ant_value_t number_proto = js_mkobj(js); 14625 14755 set_proto(js, number_proto, object_proto);