Commit Graph

55 Commits

Author SHA1 Message Date
isRyven
625542e463 fix split doesn't convert context to string if no argument is passed 2021-03-24 15:43:04 +01:00
Tor Andersson
832e069049 Support 4-byte UTF-8 sequences.
The following functions are no longer restricted to 16-bit integer values:

	String.fromCharCode()
	String.prototype.charCodeAt()

repr() will not escape SMP characters, as doing so would require conversion to
surrogate pairs, but will encode these characters as UTF-8. Unicode characters
in the BMP will still be escaped with \uXXXX as before.

JSON.stringify() only escapes control characters, so will represent all non-ASCII
characters as UTF-8.

We do no automatic conversions to/from surrogate pairs. Code that worked with
surrogate pairs should not be affected by these changes.
2020-05-27 12:32:32 +02:00
Tor Andersson
0261579d78 Support embedded 0 in strings by using modified UTF-8. 2020-05-27 12:32:32 +02:00
Tor Andersson
00d4606c3b Bug 700937: Limit recursion in regexp matcher.
Also handle negative return code as an error in the JS bindings.
2019-04-04 12:41:04 +02:00
Sebastian Rasmussen
7448a82448 Fix gcc compiler warnings about switch fallthroughs. 2018-09-11 12:47:31 +02:00
Tor Andersson
57b698f0b2 Return null if String.prototype.match with a global regex finds no matches. 2018-04-26 13:30:13 +02:00
Tor Andersson
75cab70afd Handle undefined this at the OP_THIS level.
Don't distinguish lax mode code by pushing the global object.
Always push undefined and let the calling code promote an undefined
this to the global object instead.
2017-04-17 14:57:38 +02:00
Tor Andersson
12a66c0a21 Fix printf format warnings.
We can't print function pointer addresses at all, since converting
a function pointer to a void* is forbidden with ANSI C, so we only
print the function name.
2016-12-27 13:49:21 +01:00
Tor Andersson
5000749f5a Fix bug 697141: buffer overrun in regexp string substitution.
A '$' escape at the end of the string would read past the zero terminator
when looking for the escaped character.
2016-09-21 16:04:14 +02:00
Tor Andersson
361b6ca997 Add CheckObjectCoercible in String prototype functions. 2016-04-28 13:15:24 +02:00
Tor Andersson
a2fcfd69fe Define built-in functions with the full name.
Improves error messages and stack traces.
2016-04-28 12:57:22 +02:00
Tor Andersson
3e3c382a0c Avoid using 'unsigned int'.
Mixing signed and unsigned ints is just a plain headache.
2016-04-27 16:26:00 +02:00
Tor Andersson
7c7a9cd78f Oops! Forgot to use the allocator in a few places... 2016-04-27 15:54:52 +02:00
Tor Andersson
c90c32326e Fix bugs introduced when moving from argc to js_gettop.
The 'length' field of a function is used to fill in missing arguments
with undefined; this does not mesh well with functions that query for
missing arguments using js_gettop. Set their lengths to 0 instead.
2016-04-15 12:18:34 +02:00
Tor Andersson
eed7619158 Rename our internal regex.h to not collide with system regex.h. 2015-08-14 12:05:09 +02:00
Tor Andersson
d9ed73fd71 strict mode: 'this' is undefined for normal function calls.
Global (script) code still uses the global object as 'this'.
Eval still uses the calling context's 'this'.
2015-01-14 13:05:12 +01:00
Tor Andersson
9b151f1513 Fix test for empty string in String.prototype.split with regexp. 2015-01-05 13:10:07 +01:00
Tor Andersson
031513b25b Add stack traces to error objects.
Revert 'add context and flag argument to js_newstate' commit.

The context argument just adds clutter. The flag which was intended
for JS_DEBUG and/or JS_STRICT shouldn't be necessary.

js_newcfunction and js_newcconstructor need an extra argument, the
name of the function to use in stack traces.
2014-12-03 01:18:21 +01:00
Tor Andersson
0cbd5326f2 Garbage collect (some) strings.
Separate literal/interned and garbage collected string types in js_Value.

js_pushintern/js_tointern are convenience functions to push/pop strings and
automatically intern them (so that the string pointers are guaranteed to be
stable).

js_pushliteral should push stable strings (either interned or actual literals).

js_pushstring will copy the string into garbage collected memory.

The pointer returned by js_tostring is guaranteed to be stable only for as long as
the stack slot it came from remains untouched.

