Commit Graph

37 Commits

Author SHA1 Message Date
Tor Andersson
e690d31ee3 Issue 122: Allow floating point return values from Array.sort callback. 2020-01-02 12:42:09 +01:00
Tor Andersson
b4297c0dec Fix 699557: Pause garbage collector during Ap_sort.
The temporary array we use for sorting cannot be seen by the GC, and that
violates the constraint that all js_Value values must always be reachable
from the stack or global environment.

Temporarily turning off the GC will let us use the temporary array for
fast sorting using qsort(), without tripping over this violation.
2018-07-25 12:00:33 +02:00
Tor Andersson
40b73014d9 Fix 699549: Integer overflow in Array.prototype.sort().
Check size calculation for overflow before allocating memory buffer.
2018-07-23 11:30:22 +02:00
Tor Andersson
34cb61711f Fix 699383: Sorting arrays with zero or negative length. 2018-05-29 14:29:16 +02:00
Tor Andersson
cbdf814ee2 Handle undefined and unset array slots separately in Array.prototype.sort. 2018-05-15 13:51:24 +02:00
Tor Andersson
caabe08cb1 Use qsort to sort arrays. 2018-05-15 13:22:04 +02:00
Tor Andersson
780b14b5b7 Fix bug in Ap_sort where tostring values were put back into the array. 2018-04-27 11:11:50 +02:00
Tor Andersson
505751a54e Fix issue #55: Stack overflow bug in Array.prototype.sort(). 2017-12-11 13:22:23 +01: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
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
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
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
7bb55ad356 Add js_itoa for faster conversion of unsigned int to string. 2014-11-29 12:39:57 +01:00
Tor Andersson
9ded251f9b Oops. Remove stray printf. 2014-11-06 01:17:07 +01:00
Tor Andersson
98744d09a4 Fix bug in Array.prototype.splice(). 2014-11-05 17:36:47 +01:00
Tor Andersson
9ed0914704 Fix bug in js_setlength when used for relative indices. 2014-11-05 17:36:47 +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
44ddedea93 Some tidying. 2014-03-06 22:26:47 +01:00
Tor Andersson
67b33c5a86 Handle malloc failure by throwing exceptions. 2014-02-28 14:24:13 +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
9f7141ce30 Make array length helper public. 2014-02-13 12:06:27 +01:00
Tor Andersson
d59d0e2721 Make argc/undefined checks more resilient. 2014-02-07 15:45:08 +01:00
Tor Andersson
22a7477161 Implement ES5 array functions. 2014-02-07 15:21:14 +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
01cab639cb Make the array has/get/setindex functions part of the public API. 2014-01-28 17:19:09 +01:00
Tor Andersson
3b3bf534ae Array.sort() using insertion sort. 2014-01-28 14:38:17 +01:00
Tor Andersson
1aa15582d6 Let hasproperty push the value of the property on the stack if it exists.
This lets us avoid calling getproperty in the most common case of:

    if (hasproperty) { getproperty(); do stuff }
2014-01-28 13:42:20 +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
cbdebfda70 Implement some Array functions. 2014-01-25 22:57:40 +01:00
Tor Andersson
90b54a9eec Add userdata class.
js_newuserdata(J, tag, ptr) creates a userdata object, wrapping the ptr.
It takes the prototype for the new object from the top of the stack, just
like js_newcconstructor does.

js_touserdata(J, tag, idx) extracts the userdata pointer. Throws a
TypeError if the object is not a userdata object with a matching tag.

js_isuserdata(J, tag, idx) checks if a value on the stack is a userdata
object with a matching tag.
2014-01-24 17:11:49 +01:00
Tor Andersson
195816c208 Set property attributes on built-in objects and respect DontEnum. 2014-01-23 17:53:22 +01:00
Tor Andersson
3a92e13e47 Rename files and move a few functions around. 2014-01-21 13:58:32 +01:00