Some uses will always cause a string to be interned:

 * Using it as a property name.
 * Wrapping it in a new String() object.
 * Strings returned by toString().
	ToPrimitive must not clobber the stack, so the result has to be unrooted.
 * Numbers converted to strings (by js_tostring)
	Likewise, we have nowhere to store the temporary string here.
	Passing in a scratch buffer to js_tostring could help this problem.
	Mostly an issue with array accesses (OP_GETPROP, etc) so an auxiliary
	function and we don't have to clutter the API needlessly.
2014-11-28 17:10:08 +01:00
Tor Andersson
5dbd120154 Fix several constructors.
"is/was supplied/specified" is different from "is not undefined" which
is used in most of the spec.
2014-03-13 13:36:29 +01:00
Tor Andersson
d366e4b852 Don't pass argc to functions. Use js_gettop instead. 2014-03-12 16:40:48 +01:00
Tor Andersson
dc386479da Add and use js_touint16. 2014-03-06 22:33:37 +01:00
Tor Andersson
67b33c5a86 Handle malloc failure by throwing exceptions. 2014-02-28 14:24:13 +01:00
Tor Andersson
bfe569921d Improve Resub API.
Hold the subexpression count and array of matches inside a struct.
2014-02-26 20:22:53 +01:00
Tor Andersson
01d85a4994 Move nelem() macro into jsi.h 2014-02-26 17:35:18 +01:00
Tor Andersson
90c2ba0bf3 Nul-terminate strings created by toUpper/LowerCase. 2014-02-26 16:00:23 +01:00
Tor Andersson
7562052e87 Handle two-digit backreferences and captures. 2014-02-26 15:30:46 +01:00
Tor Andersson
45e3a31950 Some -pedantic warning fixes.
Drop the use of 'inline' in most places... place some trust in the
compiler.
2014-02-25 01:23:52 +01:00
Tor Andersson
70b0d8b902 Change C functions to not have a return value.
They should always push a return value on the JS stack.
2014-02-25 00:56:33 +01:00
Tor Andersson
c7e9ab0b05 Fix signed/unsigned comparison warnings. 2014-02-24 23:55:58 +01:00
Tor Andersson
2ac601d07e Prepare for regular expression library.
Wrap the posix regex calls with the desired API.
2014-02-20 15:07:37 +01:00
Tor Andersson
8e938724ff Clean up for one.c compilation. 2014-02-11 13:42:25 +01:00
Tor Andersson
ab5236f243 UTF string index/pointer juggling. 2014-02-10 15:01:52 +01:00
Tor Andersson
46dec712a7 Simplify string-buffer function API. 2014-02-10 13:17:33 +01:00
Tor Andersson
b219aef882 Add virtual string array index properties for characters. 2014-02-07 16:40:22 +01:00
Tor Andersson
d59d0e2721 Make argc/undefined checks more resilient. 2014-02-07 15:45:08 +01:00
Tor Andersson
8e917e8c27 String.trim() 2014-02-06 23:40:38 +01:00
Tor Andersson
bc6da35e59 Add decode/encode URI functions. 2014-02-06 18:19:07 +01:00
Tor Andersson
71afe58cc4 Reset the lastIndex property in String.match() and replace(). 2014-02-05 14:36:35 +01:00
Tor Andersson
e17dcbba7c Encapsulate all regexp state in js_Regexp struct. 2014-02-05 13:57:44 +01:00
Tor Andersson
e645f5989c Handle global flag in String.match(). 2014-02-04 15:05:04 +01:00
Tor Andersson
450a0ef35e Handle String.replace() when the search matches the empty string. 2014-02-04 15:05:04 +01:00
Tor Andersson
b749e23cb4 String.split(). 2014-02-04 15:05:03 +01:00
Tor Andersson
d949e16118 String.replace() 2014-01-31 17:08:50 +01:00
Tor Andersson
b7afd400f6 Add js_pushlstring to avoid a lot of try/malloc/pushstring boilerplate. 2014-01-31 16:14:51 +01:00
Tor Andersson
6c37f967b4 Use POSIX regcomp/regexec.
A temporary measure, since POSIX regexes (a) don't have the same
syntax as javascript's regexes, and (b) don't work on UTF-8 (unless
the setlocale crap is configured correctly, and the implementation
supports it), and (c) doesn't work on windows.
2014-01-30 16:53:00 +01:00
Tor Andersson
e8dfb4e624 Rename non-js utility sources to not have the 'js' prefix. 2014-01-28 01:34:41 +01:00
Tor Andersson
ac953db0f7 Add more array functions.
And some internal wrapper functions to get/set array index properties.
2014-01-27 17:59:36 +01:00
Tor Andersson
b1c99267f0 Implement substring and slice. 2014-01-27 13:08:24 +01:00
Tor Andersson
489365dcf3 Add some more String functions. 2014-01-27 12:12:19 +01:00