summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--!NetSurf/Resources/en/credits.html,faf2
-rw-r--r--!NetSurf/Resources/en/licence.html,faf18
-rw-r--r--!NetSurf/Resources/it/credits.html,faf2
-rw-r--r--!NetSurf/Resources/it/licence.html,faf14
-rw-r--r--!NetSurf/Resources/nl/credits.html,faf2
-rw-r--r--!NetSurf/Resources/nl/licence.html,faf14
-rw-r--r--content/handlers/css/dump.c7
-rw-r--r--content/handlers/css/hints.c2
-rw-r--r--content/handlers/css/utils.h69
-rw-r--r--content/handlers/javascript/duktape/duk_config.h165
-rw-r--r--content/handlers/javascript/duktape/duktape.c26480
-rw-r--r--content/handlers/javascript/duktape/duktape.h179
-rw-r--r--content/llcache.c4
-rw-r--r--desktop/textarea.c2
-rw-r--r--desktop/version.c4
-rw-r--r--docs/env.sh314
-rw-r--r--frontends/amiga/Makefile2
-rw-r--r--frontends/amiga/font.c2
-rw-r--r--frontends/amiga/font_diskfont.c1
-rw-r--r--frontends/amiga/gui.c2
-rwxr-xr-xfrontends/amiga/gui_options.c7
-rw-r--r--frontends/amiga/libs.c3
-rw-r--r--frontends/amiga/version.c2
-rw-r--r--frontends/framebuffer/bitmap.c10
-rw-r--r--frontends/framebuffer/fbtk/text.c16
-rw-r--r--frontends/gtk/download.c2
-rw-r--r--frontends/gtk/res/options.gtk2.ui589
-rw-r--r--frontends/gtk/res/toolbar.gtk2.ui183
-rw-r--r--frontends/gtk/res/toolbar.gtk3.ui242
-rw-r--r--frontends/gtk/scaffolding.c8
-rw-r--r--frontends/gtk/toolbar.c124
-rw-r--r--frontends/windows/Makefile2
-rw-r--r--frontends/windows/bitmap.c2
-rw-r--r--render/box_construct.c27
-rw-r--r--render/html_interaction.c3
-rw-r--r--render/layout.c6
-rw-r--r--render/table.c52
-rwxr-xr-xutils/jenkins-build.sh22
38 files changed, 15283 insertions, 13302 deletions
diff --git a/!NetSurf/Resources/en/credits.html,faf b/!NetSurf/Resources/en/credits.html,faf
index b7098df..7789bcd 100644
--- a/!NetSurf/Resources/en/credits.html,faf
+++ b/!NetSurf/Resources/en/credits.html,faf
@@ -92,7 +92,7 @@ div#DevList ul {
</div>
<div class="footer">
-<p>Copyright 2003&ndash;2016 The NetSurf Developers</p>
+<p>Copyright 2003&ndash;2017 The NetSurf Developers</p>
</div>
</body>
diff --git a/!NetSurf/Resources/en/licence.html,faf b/!NetSurf/Resources/en/licence.html,faf
index da0df45..515757c 100644
--- a/!NetSurf/Resources/en/licence.html,faf
+++ b/!NetSurf/Resources/en/licence.html,faf
@@ -60,25 +60,25 @@ version.</p>
<dl class="components">
<dt><a href="http://www.netsurf-browser.org/">NetSurf</a></dt>
<dd>
-<span>&copy; 2002&ndash;2016 The NetSurf Developers</span>
+<span>&copy; 2002&ndash;2017 The NetSurf Developers</span>
<span><a href="#gplv2">GPLv2</a></span>
</dd>
<dt><a href="http://www.netsurf-browser.org/projects/libcss/">LibCSS</a></dt>
<dd>
-<span>&copy; 2007&ndash;2016 John-Mark Bell</span>
+<span>&copy; 2007&ndash;2017 John-Mark Bell</span>
<span><a href="#mit">MIT</a></span>
</dd>
<dt><a href="http://www.netsurf-browser.org/projects/hubbub/">Hubbub</a></dt>
<dd>
-<span>&copy; 2007&ndash;2016 John-Mark Bell<br>&copy; 2008&ndash;2009 Andrew Sidwell</span>
+<span>&copy; 2007&ndash;2017 John-Mark Bell<br>&copy; 2008&ndash;2009 Andrew Sidwell</span>
<span><a href="#mit">MIT</a></span>
</dd>
<dt><a href="http://www.netsurf-browser.org/projects/libparserutils/">LibParserUtils</a></dt>
<dd>
-<span>&copy; 2007&ndash;2016 John-Mark Bell</span>
+<span>&copy; 2007&ndash;2017 John-Mark Bell</span>
<span><a href="#mit">MIT</a></span>
</dd>
@@ -102,19 +102,19 @@ version.</p>
<dt><a href="http://www.netsurf-browser.org/projects/libsvgtiny">Libsvgtiny</a></dt>
<dd>
-<span>&copy; 2008&ndash;2009 James Bursa<br>&copy; 2016 Michael Drake</span>
+<span>&copy; 2008&ndash;2009 James Bursa<br>&copy; 2017 Michael Drake</span>
<span><a href="#mit">MIT</a></span>
</dd>
<dt><a href="http://www.netsurf-browser.org/projects/libnsbmp/">Libnsbmp</a></dt>
<dd>
-<span>&copy; 2006 Richard Wilson<br>&copy; 2008 Sean Fox<br>&copy; 2016 Vincent Sanders</span>
+<span>&copy; 2006 Richard Wilson<br>&copy; 2008 Sean Fox<br>&copy; 2017 Vincent Sanders</span>
<span><a href="#mit">MIT</a></span>
</dd>
<dt><a href="http://www.netsurf-browser.org/projects/libnsfb/">Libnsfb</a></dt>
<dd>
-<span>&copy; 2009&ndash;2016 Vincent Sanders<br>&copy; 2009&ndash;2016 Michael Drake</span>
+<span>&copy; 2009&ndash;2017 Vincent Sanders<br>&copy; 2009&ndash;2017 Michael Drake</span>
<span><a href="#mit">MIT</a></span>
</dd>
@@ -126,7 +126,7 @@ version.</p>
<dt><a href="http://www.netsurf-browser.org/projects/libwapcaplet">LibWapcaplet</a></dt>
<dd>
-<span>&copy; 2009&ndash;2016 NetSurf Browser Project, Daniel Silverstone</span>
+<span>&copy; 2009&ndash;2017 NetSurf Browser Project, Daniel Silverstone</span>
<span><a href="#mit">MIT</a></span>
</dd>
</dl>
@@ -1865,7 +1865,7 @@ PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
</div>
<div class="footer">
-<p>Copyright 2003&ndash;2016 The NetSurf Developers</p>
+<p>Copyright 2003&ndash;2017 The NetSurf Developers</p>
</div>
</body>
diff --git a/!NetSurf/Resources/it/credits.html,faf b/!NetSurf/Resources/it/credits.html,faf
index fe65443..cec1912 100644
--- a/!NetSurf/Resources/it/credits.html,faf
+++ b/!NetSurf/Resources/it/credits.html,faf
@@ -91,7 +91,7 @@ div#DevList ul {
</div>
<div class="footer">
-<p><br>Copyright 2003&ndash;2013 The NetSurf Developers</p>
+<p><br>Copyright 2003&ndash;2017 The NetSurf Developers</p>
</div>
</body>
diff --git a/!NetSurf/Resources/it/licence.html,faf b/!NetSurf/Resources/it/licence.html,faf
index b0a6c8a..8b9c489 100644
--- a/!NetSurf/Resources/it/licence.html,faf
+++ b/!NetSurf/Resources/it/licence.html,faf
@@ -52,25 +52,25 @@ dl.components > dd > span + span {
<dl class="components">
<dt><a href="http://www.netsurf-browser.org/">NetSurf</a></dt>
<dd>
-<span>&copy; 2002&ndash;2013 The NetSurf Developers</span>
+<span>&copy; 2002&ndash;2017 The NetSurf Developers</span>
<span><a href="#gplv2">GPLv2</a></span>
</dd>
<dt><a href="http://www.netsurf-browser.org/projects/libcss/">LibCSS</a></dt>
<dd>
-<span>&copy; 2007&ndash;2013 John-Mark Bell</span>
+<span>&copy; 2007&ndash;2017 John-Mark Bell</span>
<span><a href="#mit">MIT</a></span>
</dd>
<dt><a href="http://www.netsurf-browser.org/projects/hubbub/">Hubbub</a></dt>
<dd>
-<span>&copy; 2007&ndash;2013 John-Mark Bell<br>&copy; 2008&ndash;2009 Andrew Sidwell</span>
+<span>&copy; 2007&ndash;2017 John-Mark Bell<br>&copy; 2008&ndash;2009 Andrew Sidwell</span>
<span><a href="#mit">MIT</a></span>
</dd>
<dt><a href="http://www.netsurf-browser.org/projects/libparserutils/">LibParserUtils</a></dt>
<dd>
-<span>&copy; 2007&ndash;2013 John-Mark Bell</span>
+<span>&copy; 2007&ndash;2017 John-Mark Bell</span>
<span><a href="#mit">MIT</a></span>
</dd>
@@ -106,7 +106,7 @@ dl.components > dd > span + span {
<dt><a href="http://www.netsurf-browser.org/projects/libnsfb/">Libnsfb</a></dt>
<dd>
-<span>&copy; 2009&ndash;2013 Vincent Sanders<br>&copy; 2009&ndash;2013 Michael Drake</span>
+<span>&copy; 2009&ndash;2017 Vincent Sanders<br>&copy; 2009&ndash;2017 Michael Drake</span>
<span><a href="#mit">MIT</a></span>
</dd>
@@ -118,7 +118,7 @@ dl.components > dd > span + span {
<dt><a href="http://www.netsurf-browser.org/projects/libwapcaplet">LibWapcaplet</a></dt>
<dd>
-<span>&copy; 2009&ndash;2013 NetSurf Browser Project, Daniel Silverstone</span>
+<span>&copy; 2009&ndash;2017 NetSurf Browser Project, Daniel Silverstone</span>
<span><a href="#mit">MIT</a></span>
</dd>
</dl>
@@ -1853,7 +1853,7 @@ PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
</div>
<div class="footer">
-<p>Copyright 2003&ndash;2013 The NetSurf Developers</p>
+<p>Copyright 2003&ndash;2017 The NetSurf Developers</p>
</div>
</body>
diff --git a/!NetSurf/Resources/nl/credits.html,faf b/!NetSurf/Resources/nl/credits.html,faf
index 3cae27a..f9e0932 100644
--- a/!NetSurf/Resources/nl/credits.html,faf
+++ b/!NetSurf/Resources/nl/credits.html,faf
@@ -96,7 +96,7 @@ div#DevList ul {
</div>
<div class="footer">
-<p>Auteursrecht 2003&ndash;2016 De NetSurf-ontwikkelaars</p>
+<p>Auteursrecht 2003&ndash;2017 De NetSurf-ontwikkelaars</p>
</div>
</body>
diff --git a/!NetSurf/Resources/nl/licence.html,faf b/!NetSurf/Resources/nl/licence.html,faf
index d3272c7..89ce856 100644
--- a/!NetSurf/Resources/nl/licence.html,faf
+++ b/!NetSurf/Resources/nl/licence.html,faf
@@ -63,25 +63,25 @@ dan verwijder deze uitzonderingverklaring uit uw eigen versie.</p>
<dl class="components">
<dt><a href="http://www.netsurf-browser.org/">NetSurf</a></dt>
<dd>
-<span>&copy; 2002&ndash;2016 De NetSurf-ontwikkerlaars</span>
+<span>&copy; 2002&ndash;2017 De NetSurf-ontwikkerlaars</span>
<span><a href="#gplv2">GPLv2</a></span>
</dd>
<dt><a href="http://www.netsurf-browser.org/projects/libcss/">LibCSS</a></dt>
<dd>
-<span>&copy; 2007&ndash;2016 John-Mark Bell</span>
+<span>&copy; 2007&ndash;2017 John-Mark Bell</span>
<span><a href="#mit">MIT</a></span>
</dd>
<dt><a href="http://www.netsurf-browser.org/projects/hubbub/">Hubbub</a></dt>
<dd>
-<span>&copy; 2007&ndash;2016 John-Mark Bell<br>&copy; 2008&ndash;2009 Andrew Sidwell</span>
+<span>&copy; 2007&ndash;2017 John-Mark Bell<br>&copy; 2008&ndash;2009 Andrew Sidwell</span>
<span><a href="#mit">MIT</a></span>
</dd>
<dt><a href="http://www.netsurf-browser.org/projects/libparserutils/">LibParserUtils</a></dt>
<dd>
-<span>&copy; 2007&ndash;2016 John-Mark Bell</span>
+<span>&copy; 2007&ndash;2017 John-Mark Bell</span>
<span><a href="#mit">MIT</a></span>
</dd>
@@ -117,7 +117,7 @@ dan verwijder deze uitzonderingverklaring uit uw eigen versie.</p>
<dt><a href="http://www.netsurf-browser.org/projects/libnsfb/">Libnsfb</a></dt>
<dd>
-<span>&copy; 2009&ndash;2016 Vincent Sanders<br>&copy; 2009&ndash;2016 Michael Drake</span>
+<span>&copy; 2009&ndash;2017 Vincent Sanders<br>&copy; 2009&ndash;2017 Michael Drake</span>
<span><a href="#mit">MIT</a></span>
</dd>
@@ -129,7 +129,7 @@ dan verwijder deze uitzonderingverklaring uit uw eigen versie.</p>
<dt><a href="http://www.netsurf-browser.org/projects/libwapcaplet">LibWapcaplet</a></dt>
<dd>
-<span>&copy; 2009&ndash;2016 NetSurf Browser Project, Daniel Silverstone</span>
+<span>&copy; 2009&ndash;2017 NetSurf Browser Project, Daniel Silverstone</span>
<span><a href="#mit">MIT</a></span>
</dd>
</dl>
@@ -1872,7 +1872,7 @@ PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
</div>
<div class="footer">
-<p>Auteursrecht 2003&ndash;2016 De NetSurf-ontwikkelaars</p>
+<p>Auteursrecht 2003&ndash;2017 De NetSurf-ontwikkelaars</p>
</div>
</body>
diff --git a/content/handlers/css/dump.c b/content/handlers/css/dump.c
index 1ad188c..529bd4a 100644
--- a/content/handlers/css/dump.c
+++ b/content/handlers/css/dump.c
@@ -20,6 +20,7 @@
#include <libcss/libcss.h>
#include "css/dump.h"
+#include "css/utils.h"
/**
* Dump a fixed point value to the stream in a textual form.
@@ -783,7 +784,7 @@ void nscss_dump_computed_style(FILE *stream, const css_computed_style *style)
}
/* display */
- val = css_computed_display_static(style);
+ val = ns_computed_display_static(style);
switch (val) {
case CSS_DISPLAY_INLINE:
fprintf(stream, "display: inline ");
@@ -1268,7 +1269,7 @@ void nscss_dump_computed_style(FILE *stream, const css_computed_style *style)
}
/* min-height */
- val = css_computed_min_height(style, &len1, &unit1);
+ val = ns_computed_min_height(style, &len1, &unit1);
switch (val) {
case CSS_MIN_HEIGHT_SET:
fprintf(stream, "min-height: ");
@@ -1282,7 +1283,7 @@ void nscss_dump_computed_style(FILE *stream, const css_computed_style *style)
}
/* min-width */
- val = css_computed_min_width(style, &len1, &unit1);
+ val = ns_computed_min_width(style, &len1, &unit1);
switch (val) {
case CSS_MIN_WIDTH_SET:
fprintf(stream, "min-width: ");
diff --git a/content/handlers/css/hints.c b/content/handlers/css/hints.c
index 08fe438..3a15f8e 100644
--- a/content/handlers/css/hints.c
+++ b/content/handlers/css/hints.c
@@ -748,6 +748,8 @@ static void css_hint_vertical_align_table_cells(
corestring_dom_valign, &attr);
if (err == DOM_NO_ERR && attr != NULL) {
+ hint->data.length.value = 0;
+ hint->data.length.unit = CSS_UNIT_PX;
if (dom_string_caseless_lwc_isequal(attr,
corestring_lwc_top)) {
hint->prop = CSS_PROP_VERTICAL_ALIGN;
diff --git a/content/handlers/css/utils.h b/content/handlers/css/utils.h
index 58a5ea6..21cb497 100644
--- a/content/handlers/css/utils.h
+++ b/content/handlers/css/utils.h
@@ -46,4 +46,73 @@ css_fixed nscss_len2pt(css_fixed length, css_unit unit);
*/
css_fixed nscss_len2px(css_fixed length, css_unit unit, const css_computed_style *style);
+
+/**
+ * Temporary helper wrappers for for libcss computed style getter, while
+ * we don't support flexbox related property values.
+ */
+
+static inline uint8_t ns_computed_display(
+ const css_computed_style *style, bool root)
+{
+ uint8_t value = css_computed_display(style, root);
+
+ if (value == CSS_DISPLAY_FLEX) {
+ return CSS_DISPLAY_BLOCK;
+
+ } else if (value == CSS_DISPLAY_INLINE_FLEX) {
+ return CSS_DISPLAY_INLINE_BLOCK;
+ }
+
+ return value;
+}
+
+
+static inline uint8_t ns_computed_display_static(
+ const css_computed_style *style)
+{
+ uint8_t value = css_computed_display_static(style);
+
+ if (value == CSS_DISPLAY_FLEX) {
+ return CSS_DISPLAY_BLOCK;
+
+ } else if (value == CSS_DISPLAY_INLINE_FLEX) {
+ return CSS_DISPLAY_INLINE_BLOCK;
+ }
+
+ return value;
+}
+
+
+static inline uint8_t ns_computed_min_height(
+ const css_computed_style *style,
+ css_fixed *length, css_unit *unit)
+{
+ uint8_t value = css_computed_min_height(style, length, unit);
+
+ if (value == CSS_MIN_HEIGHT_AUTO) {
+ value = CSS_MIN_HEIGHT_SET;
+ *length = 0;
+ *unit = CSS_UNIT_PX;
+ }
+
+ return value;
+}
+
+
+static inline uint8_t ns_computed_min_width(
+ const css_computed_style *style,
+ css_fixed *length, css_unit *unit)
+{
+ uint8_t value = css_computed_min_width(style, length, unit);
+
+ if (value == CSS_MIN_WIDTH_AUTO) {
+ value = CSS_MIN_WIDTH_SET;
+ *length = 0;
+ *unit = CSS_UNIT_PX;
+ }
+
+ return value;
+}
+
#endif
diff --git a/content/handlers/javascript/duktape/duk_config.h b/content/handlers/javascript/duktape/duk_config.h
index 4a16a68..379e9f6 100644
--- a/content/handlers/javascript/duktape/duk_config.h
+++ b/content/handlers/javascript/duktape/duk_config.h
@@ -525,6 +525,11 @@
#endif
#elif defined(DUK_F_WINDOWS)
/* --- Windows --- */
+/* Windows version can't obviously be determined at compile time,
+ * but _WIN32_WINNT indicates the minimum version targeted:
+ * - https://msdn.microsoft.com/en-us/library/6sehtctf.aspx
+ */
+
/* Initial fix: disable secure CRT related warnings when compiling Duktape
* itself (must be defined before including Windows headers). Don't define
* for user code including duktape.h.
@@ -535,17 +540,40 @@
/* Windows 32-bit and 64-bit are currently the same. */
/* MSVC does not have sys/param.h */
+
+#if defined(DUK_COMPILING_DUKTAPE)
+/* Only include when compiling Duktape to avoid polluting application build
+ * with a lot of unnecessary defines.
+ */
+#include <windows.h>
+#endif
+
+/* GetSystemTimePreciseAsFileTime() available from Windows 8:
+ * https://msdn.microsoft.com/en-us/library/windows/desktop/hh706895(v=vs.85).aspx
+ */
+#if defined(DUK_USE_DATE_NOW_WINDOWS_SUBMS) || defined(DUK_USE_DATE_NOW_WINDOWS)
+/* User forced provider. */
+#else
+#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)
+#define DUK_USE_DATE_NOW_WINDOWS_SUBMS
+#else
#define DUK_USE_DATE_NOW_WINDOWS
+#endif
+#endif
+
#define DUK_USE_DATE_TZO_WINDOWS
+
/* Note: PRS and FMT are intentionally left undefined for now. This means
* there is no platform specific date parsing/formatting but there is still
* the ISO 8601 standard format.
*/
-#if defined(DUK_COMPILING_DUKTAPE)
-/* Only include when compiling Duktape to avoid polluting application build
- * with a lot of unnecessary defines.
+
+/* QueryPerformanceCounter() may go backwards in Windows XP, so enable for
+ * Vista and later: https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx#qpc_support_in_windows_versions
*/
-#include <windows.h>
+#if !defined(DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC) && \
+ defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)
+#define DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC
#endif
#define DUK_USE_OS_STRING "windows"
@@ -667,6 +695,10 @@
#define DUK_USE_DATE_PRS_STRPTIME
#define DUK_USE_DATE_FMT_STRFTIME
+#if 0 /* XXX: safe condition? */
+#define DUK_USE_GET_MONOTONIC_TIME_CLOCK_GETTIME
+#endif
+
#define DUK_USE_OS_STRING "linux"
#elif defined(DUK_F_SUN)
/* --- Solaris --- */
@@ -818,12 +850,6 @@
#if !defined(DUK_USE_BYTEORDER)
#define DUK_USE_BYTEORDER 1
#endif
-/* XXX: This is technically not guaranteed because it's possible to configure
- * an x86 to require aligned accesses with Alignment Check (AC) flag.
- */
-#if !defined(DUK_USE_ALIGN_BY)
-#define DUK_USE_ALIGN_BY 1
-#endif
#define DUK_USE_PACKED_TVAL
#define DUK_F_PACKED_TVAL_PROVIDED
#elif defined(DUK_F_X64)
@@ -832,12 +858,6 @@
#if !defined(DUK_USE_BYTEORDER)
#define DUK_USE_BYTEORDER 1
#endif
-/* XXX: This is technically not guaranteed because it's possible to configure
- * an x86 to require aligned accesses with Alignment Check (AC) flag.
- */
-#if !defined(DUK_USE_ALIGN_BY)
-#define DUK_USE_ALIGN_BY 1
-#endif
#undef DUK_USE_PACKED_TVAL
#define DUK_F_PACKED_TVAL_PROVIDED
#elif defined(DUK_F_X32)
@@ -846,48 +866,30 @@
#if !defined(DUK_USE_BYTEORDER)
#define DUK_USE_BYTEORDER 1
#endif
-/* XXX: This is technically not guaranteed because it's possible to configure
- * an x86 to require aligned accesses with Alignment Check (AC) flag.
- */
-#if !defined(DUK_USE_ALIGN_BY)
-#define DUK_USE_ALIGN_BY 1
-#endif
#define DUK_USE_PACKED_TVAL
#define DUK_F_PACKED_TVAL_PROVIDED
#elif defined(DUK_F_ARM32)
/* --- ARM 32-bit --- */
#define DUK_USE_ARCH_STRING "arm32"
/* Byte order varies, so rely on autodetect. */
-#if !defined(DUK_USE_ALIGN_BY)
-#define DUK_USE_ALIGN_BY 4
-#endif
#define DUK_USE_PACKED_TVAL
#define DUK_F_PACKED_TVAL_PROVIDED
#elif defined(DUK_F_ARM64)
/* --- ARM 64-bit --- */
#define DUK_USE_ARCH_STRING "arm64"
/* Byte order varies, so rely on autodetect. */
-#if !defined(DUK_USE_ALIGN_BY)
-#define DUK_USE_ALIGN_BY 8
-#endif
#undef DUK_USE_PACKED_TVAL
#define DUK_F_PACKED_TVAL_PROVIDED
#elif defined(DUK_F_MIPS32)
/* --- MIPS 32-bit --- */
#define DUK_USE_ARCH_STRING "mips32"
/* MIPS byte order varies so rely on autodetection. */
-#if !defined(DUK_USE_ALIGN_BY)
-#define DUK_USE_ALIGN_BY 8
-#endif
#define DUK_USE_PACKED_TVAL
#define DUK_F_PACKED_TVAL_PROVIDED
#elif defined(DUK_F_MIPS64)
/* --- MIPS 64-bit --- */
#define DUK_USE_ARCH_STRING "mips64"
/* MIPS byte order varies so rely on autodetection. */
-#if !defined(DUK_USE_ALIGN_BY)
-#define DUK_USE_ALIGN_BY 8
-#endif
#undef DUK_USE_PACKED_TVAL
#define DUK_F_PACKED_TVAL_PROVIDED
#elif defined(DUK_F_PPC32)
@@ -896,9 +898,6 @@
#if !defined(DUK_USE_BYTEORDER)
#define DUK_USE_BYTEORDER 3
#endif
-#if !defined(DUK_USE_ALIGN_BY)
-#define DUK_USE_ALIGN_BY 8
-#endif
#define DUK_USE_PACKED_TVAL
#define DUK_F_PACKED_TVAL_PROVIDED
#elif defined(DUK_F_PPC64)
@@ -907,27 +906,18 @@
#if !defined(DUK_USE_BYTEORDER)
#define DUK_USE_BYTEORDER 3
#endif
-#if !defined(DUK_USE_ALIGN_BY)
-#define DUK_USE_ALIGN_BY 8
-#endif
#undef DUK_USE_PACKED_TVAL
#define DUK_F_PACKED_TVAL_PROVIDED
#elif defined(DUK_F_SPARC32)
/* --- SPARC 32-bit --- */
#define DUK_USE_ARCH_STRING "sparc32"
/* SPARC byte order varies so rely on autodetection. */
-#if !defined(DUK_USE_ALIGN_BY)
-#define DUK_USE_ALIGN_BY 8
-#endif
#define DUK_USE_PACKED_TVAL
#define DUK_F_PACKED_TVAL_PROVIDED
#elif defined(DUK_F_SPARC64)
/* --- SPARC 64-bit --- */
#define DUK_USE_ARCH_STRING "sparc64"
/* SPARC byte order varies so rely on autodetection. */
-#if !defined(DUK_USE_ALIGN_BY)
-#define DUK_USE_ALIGN_BY 8
-#endif
#undef DUK_USE_PACKED_TVAL
#define DUK_F_PACKED_TVAL_PROVIDED
#elif defined(DUK_F_SUPERH)
@@ -937,9 +927,6 @@
/* Based on 'make checkalign' there are no alignment requirements on
* Linux SH4, but align by 4 is probably a good basic default.
*/
-#if !defined(DUK_USE_ALIGN_BY)
-#define DUK_USE_ALIGN_BY 4
-#endif
#define DUK_USE_PACKED_TVAL
#define DUK_F_PACKED_TVAL_PROVIDED
#elif defined(DUK_F_M68K)
@@ -948,9 +935,6 @@
#if !defined(DUK_USE_BYTEORDER)
#define DUK_USE_BYTEORDER 3
#endif
-#if !defined(DUK_USE_ALIGN_BY)
-#define DUK_USE_ALIGN_BY 8
-#endif
#define DUK_USE_PACKED_TVAL
#define DUK_F_PACKED_TVAL_PROVIDED
#elif defined(DUK_F_EMSCRIPTEN)
@@ -959,9 +943,6 @@
#if !defined(DUK_USE_BYTEORDER)
#define DUK_USE_BYTEORDER 1
#endif
-#if !defined(DUK_USE_ALIGN_BY)
-#define DUK_USE_ALIGN_BY 8
-#endif
#undef DUK_USE_PACKED_TVAL
#define DUK_F_PACKED_TVAL_PROVIDED
#else
@@ -1307,7 +1288,16 @@
#endif
/* Avoid warning when doing DUK_UNREF(some_function). */
+#if defined(_MSC_VER) && (_MSC_VER < 1500)
+#pragma warning(disable: 4100 4101 4550 4551)
+#define DUK_UNREF(x)
+#else
#define DUK_UNREF(x) do { __pragma(warning(suppress:4100 4101 4550 4551)) (x); } while (0)
+#endif
+
+/* Older versions of MSVC don't support the LL/ULL suffix. */
+#define DUK_U64_CONSTANT(x) x##ui64
+#define DUK_I64_CONSTANT(x) x##i64
#elif defined(DUK_F_EMSCRIPTEN)
/* --- Emscripten --- */
#define DUK_NORETURN(decl) decl __attribute__((noreturn))
@@ -1535,12 +1525,14 @@
defined(DUK_F_BCC) || \
(defined(__WORDSIZE) && (__WORDSIZE == 32)) || \
((defined(DUK_F_OLD_SOLARIS) || defined(DUK_F_AIX) || \
- defined(DUK_F_HPUX)) && defined(_ILP32))
+ defined(DUK_F_HPUX)) && defined(_ILP32)) || \
+ defined(DUK_F_ARM32)
#define DUK_F_32BIT_PTRS
#elif defined(DUK_F_X64) || \
(defined(__WORDSIZE) && (__WORDSIZE == 64)) || \
((defined(DUK_F_OLD_SOLARIS) || defined(DUK_F_AIX) || \
- defined(DUK_F_HPUX)) && defined(_LP64))
+ defined(DUK_F_HPUX)) && defined(_LP64)) || \
+ defined(DUK_F_ARM64)
#define DUK_F_64BIT_PTRS
#else
/* not sure, not needed with C99 anyway */
@@ -1743,13 +1735,16 @@ typedef unsigned long long duk_uint64_t;
typedef signed long long duk_int64_t;
#endif
#endif
-#if !defined(DUK_F_HAVE_64BIT) && \
- (defined(DUK_F_MINGW) || defined(DUK_F_MSVC))
-/* Both MinGW and MSVC have a 64-bit type. */
+#if !defined(DUK_F_HAVE_64BIT) && defined(DUK_F_MINGW)
#define DUK_F_HAVE_64BIT
typedef unsigned long duk_uint64_t;
typedef signed long duk_int64_t;
#endif
+#if !defined(DUK_F_HAVE_64BIT) && defined(DUK_F_MSVC)
+#define DUK_F_HAVE_64BIT
+typedef unsigned __int64 duk_uint64_t;
+typedef signed __int64 duk_int64_t;
+#endif
#if !defined(DUK_F_HAVE_64BIT)
/* cannot detect 64-bit type, not always needed so don't error */
#endif
@@ -1957,8 +1952,8 @@ typedef duk_uint_fast16_t duk_small_uint_fast_t;
#define DUK_SMALL_UINT_FAST_MIN DUK_UINT_FAST16_MIN
#define DUK_SMALL_UINT_FAST_MAX DUK_UINT_FAST16_MAX
-/* Boolean values are represented with the platform 'int'. */
-typedef duk_small_int_t duk_bool_t;
+/* Boolean values are represented with the platform 'unsigned int'. */
+typedef duk_small_uint_t duk_bool_t;
#define DUK_BOOL_MIN DUK_SMALL_INT_MIN
#define DUK_BOOL_MAX DUK_SMALL_INT_MAX
@@ -2029,7 +2024,10 @@ typedef double duk_double_t;
#endif
#endif
-/* Type for public API calls. */
+/* Type used in public API declarations and user code. Typedef maps to
+ * 'struct duk_hthread' like the 'duk_hthread' typedef which is used
+ * exclusively in internals.
+ */
typedef struct duk_hthread duk_context;
/* Check whether we should use 64-bit integers or not.
@@ -2676,6 +2674,13 @@ typedef struct duk_hthread duk_context;
#undef DUK_USE_GCC_PRAGMAS
#endif
+#if !defined(DUK_U64_CONSTANT)
+#define DUK_U64_CONSTANT(x) x##ULL
+#endif
+#if !defined(DUK_I64_CONSTANT)
+#define DUK_I64_CONSTANT(x) x##LL
+#endif
+
/* Workaround for GH-323: avoid inlining control when compiling from
* multiple sources, as it causes compiler portability trouble.
*/
@@ -2773,6 +2778,9 @@ typedef struct duk_hthread duk_context;
#define DUK_USE_BUFFEROBJECT_SUPPORT
#undef DUK_USE_BUFLEN16
#define DUK_USE_BYTECODE_DUMP_SUPPORT
+#define DUK_USE_CACHE_ACTIVATION
+#define DUK_USE_CACHE_CATCHER
+#define DUK_USE_CALLSTACK_LIMIT 10000
#define DUK_USE_COMMONJS_MODULES
#define DUK_USE_COMPILER_RECLIMIT 2500
#define DUK_USE_COROUTINE_SUPPORT
@@ -2807,7 +2815,10 @@ typedef struct duk_hthread duk_context;
#define DUK_USE_ES6_PROXY
#define DUK_USE_ES6_REGEXP_SYNTAX
#define DUK_USE_ES6_UNICODE_ESCAPE
+#define DUK_USE_ES7
#define DUK_USE_ES7_EXP_OPERATOR
+#define DUK_USE_ES8
+#define DUK_USE_ES9
#define DUK_USE_ESBC_LIMITS
#define DUK_USE_ESBC_MAX_BYTES 2147418112L
#define DUK_USE_ESBC_MAX_LINENUMBER 2147418112L
@@ -2822,6 +2833,7 @@ typedef struct duk_hthread duk_context;
#undef DUK_USE_FASTINT
#define DUK_USE_FAST_REFCOUNT_DEFAULT
#undef DUK_USE_FATAL_HANDLER
+#define DUK_USE_FATAL_MAXLEN 128
#define DUK_USE_FINALIZER_SUPPORT
#undef DUK_USE_FINALIZER_TORTURE
#undef DUK_USE_FUNCPTR16
@@ -2831,6 +2843,7 @@ typedef struct duk_hthread duk_context;
#define DUK_USE_FUNC_FILENAME_PROPERTY
#define DUK_USE_FUNC_NAME_PROPERTY
#undef DUK_USE_GC_TORTURE
+#undef DUK_USE_GET_MONOTONIC_TIME
#undef DUK_USE_GET_RANDOM_DOUBLE
#undef DUK_USE_GLOBAL_BINDING
#define DUK_USE_GLOBAL_BUILTIN
@@ -2849,6 +2862,7 @@ typedef struct duk_hthread duk_context;
#define DUK_USE_HSTRING_ARRIDX
#define DUK_USE_HSTRING_CLEN
#undef DUK_USE_HSTRING_EXTDATA
+#define DUK_USE_HSTRING_LAZY_CLEN
#define DUK_USE_HTML_COMMENTS
#define DUK_USE_IDCHAR_FASTPATH
#undef DUK_USE_INJECT_HEAP_ALLOC_ERROR
@@ -2885,12 +2899,15 @@ typedef struct duk_hthread duk_context;
#undef DUK_USE_OBJSIZES16
#undef DUK_USE_PARANOID_ERRORS
#define DUK_USE_PC2LINE
+#define DUK_USE_PERFORMANCE_BUILTIN
#undef DUK_USE_PREFER_SIZE
+#undef DUK_USE_PROMISE_BUILTIN
#define DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS
#undef DUK_USE_REFCOUNT16
#define DUK_USE_REFCOUNT32
#define DUK_USE_REFERENCE_COUNTING
#define DUK_USE_REFLECT_BUILTIN
+#define DUK_USE_REGEXP_CANON_BITMAP
#undef DUK_USE_REGEXP_CANON_WORKAROUND
#define DUK_USE_REGEXP_COMPILER_RECLIMIT 10000
#define DUK_USE_REGEXP_EXECUTOR_RECLIMIT 10000
@@ -2925,6 +2942,10 @@ typedef struct duk_hthread duk_context;
#define DUK_USE_TRACEBACKS
#define DUK_USE_TRACEBACK_DEPTH 10
#define DUK_USE_USER_DECLARE() /* no user declarations */
+#define DUK_USE_VALSTACK_GROW_SHIFT 2
+#define DUK_USE_VALSTACK_LIMIT 1000000L
+#define DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT 2
+#define DUK_USE_VALSTACK_SHRINK_SLACK_SHIFT 4
#undef DUK_USE_VALSTACK_UNSAFE
#define DUK_USE_VERBOSE_ERRORS
#define DUK_USE_VERBOSE_EXECUTOR_ERRORS
@@ -2958,11 +2979,13 @@ typedef struct duk_hthread duk_context;
#if defined(DUK_USE_DATE_GET_NOW)
/* External provider already defined. */
#elif defined(DUK_USE_DATE_NOW_GETTIMEOFDAY)
-#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_gettimeofday((ctx))
+#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_gettimeofday()
#elif defined(DUK_USE_DATE_NOW_TIME)
-#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_time((ctx))
+#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_time()
#elif defined(DUK_USE_DATE_NOW_WINDOWS)
-#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_windows((ctx))
+#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_windows()
+#elif defined(DUK_USE_DATE_NOW_WINDOWS_SUBMS)
+#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_windows_subms()
#else
#error no provider for DUK_USE_DATE_GET_NOW()
#endif
@@ -2998,6 +3021,16 @@ typedef struct duk_hthread duk_context;
/* No provider for DUK_USE_DATE_FORMAT_STRING(), fall back to ISO 8601 only. */
#endif
+#if defined(DUK_USE_GET_MONOTONIC_TIME)
+/* External provider already defined. */
+#elif defined(DUK_USE_GET_MONOTONIC_TIME_CLOCK_GETTIME)
+#define DUK_USE_GET_MONOTONIC_TIME(ctx) duk_bi_date_get_monotonic_time_clock_gettime()
+#elif defined(DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC)
+#define DUK_USE_GET_MONOTONIC_TIME(ctx) duk_bi_date_get_monotonic_time_windows_qpc()
+#else
+/* No provider for DUK_USE_GET_MONOTONIC_TIME(), fall back to DUK_USE_DATE_GET_NOW(). */
+#endif
+
#endif /* DUK_COMPILING_DUKTAPE */
/*
diff --git a/content/handlers/javascript/duktape/duktape.c b/content/handlers/javascript/duktape/duktape.c
index c031de0..52b9e13 100644
--- a/content/handlers/javascript/duktape/duktape.c
+++ b/content/handlers/javascript/duktape/duktape.c
@@ -1,7 +1,7 @@
/* Omit from static analysis. */
#ifndef __clang_analyzer__
/*
- * Single source autogenerated distributable for Duktape 2.1.0.
+ * Single source autogenerated distributable for Duktape 2.2.0.
*
* Git commit external (external).
* Git branch external.
@@ -86,6 +86,9 @@
* * Remko Tron\u00e7on (https://el-tramo.be)
* * Romero Malaquias (rbsm@ic.ufal.br)
* * Michael Drake <michael.drake@codethink.co.uk>
+* * Steven Don (https://github.com/shdon)
+* * Simon Stone (https://github.com/sstone1)
+* * \J. McC. (https://github.com/jmhmccr)
*
* Other contributions
* ===================
@@ -410,47 +413,47 @@ typedef union duk_double_union duk_double_union;
#if defined(DUK_USE_DOUBLE_ME)
/* Macros for 64-bit ops + mixed endian doubles. */
#define DUK__DBLUNION_SET_NAN_FULL(u) do { \
- (u)->ull[DUK_DBL_IDX_ULL0] = 0x000000007ff80000ULL; \
+ (u)->ull[DUK_DBL_IDX_ULL0] = DUK_U64_CONSTANT(0x000000007ff80000); \
} while (0)
#define DUK__DBLUNION_IS_NAN_FULL(u) \
- ((((u)->ull[DUK_DBL_IDX_ULL0] & 0x000000007ff00000ULL) == 0x000000007ff00000ULL) && \
- ((((u)->ull[DUK_DBL_IDX_ULL0]) & 0xffffffff000fffffULL) != 0))
+ ((((u)->ull[DUK_DBL_IDX_ULL0] & DUK_U64_CONSTANT(0x000000007ff00000)) == DUK_U64_CONSTANT(0x000000007ff00000)) && \
+ ((((u)->ull[DUK_DBL_IDX_ULL0]) & DUK_U64_CONSTANT(0xffffffff000fffff)) != 0))
#define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \
- ((u)->ull[DUK_DBL_IDX_ULL0] == 0x000000007ff80000ULL)
+ ((u)->ull[DUK_DBL_IDX_ULL0] == DUK_U64_CONSTANT(0x000000007ff80000))
#define DUK__DBLUNION_IS_ANYINF(u) \
- (((u)->ull[DUK_DBL_IDX_ULL0] & 0xffffffff7fffffffULL) == 0x000000007ff00000ULL)
+ (((u)->ull[DUK_DBL_IDX_ULL0] & DUK_U64_CONSTANT(0xffffffff7fffffff)) == DUK_U64_CONSTANT(0x000000007ff00000))
#define DUK__DBLUNION_IS_POSINF(u) \
- ((u)->ull[DUK_DBL_IDX_ULL0] == 0x000000007ff00000ULL)
+ ((u)->ull[DUK_DBL_IDX_ULL0] == DUK_U64_CONSTANT(0x000000007ff00000))
#define DUK__DBLUNION_IS_NEGINF(u) \
- ((u)->ull[DUK_DBL_IDX_ULL0] == 0x00000000fff00000ULL)
+ ((u)->ull[DUK_DBL_IDX_ULL0] == DUK_U64_CONSTANT(0x00000000fff00000))
#define DUK__DBLUNION_IS_ANYZERO(u) \
- (((u)->ull[DUK_DBL_IDX_ULL0] & 0xffffffff7fffffffULL) == 0x0000000000000000ULL)
+ (((u)->ull[DUK_DBL_IDX_ULL0] & DUK_U64_CONSTANT(0xffffffff7fffffff)) == DUK_U64_CONSTANT(0x0000000000000000))
#define DUK__DBLUNION_IS_POSZERO(u) \
- ((u)->ull[DUK_DBL_IDX_ULL0] == 0x0000000000000000ULL)
+ ((u)->ull[DUK_DBL_IDX_ULL0] == DUK_U64_CONSTANT(0x0000000000000000))
#define DUK__DBLUNION_IS_NEGZERO(u) \
- ((u)->ull[DUK_DBL_IDX_ULL0] == 0x0000000080000000ULL)
+ ((u)->ull[DUK_DBL_IDX_ULL0] == DUK_U64_CONSTANT(0x0000000080000000))
#else
/* Macros for 64-bit ops + big/little endian doubles. */
#define DUK__DBLUNION_SET_NAN_FULL(u) do { \
- (u)->ull[DUK_DBL_IDX_ULL0] = 0x7ff8000000000000ULL; \
+ (u)->ull[DUK_DBL_IDX_ULL0] = DUK_U64_CONSTANT(0x7ff8000000000000); \
} while (0)
#define DUK__DBLUNION_IS_NAN_FULL(u) \
- ((((u)->ull[DUK_DBL_IDX_ULL0] & 0x7ff0000000000000ULL) == 0x7ff0000000000000UL) && \
- ((((u)->ull[DUK_DBL_IDX_ULL0]) & 0x000fffffffffffffULL) != 0))
+ ((((u)->ull[DUK_DBL_IDX_ULL0] & DUK_U64_CONSTANT(0x7ff0000000000000)) == DUK_U64_CONSTANT(0x7ff0000000000000)) && \
+ ((((u)->ull[DUK_DBL_IDX_ULL0]) & DUK_U64_CONSTANT(0x000fffffffffffff)) != 0))
#define DUK__DBLUNION_IS_NORMALIZED_NAN_FULL(u) \
- ((u)->ull[DUK_DBL_IDX_ULL0] == 0x7ff8000000000000ULL)
+ ((u)->ull[DUK_DBL_IDX_ULL0] == DUK_U64_CONSTANT(0x7ff8000000000000))
#define DUK__DBLUNION_IS_ANYINF(u) \
- (((u)->ull[DUK_DBL_IDX_ULL0] & 0x7fffffffffffffffULL) == 0x7ff0000000000000ULL)
+ (((u)->ull[DUK_DBL_IDX_ULL0] & DUK_U64_CONSTANT(0x7fffffffffffffff)) == DUK_U64_CONSTANT(0x7ff0000000000000))
#define DUK__DBLUNION_IS_POSINF(u) \
- ((u)->ull[DUK_DBL_IDX_ULL0] == 0x7ff0000000000000ULL)
+ ((u)->ull[DUK_DBL_IDX_ULL0] == DUK_U64_CONSTANT(0x7ff0000000000000))
#define DUK__DBLUNION_IS_NEGINF(u) \
- ((u)->ull[DUK_DBL_IDX_ULL0] == 0xfff0000000000000ULL)
+ ((u)->ull[DUK_DBL_IDX_ULL0] == DUK_U64_CONSTANT(0xfff0000000000000))
#define DUK__DBLUNION_IS_ANYZERO(u) \
- (((u)->ull[DUK_DBL_IDX_ULL0] & 0x7fffffffffffffffULL) == 0x0000000000000000ULL)
+ (((u)->ull[DUK_DBL_IDX_ULL0] & DUK_U64_CONSTANT(0x7fffffffffffffff)) == DUK_U64_CONSTANT(0x0000000000000000))
#define DUK__DBLUNION_IS_POSZERO(u) \
- ((u)->ull[DUK_DBL_IDX_ULL0] == 0x0000000000000000ULL)
+ ((u)->ull[DUK_DBL_IDX_ULL0] == DUK_U64_CONSTANT(0x0000000000000000))
#define DUK__DBLUNION_IS_NEGZERO(u) \
- ((u)->ull[DUK_DBL_IDX_ULL0] == 0x8000000000000000ULL)
+ ((u)->ull[DUK_DBL_IDX_ULL0] == DUK_U64_CONSTANT(0x8000000000000000))
#endif
#else /* DUK_USE_64BIT_OPS */
/* Macros for no 64-bit ops, any endianness. */
@@ -597,7 +600,7 @@ typedef union duk_double_union duk_double_union;
/* Some sign bit helpers. */
#if defined(DUK_USE_64BIT_OPS)
-#define DUK_DBLUNION_HAS_SIGNBIT(u) (((u)->ull[DUK_DBL_IDX_ULL0] & 0x8000000000000000ULL) != 0)
+#define DUK_DBLUNION_HAS_SIGNBIT(u) (((u)->ull[DUK_DBL_IDX_ULL0] & DUK_U64_CONSTANT(0x8000000000000000)) != 0)
#define DUK_DBLUNION_GET_SIGNBIT(u) (((u)->ull[DUK_DBL_IDX_ULL0] >> 63U))
#else
#define DUK_DBLUNION_HAS_SIGNBIT(u) (((u)->ui[DUK_DBL_IDX_UI0] & 0x80000000UL) != 0)
@@ -706,10 +709,12 @@ struct duk_hstring_external;
struct duk_hobject;
struct duk_hcompfunc;
struct duk_hnatfunc;
+struct duk_hboundfunc;
struct duk_hthread;
struct duk_hbufobj;
struct duk_hdecenv;
struct duk_hobjenv;
+struct duk_hproxy;
struct duk_hbuffer;
struct duk_hbuffer_fixed;
struct duk_hbuffer_dynamic;
@@ -764,10 +769,12 @@ typedef struct duk_hstring_external duk_hstring_external;
typedef struct duk_hobject duk_hobject;
typedef struct duk_hcompfunc duk_hcompfunc;
typedef struct duk_hnatfunc duk_hnatfunc;
+typedef struct duk_hboundfunc duk_hboundfunc;
typedef struct duk_hthread duk_hthread;
typedef struct duk_hbufobj duk_hbufobj;
typedef struct duk_hdecenv duk_hdecenv;
typedef struct duk_hobjenv duk_hobjenv;
+typedef struct duk_hproxy duk_hproxy;
typedef struct duk_hbuffer duk_hbuffer;
typedef struct duk_hbuffer_fixed duk_hbuffer_fixed;
typedef struct duk_hbuffer_dynamic duk_hbuffer_dynamic;
@@ -942,7 +949,7 @@ typedef struct {
} while (0)
#else
#define DUK__TVAL_SET_I48(tv,i) do { \
- (tv)->ull[DUK_DBL_IDX_ULL0] = (((duk_uint64_t) DUK_TAG_FASTINT) << 48) | (((duk_uint64_t) (i)) & 0x0000ffffffffffffULL); \
+ (tv)->ull[DUK_DBL_IDX_ULL0] = (((duk_uint64_t) DUK_TAG_FASTINT) << 48) | (((duk_uint64_t) (i)) & DUK_U64_CONSTANT(0x0000ffffffffffff)); \
} while (0)
#define DUK__TVAL_SET_U32(tv,i) do { \
(tv)->ull[DUK_DBL_IDX_ULL0] = (((duk_uint64_t) DUK_TAG_FASTINT) << 48) | (duk_uint64_t) (i); \
@@ -1039,7 +1046,7 @@ typedef struct {
#define DUK_TVAL_SET_TVAL(tv,x) do { *(tv) = *(x); } while (0)
/* getters */
-#define DUK_TVAL_GET_BOOLEAN(tv) ((duk_small_int_t) (tv)->us[DUK_DBL_IDX_US1])
+#define DUK_TVAL_GET_BOOLEAN(tv) ((duk_small_uint_t) (tv)->us[DUK_DBL_IDX_US1])
#if defined(DUK_USE_FASTINT)
#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->d)
#define DUK_TVAL_GET_FASTINT(tv) DUK__TVAL_GET_FASTINT((tv))
@@ -1055,7 +1062,7 @@ typedef struct {
(out_fp) = (duk_c_function) (tv)->ui[DUK_DBL_IDX_UI1]; \
} while (0)
#define DUK_TVAL_GET_LIGHTFUNC_FUNCPTR(tv) ((duk_c_function) ((tv)->ui[DUK_DBL_IDX_UI1]))
-#define DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv) (((duk_small_int_t) (tv)->ui[DUK_DBL_IDX_UI0]) & 0xffffUL)
+#define DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv) (((duk_small_uint_t) (tv)->ui[DUK_DBL_IDX_UI0]) & 0xffffUL)
#define DUK_TVAL_GET_STRING(tv) ((duk_hstring *) (tv)->vp[DUK_DBL_IDX_VP1])
#define DUK_TVAL_GET_OBJECT(tv) ((duk_hobject *) (tv)->vp[DUK_DBL_IDX_VP1])
#define DUK_TVAL_GET_BUFFER(tv) ((duk_hbuffer *) (tv)->vp[DUK_DBL_IDX_VP1])
@@ -1193,7 +1200,7 @@ typedef struct {
duk_tval *duk__tv; \
duk__tv = (tv); \
duk__tv->t = DUK_TAG_BOOLEAN; \
- duk__tv->v.i = (val); \
+ duk__tv->v.i = (duk_small_int_t) (val); \
} while (0)
#if defined(DUK_USE_FASTINT)
@@ -1324,7 +1331,7 @@ typedef struct {
#define DUK_TVAL_SET_TVAL(tv,x) do { *(tv) = *(x); } while (0)
/* getters */
-#define DUK_TVAL_GET_BOOLEAN(tv) ((tv)->v.i)
+#define DUK_TVAL_GET_BOOLEAN(tv) ((duk_small_uint_t) (tv)->v.i)
#if defined(DUK_USE_FASTINT)
#define DUK_TVAL_GET_DOUBLE(tv) ((tv)->v.d)
#define DUK_TVAL_GET_FASTINT(tv) ((tv)->v.fi)
@@ -1351,7 +1358,7 @@ typedef struct {
(out_fp) = (tv)->v.lightfunc; \
} while (0)
#define DUK_TVAL_GET_LIGHTFUNC_FUNCPTR(tv) ((tv)->v.lightfunc)
-#define DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv) ((duk_uint32_t) ((tv)->v_extra))
+#define DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv) ((duk_small_uint_t) ((tv)->v_extra))
#define DUK_TVAL_GET_STRING(tv) ((tv)->v.hstring)
#define DUK_TVAL_GET_OBJECT(tv) ((tv)->v.hobject)
#define DUK_TVAL_GET_BUFFER(tv) ((tv)->v.hbuffer)
@@ -1416,11 +1423,11 @@ DUK_INTERNAL_DECL DUK_INLINE duk_double_t duk_tval_get_number_unpacked_fastint(d
#define DUK_LFUNC_FLAGS_GET_MAGIC(lf_flags) \
((duk_int32_t) (duk_int8_t) (((duk_uint16_t) (lf_flags)) >> 8))
#define DUK_LFUNC_FLAGS_GET_LENGTH(lf_flags) \
- (((lf_flags) >> 4) & 0x0f)
+ (((lf_flags) >> 4) & 0x0fU)
#define DUK_LFUNC_FLAGS_GET_NARGS(lf_flags) \
- ((lf_flags) & 0x0f)
+ ((lf_flags) & 0x0fU)
#define DUK_LFUNC_FLAGS_PACK(magic,length,nargs) \
- (((magic) & 0xff) << 8) | ((length) << 4) | (nargs)
+ ((((duk_small_uint_t) (magic)) & 0xffU) << 8) | ((length) << 4) | (nargs)
#define DUK_LFUNC_NARGS_VARARGS 0x0f /* varargs marker */
#define DUK_LFUNC_NARGS_MIN 0x00
@@ -1432,8 +1439,8 @@ DUK_INTERNAL_DECL DUK_INLINE duk_double_t duk_tval_get_number_unpacked_fastint(d
/* fastint constants etc */
#if defined(DUK_USE_FASTINT)
-#define DUK_FASTINT_MIN (-0x800000000000LL)
-#define DUK_FASTINT_MAX 0x7fffffffffffLL
+#define DUK_FASTINT_MIN (DUK_I64_CONSTANT(-0x800000000000))
+#define DUK_FASTINT_MAX (DUK_I64_CONSTANT(0x7fffffffffff))
#define DUK_FASTINT_BITS 48
DUK_INTERNAL_DECL DUK_INLINE void duk_tval_set_number_chkfast_fast(duk_tval *tv, duk_double_t x);
@@ -1662,302 +1669,296 @@ DUK_INTERNAL_DECL void duk_tval_set_number_chkfast_slow(duk_tval *tv, duk_double
#define DUK_STRIDX_CALLER 69 /* 'caller' */
#define DUK_HEAP_STRING_CALLER(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_CALLER)
#define DUK_HTHREAD_STRING_CALLER(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_CALLER)
-#define DUK_STRIDX_DELETE_PROPERTY 70 /* 'deleteProperty' */
+#define DUK_STRIDX_APPLY 70 /* 'apply' */
+#define DUK_HEAP_STRING_APPLY(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_APPLY)
+#define DUK_HTHREAD_STRING_APPLY(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_APPLY)
+#define DUK_STRIDX_CONSTRUCT 71 /* 'construct' */
+#define DUK_HEAP_STRING_CONSTRUCT(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_CONSTRUCT)
+#define DUK_HTHREAD_STRING_CONSTRUCT(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_CONSTRUCT)
+#define DUK_STRIDX_DELETE_PROPERTY 72 /* 'deleteProperty' */
#define DUK_HEAP_STRING_DELETE_PROPERTY(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_DELETE_PROPERTY)
#define DUK_HTHREAD_STRING_DELETE_PROPERTY(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_DELETE_PROPERTY)
-#define DUK_STRIDX_GET 71 /* 'get' */
+#define DUK_STRIDX_GET 73 /* 'get' */
#define DUK_HEAP_STRING_GET(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_GET)
#define DUK_HTHREAD_STRING_GET(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_GET)
-#define DUK_STRIDX_HAS 72 /* 'has' */
+#define DUK_STRIDX_HAS 74 /* 'has' */
#define DUK_HEAP_STRING_HAS(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_HAS)
#define DUK_HTHREAD_STRING_HAS(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_HAS)
-#define DUK_STRIDX_OWN_KEYS 73 /* 'ownKeys' */
+#define DUK_STRIDX_OWN_KEYS 75 /* 'ownKeys' */
#define DUK_HEAP_STRING_OWN_KEYS(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_OWN_KEYS)
#define DUK_HTHREAD_STRING_OWN_KEYS(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_OWN_KEYS)
-#define DUK_STRIDX_SET_PROTOTYPE_OF 74 /* 'setPrototypeOf' */
+#define DUK_STRIDX_SET_PROTOTYPE_OF 76 /* 'setPrototypeOf' */
#define DUK_HEAP_STRING_SET_PROTOTYPE_OF(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_SET_PROTOTYPE_OF)
#define DUK_HTHREAD_STRING_SET_PROTOTYPE_OF(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_SET_PROTOTYPE_OF)
-#define DUK_STRIDX___PROTO__ 75 /* '__proto__' */
+#define DUK_STRIDX___PROTO__ 77 /* '__proto__' */
#define DUK_HEAP_STRING___PROTO__(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX___PROTO__)
#define DUK_HTHREAD_STRING___PROTO__(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX___PROTO__)
-#define DUK_STRIDX_TO_STRING 76 /* 'toString' */
+#define DUK_STRIDX_TO_STRING 78 /* 'toString' */
#define DUK_HEAP_STRING_TO_STRING(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_TO_STRING)
#define DUK_HTHREAD_STRING_TO_STRING(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_TO_STRING)
-#define DUK_STRIDX_TO_JSON 77 /* 'toJSON' */
+#define DUK_STRIDX_TO_JSON 79 /* 'toJSON' */
#define DUK_HEAP_STRING_TO_JSON(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_TO_JSON)
#define DUK_HTHREAD_STRING_TO_JSON(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_TO_JSON)
-#define DUK_STRIDX_TYPE 78 /* 'type' */
+#define DUK_STRIDX_TYPE 80 /* 'type' */
#define DUK_HEAP_STRING_TYPE(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_TYPE)
#define DUK_HTHREAD_STRING_TYPE(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_TYPE)
-#define DUK_STRIDX_DATA 79 /* 'data' */
+#define DUK_STRIDX_DATA 81 /* 'data' */
#define DUK_HEAP_STRING_DATA(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_DATA)
#define DUK_HTHREAD_STRING_DATA(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_DATA)
-#define DUK_STRIDX_LENGTH 80 /* 'length' */
+#define DUK_STRIDX_LENGTH 82 /* 'length' */
#define DUK_HEAP_STRING_LENGTH(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LENGTH)
#define DUK_HTHREAD_STRING_LENGTH(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LENGTH)
-#define DUK_STRIDX_SET 81 /* 'set' */
+#define DUK_STRIDX_SET 83 /* 'set' */
#define DUK_HEAP_STRING_SET(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_SET)
#define DUK_HTHREAD_STRING_SET(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_SET)
-#define DUK_STRIDX_STACK 82 /* 'stack' */
+#define DUK_STRIDX_STACK 84 /* 'stack' */
#define DUK_HEAP_STRING_STACK(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_STACK)
#define DUK_HTHREAD_STRING_STACK(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_STACK)
-#define DUK_STRIDX_PC 83 /* 'pc' */
+#define DUK_STRIDX_PC 85 /* 'pc' */
#define DUK_HEAP_STRING_PC(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_PC)
#define DUK_HTHREAD_STRING_PC(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_PC)
-#define DUK_STRIDX_LINE_NUMBER 84 /* 'lineNumber' */
+#define DUK_STRIDX_LINE_NUMBER 86 /* 'lineNumber' */
#define DUK_HEAP_STRING_LINE_NUMBER(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LINE_NUMBER)
#define DUK_HTHREAD_STRING_LINE_NUMBER(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LINE_NUMBER)
-#define DUK_STRIDX_INT_TRACEDATA 85 /* '\xffTracedata' */
+#define DUK_STRIDX_INT_TRACEDATA 87 /* '\x82Tracedata' */
#define DUK_HEAP_STRING_INT_TRACEDATA(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_TRACEDATA)
#define DUK_HTHREAD_STRING_INT_TRACEDATA(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_TRACEDATA)
-#define DUK_STRIDX_NAME 86 /* 'name' */
+#define DUK_STRIDX_NAME 88 /* 'name' */
#define DUK_HEAP_STRING_NAME(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_NAME)
#define DUK_HTHREAD_STRING_NAME(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_NAME)
-#define DUK_STRIDX_FILE_NAME 87 /* 'fileName' */
+#define DUK_STRIDX_FILE_NAME 89 /* 'fileName' */
#define DUK_HEAP_STRING_FILE_NAME(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_FILE_NAME)
#define DUK_HTHREAD_STRING_FILE_NAME(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_FILE_NAME)
-#define DUK_STRIDX_LC_POINTER 88 /* 'pointer' */
+#define DUK_STRIDX_LC_POINTER 90 /* 'pointer' */
#define DUK_HEAP_STRING_LC_POINTER(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_POINTER)
#define DUK_HTHREAD_STRING_LC_POINTER(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_POINTER)
-#define DUK_STRIDX_INT_VALUE 89 /* '\xffValue' */
-#define DUK_HEAP_STRING_INT_VALUE(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_VALUE)
-#define DUK_HTHREAD_STRING_INT_VALUE(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_VALUE)
-#define DUK_STRIDX_INT_NEXT 90 /* '\xffNext' */
+#define DUK_STRIDX_INT_TARGET 91 /* '\x82Target' */
+#define DUK_HEAP_STRING_INT_TARGET(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_TARGET)
+#define DUK_HTHREAD_STRING_INT_TARGET(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_TARGET)
+#define DUK_STRIDX_INT_NEXT 92 /* '\x82Next' */
#define DUK_HEAP_STRING_INT_NEXT(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_NEXT)
#define DUK_HTHREAD_STRING_INT_NEXT(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_NEXT)
-#define DUK_STRIDX_INT_BYTECODE 91 /* '\xffBytecode' */
+#define DUK_STRIDX_INT_BYTECODE 93 /* '\x82Bytecode' */
#define DUK_HEAP_STRING_INT_BYTECODE(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_BYTECODE)
#define DUK_HTHREAD_STRING_INT_BYTECODE(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_BYTECODE)
-#define DUK_STRIDX_INT_FORMALS 92 /* '\xffFormals' */
+#define DUK_STRIDX_INT_FORMALS 94 /* '\x82Formals' */
#define DUK_HEAP_STRING_INT_FORMALS(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_FORMALS)
#define DUK_HTHREAD_STRING_INT_FORMALS(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_FORMALS)
-#define DUK_STRIDX_INT_VARMAP 93 /* '\xffVarmap' */
+#define DUK_STRIDX_INT_VARMAP 95 /* '\x82Varmap' */
#define DUK_HEAP_STRING_INT_VARMAP(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_VARMAP)
#define DUK_HTHREAD_STRING_INT_VARMAP(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_VARMAP)
-#define DUK_STRIDX_INT_SOURCE 94 /* '\xffSource' */
+#define DUK_STRIDX_INT_SOURCE 96 /* '\x82Source' */
#define DUK_HEAP_STRING_INT_SOURCE(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_SOURCE)
#define DUK_HTHREAD_STRING_INT_SOURCE(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_SOURCE)
-#define DUK_STRIDX_INT_PC2LINE 95 /* '\xffPc2line' */
+#define DUK_STRIDX_INT_PC2LINE 97 /* '\x82Pc2line' */
#define DUK_HEAP_STRING_INT_PC2LINE(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_PC2LINE)
#define DUK_HTHREAD_STRING_INT_PC2LINE(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_PC2LINE)
-#define DUK_STRIDX_INT_THIS 96 /* '\xffThis' */
-#define DUK_HEAP_STRING_INT_THIS(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_THIS)
-#define DUK_HTHREAD_STRING_INT_THIS(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_THIS)
-#define DUK_STRIDX_INT_ARGS 97 /* '\xffArgs' */
-#define DUK_HEAP_STRING_INT_ARGS(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_ARGS)
-#define DUK_HTHREAD_STRING_INT_ARGS(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_ARGS)
-#define DUK_STRIDX_INT_MAP 98 /* '\xffMap' */
+#define DUK_STRIDX_INT_MAP 98 /* '\x82Map' */
#define DUK_HEAP_STRING_INT_MAP(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_MAP)
#define DUK_HTHREAD_STRING_INT_MAP(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_MAP)
-#define DUK_STRIDX_INT_VARENV 99 /* '\xffVarenv' */
+#define DUK_STRIDX_INT_VARENV 99 /* '\x82Varenv' */
#define DUK_HEAP_STRING_INT_VARENV(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_VARENV)
#define DUK_HTHREAD_STRING_INT_VARENV(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_VARENV)
-#define DUK_STRIDX_INT_FINALIZER 100 /* '\xffFinalizer' */
+#define DUK_STRIDX_INT_FINALIZER 100 /* '\x82Finalizer' */
#define DUK_HEAP_STRING_INT_FINALIZER(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_FINALIZER)
#define DUK_HTHREAD_STRING_INT_FINALIZER(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_FINALIZER)
-#define DUK_STRIDX_INT_TARGET 101 /* '\xffTarget' */
-#define DUK_HEAP_STRING_INT_TARGET(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_TARGET)
-#define DUK_HTHREAD_STRING_INT_TARGET(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_TARGET)
-#define DUK_STRIDX_INT_HANDLER 102 /* '\xffHandler' */
-#define DUK_HEAP_STRING_INT_HANDLER(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_HANDLER)
-#define DUK_HTHREAD_STRING_INT_HANDLER(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_HANDLER)
-#define DUK_STRIDX_COMPILE 103 /* 'compile' */
+#define DUK_STRIDX_INT_VALUE 101 /* '\x82Value' */
+#define DUK_HEAP_STRING_INT_VALUE(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INT_VALUE)
+#define DUK_HTHREAD_STRING_INT_VALUE(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INT_VALUE)
+#define DUK_STRIDX_COMPILE 102 /* 'compile' */
#define DUK_HEAP_STRING_COMPILE(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_COMPILE)
#define DUK_HTHREAD_STRING_COMPILE(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_COMPILE)
-#define DUK_STRIDX_INPUT 104 /* 'input' */
+#define DUK_STRIDX_INPUT 103 /* 'input' */
#define DUK_HEAP_STRING_INPUT(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INPUT)
#define DUK_HTHREAD_STRING_INPUT(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INPUT)
-#define DUK_STRIDX_ERR_CREATE 105 /* 'errCreate' */
+#define DUK_STRIDX_ERR_CREATE 104 /* 'errCreate' */
#define DUK_HEAP_STRING_ERR_CREATE(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_ERR_CREATE)
#define DUK_HTHREAD_STRING_ERR_CREATE(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_ERR_CREATE)
-#define DUK_STRIDX_ERR_THROW 106 /* 'errThrow' */
+#define DUK_STRIDX_ERR_THROW 105 /* 'errThrow' */
#define DUK_HEAP_STRING_ERR_THROW(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_ERR_THROW)
#define DUK_HTHREAD_STRING_ERR_THROW(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_ERR_THROW)
-#define DUK_STRIDX_ENV 107 /* 'env' */
+#define DUK_STRIDX_ENV 106 /* 'env' */
#define DUK_HEAP_STRING_ENV(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_ENV)
#define DUK_HTHREAD_STRING_ENV(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_ENV)
-#define DUK_STRIDX_HEX 108 /* 'hex' */
+#define DUK_STRIDX_HEX 107 /* 'hex' */
#define DUK_HEAP_STRING_HEX(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_HEX)
#define DUK_HTHREAD_STRING_HEX(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_HEX)
-#define DUK_STRIDX_BASE64 109 /* 'base64' */
+#define DUK_STRIDX_BASE64 108 /* 'base64' */
#define DUK_HEAP_STRING_BASE64(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_BASE64)
#define DUK_HTHREAD_STRING_BASE64(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_BASE64)
-#define DUK_STRIDX_JX 110 /* 'jx' */
+#define DUK_STRIDX_JX 109 /* 'jx' */
#define DUK_HEAP_STRING_JX(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JX)
#define DUK_HTHREAD_STRING_JX(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JX)
-#define DUK_STRIDX_JC 111 /* 'jc' */
+#define DUK_STRIDX_JC 110 /* 'jc' */
#define DUK_HEAP_STRING_JC(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JC)
#define DUK_HTHREAD_STRING_JC(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JC)
-#define DUK_STRIDX_RESUME 112 /* 'resume' */
-#define DUK_HEAP_STRING_RESUME(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_RESUME)
-#define DUK_HTHREAD_STRING_RESUME(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_RESUME)
-#define DUK_STRIDX_JSON_EXT_UNDEFINED 113 /* '{"_undef":true}' */
+#define DUK_STRIDX_JSON_EXT_UNDEFINED 111 /* '{"_undef":true}' */
#define DUK_HEAP_STRING_JSON_EXT_UNDEFINED(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JSON_EXT_UNDEFINED)
#define DUK_HTHREAD_STRING_JSON_EXT_UNDEFINED(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JSON_EXT_UNDEFINED)
-#define DUK_STRIDX_JSON_EXT_NAN 114 /* '{"_nan":true}' */
+#define DUK_STRIDX_JSON_EXT_NAN 112 /* '{"_nan":true}' */
#define DUK_HEAP_STRING_JSON_EXT_NAN(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JSON_EXT_NAN)
#define DUK_HTHREAD_STRING_JSON_EXT_NAN(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JSON_EXT_NAN)
-#define DUK_STRIDX_JSON_EXT_POSINF 115 /* '{"_inf":true}' */
+#define DUK_STRIDX_JSON_EXT_POSINF 113 /* '{"_inf":true}' */
#define DUK_HEAP_STRING_JSON_EXT_POSINF(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JSON_EXT_POSINF)
#define DUK_HTHREAD_STRING_JSON_EXT_POSINF(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JSON_EXT_POSINF)
-#define DUK_STRIDX_JSON_EXT_NEGINF 116 /* '{"_ninf":true}' */
+#define DUK_STRIDX_JSON_EXT_NEGINF 114 /* '{"_ninf":true}' */
#define DUK_HEAP_STRING_JSON_EXT_NEGINF(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JSON_EXT_NEGINF)
#define DUK_HTHREAD_STRING_JSON_EXT_NEGINF(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JSON_EXT_NEGINF)
-#define DUK_STRIDX_JSON_EXT_FUNCTION1 117 /* '{"_func":true}' */
+#define DUK_STRIDX_JSON_EXT_FUNCTION1 115 /* '{"_func":true}' */
#define DUK_HEAP_STRING_JSON_EXT_FUNCTION1(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JSON_EXT_FUNCTION1)
#define DUK_HTHREAD_STRING_JSON_EXT_FUNCTION1(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JSON_EXT_FUNCTION1)
-#define DUK_STRIDX_JSON_EXT_FUNCTION2 118 /* '{_func:true}' */
+#define DUK_STRIDX_JSON_EXT_FUNCTION2 116 /* '{_func:true}' */
#define DUK_HEAP_STRING_JSON_EXT_FUNCTION2(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_JSON_EXT_FUNCTION2)
#define DUK_HTHREAD_STRING_JSON_EXT_FUNCTION2(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_JSON_EXT_FUNCTION2)
-#define DUK_STRIDX_BREAK 119 /* 'break' */
+#define DUK_STRIDX_BREAK 117 /* 'break' */
#define DUK_HEAP_STRING_BREAK(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_BREAK)
#define DUK_HTHREAD_STRING_BREAK(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_BREAK)
-#define DUK_STRIDX_CASE 120 /* 'case' */
+#define DUK_STRIDX_CASE 118 /* 'case' */
#define DUK_HEAP_STRING_CASE(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_CASE)
#define DUK_HTHREAD_STRING_CASE(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_CASE)
-#define DUK_STRIDX_CATCH 121 /* 'catch' */
+#define DUK_STRIDX_CATCH 119 /* 'catch' */
#define DUK_HEAP_STRING_CATCH(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_CATCH)
#define DUK_HTHREAD_STRING_CATCH(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_CATCH)
-#define DUK_STRIDX_CONTINUE 122 /* 'continue' */
+#define DUK_STRIDX_CONTINUE 120 /* 'continue' */
#define DUK_HEAP_STRING_CONTINUE(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_CONTINUE)
#define DUK_HTHREAD_STRING_CONTINUE(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_CONTINUE)
-#define DUK_STRIDX_DEBUGGER 123 /* 'debugger' */
+#define DUK_STRIDX_DEBUGGER 121 /* 'debugger' */
#define DUK_HEAP_STRING_DEBUGGER(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_DEBUGGER)
#define DUK_HTHREAD_STRING_DEBUGGER(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_DEBUGGER)
-#define DUK_STRIDX_DEFAULT 124 /* 'default' */
+#define DUK_STRIDX_DEFAULT 122 /* 'default' */
#define DUK_HEAP_STRING_DEFAULT(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_DEFAULT)
#define DUK_HTHREAD_STRING_DEFAULT(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_DEFAULT)
-#define DUK_STRIDX_DELETE 125 /* 'delete' */
+#define DUK_STRIDX_DELETE 123 /* 'delete' */
#define DUK_HEAP_STRING_DELETE(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_DELETE)
#define DUK_HTHREAD_STRING_DELETE(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_DELETE)
-#define DUK_STRIDX_DO 126 /* 'do' */
+#define DUK_STRIDX_DO 124 /* 'do' */
#define DUK_HEAP_STRING_DO(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_DO)
#define DUK_HTHREAD_STRING_DO(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_DO)
-#define DUK_STRIDX_ELSE 127 /* 'else' */
+#define DUK_STRIDX_ELSE 125 /* 'else' */
#define DUK_HEAP_STRING_ELSE(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_ELSE)
#define DUK_HTHREAD_STRING_ELSE(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_ELSE)
-#define DUK_STRIDX_FINALLY 128 /* 'finally' */
+#define DUK_STRIDX_FINALLY 126 /* 'finally' */
#define DUK_HEAP_STRING_FINALLY(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_FINALLY)
#define DUK_HTHREAD_STRING_FINALLY(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_FINALLY)
-#define DUK_STRIDX_FOR 129 /* 'for' */
+#define DUK_STRIDX_FOR 127 /* 'for' */
#define DUK_HEAP_STRING_FOR(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_FOR)
#define DUK_HTHREAD_STRING_FOR(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_FOR)
-#define DUK_STRIDX_LC_FUNCTION 130 /* 'function' */
+#define DUK_STRIDX_LC_FUNCTION 128 /* 'function' */
#define DUK_HEAP_STRING_LC_FUNCTION(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_FUNCTION)
#define DUK_HTHREAD_STRING_LC_FUNCTION(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_FUNCTION)
-#define DUK_STRIDX_IF 131 /* 'if' */
+#define DUK_STRIDX_IF 129 /* 'if' */
#define DUK_HEAP_STRING_IF(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_IF)
#define DUK_HTHREAD_STRING_IF(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_IF)
-#define DUK_STRIDX_IN 132 /* 'in' */
+#define DUK_STRIDX_IN 130 /* 'in' */
#define DUK_HEAP_STRING_IN(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_IN)
#define DUK_HTHREAD_STRING_IN(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_IN)
-#define DUK_STRIDX_INSTANCEOF 133 /* 'instanceof' */
+#define DUK_STRIDX_INSTANCEOF 131 /* 'instanceof' */
#define DUK_HEAP_STRING_INSTANCEOF(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INSTANCEOF)
#define DUK_HTHREAD_STRING_INSTANCEOF(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INSTANCEOF)
-#define DUK_STRIDX_NEW 134 /* 'new' */
+#define DUK_STRIDX_NEW 132 /* 'new' */
#define DUK_HEAP_STRING_NEW(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_NEW)
#define DUK_HTHREAD_STRING_NEW(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_NEW)
-#define DUK_STRIDX_RETURN 135 /* 'return' */
+#define DUK_STRIDX_RETURN 133 /* 'return' */
#define DUK_HEAP_STRING_RETURN(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_RETURN)
#define DUK_HTHREAD_STRING_RETURN(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_RETURN)
-#define DUK_STRIDX_SWITCH 136 /* 'switch' */
+#define DUK_STRIDX_SWITCH 134 /* 'switch' */
#define DUK_HEAP_STRING_SWITCH(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_SWITCH)
#define DUK_HTHREAD_STRING_SWITCH(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_SWITCH)
-#define DUK_STRIDX_THIS 137 /* 'this' */
+#define DUK_STRIDX_THIS 135 /* 'this' */
#define DUK_HEAP_STRING_THIS(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_THIS)
#define DUK_HTHREAD_STRING_THIS(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_THIS)
-#define DUK_STRIDX_THROW 138 /* 'throw' */
+#define DUK_STRIDX_THROW 136 /* 'throw' */
#define DUK_HEAP_STRING_THROW(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_THROW)
#define DUK_HTHREAD_STRING_THROW(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_THROW)
-#define DUK_STRIDX_TRY 139 /* 'try' */
+#define DUK_STRIDX_TRY 137 /* 'try' */
#define DUK_HEAP_STRING_TRY(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_TRY)
#define DUK_HTHREAD_STRING_TRY(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_TRY)
-#define DUK_STRIDX_TYPEOF 140 /* 'typeof' */
+#define DUK_STRIDX_TYPEOF 138 /* 'typeof' */
#define DUK_HEAP_STRING_TYPEOF(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_TYPEOF)
#define DUK_HTHREAD_STRING_TYPEOF(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_TYPEOF)
-#define DUK_STRIDX_VAR 141 /* 'var' */
+#define DUK_STRIDX_VAR 139 /* 'var' */
#define DUK_HEAP_STRING_VAR(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_VAR)
#define DUK_HTHREAD_STRING_VAR(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_VAR)
-#define DUK_STRIDX_CONST 142 /* 'const' */
+#define DUK_STRIDX_CONST 140 /* 'const' */
#define DUK_HEAP_STRING_CONST(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_CONST)
#define DUK_HTHREAD_STRING_CONST(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_CONST)
-#define DUK_STRIDX_VOID 143 /* 'void' */
+#define DUK_STRIDX_VOID 141 /* 'void' */
#define DUK_HEAP_STRING_VOID(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_VOID)
#define DUK_HTHREAD_STRING_VOID(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_VOID)
-#define DUK_STRIDX_WHILE 144 /* 'while' */
+#define DUK_STRIDX_WHILE 142 /* 'while' */
#define DUK_HEAP_STRING_WHILE(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_WHILE)
#define DUK_HTHREAD_STRING_WHILE(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_WHILE)
-#define DUK_STRIDX_WITH 145 /* 'with' */
+#define DUK_STRIDX_WITH 143 /* 'with' */
#define DUK_HEAP_STRING_WITH(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_WITH)
#define DUK_HTHREAD_STRING_WITH(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_WITH)
-#define DUK_STRIDX_CLASS 146 /* 'class' */
+#define DUK_STRIDX_CLASS 144 /* 'class' */
#define DUK_HEAP_STRING_CLASS(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_CLASS)
#define DUK_HTHREAD_STRING_CLASS(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_CLASS)
-#define DUK_STRIDX_ENUM 147 /* 'enum' */
+#define DUK_STRIDX_ENUM 145 /* 'enum' */
#define DUK_HEAP_STRING_ENUM(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_ENUM)
#define DUK_HTHREAD_STRING_ENUM(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_ENUM)
-#define DUK_STRIDX_EXPORT 148 /* 'export' */
+#define DUK_STRIDX_EXPORT 146 /* 'export' */
#define DUK_HEAP_STRING_EXPORT(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_EXPORT)
#define DUK_HTHREAD_STRING_EXPORT(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_EXPORT)
-#define DUK_STRIDX_EXTENDS 149 /* 'extends' */
+#define DUK_STRIDX_EXTENDS 147 /* 'extends' */
#define DUK_HEAP_STRING_EXTENDS(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_EXTENDS)
#define DUK_HTHREAD_STRING_EXTENDS(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_EXTENDS)
-#define DUK_STRIDX_IMPORT 150 /* 'import' */
+#define DUK_STRIDX_IMPORT 148 /* 'import' */
#define DUK_HEAP_STRING_IMPORT(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_IMPORT)
#define DUK_HTHREAD_STRING_IMPORT(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_IMPORT)
-#define DUK_STRIDX_SUPER 151 /* 'super' */
+#define DUK_STRIDX_SUPER 149 /* 'super' */
#define DUK_HEAP_STRING_SUPER(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_SUPER)
#define DUK_HTHREAD_STRING_SUPER(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_SUPER)
-#define DUK_STRIDX_LC_NULL 152 /* 'null' */
+#define DUK_STRIDX_LC_NULL 150 /* 'null' */
#define DUK_HEAP_STRING_LC_NULL(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LC_NULL)
#define DUK_HTHREAD_STRING_LC_NULL(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LC_NULL)
-#define DUK_STRIDX_TRUE 153 /* 'true' */
+#define DUK_STRIDX_TRUE 151 /* 'true' */
#define DUK_HEAP_STRING_TRUE(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_TRUE)
#define DUK_HTHREAD_STRING_TRUE(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_TRUE)
-#define DUK_STRIDX_FALSE 154 /* 'false' */
+#define DUK_STRIDX_FALSE 152 /* 'false' */
#define DUK_HEAP_STRING_FALSE(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_FALSE)
#define DUK_HTHREAD_STRING_FALSE(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_FALSE)
-#define DUK_STRIDX_IMPLEMENTS 155 /* 'implements' */
+#define DUK_STRIDX_IMPLEMENTS 153 /* 'implements' */
#define DUK_HEAP_STRING_IMPLEMENTS(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_IMPLEMENTS)
#define DUK_HTHREAD_STRING_IMPLEMENTS(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_IMPLEMENTS)
-#define DUK_STRIDX_INTERFACE 156 /* 'interface' */
+#define DUK_STRIDX_INTERFACE 154 /* 'interface' */
#define DUK_HEAP_STRING_INTERFACE(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_INTERFACE)
#define DUK_HTHREAD_STRING_INTERFACE(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_INTERFACE)
-#define DUK_STRIDX_LET 157 /* 'let' */
+#define DUK_STRIDX_LET 155 /* 'let' */
#define DUK_HEAP_STRING_LET(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_LET)
#define DUK_HTHREAD_STRING_LET(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_LET)
-#define DUK_STRIDX_PACKAGE 158 /* 'package' */
+#define DUK_STRIDX_PACKAGE 156 /* 'package' */
#define DUK_HEAP_STRING_PACKAGE(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_PACKAGE)
#define DUK_HTHREAD_STRING_PACKAGE(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_PACKAGE)
-#define DUK_STRIDX_PRIVATE 159 /* 'private' */
+#define DUK_STRIDX_PRIVATE 157 /* 'private' */
#define DUK_HEAP_STRING_PRIVATE(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_PRIVATE)
#define DUK_HTHREAD_STRING_PRIVATE(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_PRIVATE)
-#define DUK_STRIDX_PROTECTED 160 /* 'protected' */
+#define DUK_STRIDX_PROTECTED 158 /* 'protected' */
#define DUK_HEAP_STRING_PROTECTED(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_PROTECTED)
#define DUK_HTHREAD_STRING_PROTECTED(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_PROTECTED)
-#define DUK_STRIDX_PUBLIC 161 /* 'public' */
+#define DUK_STRIDX_PUBLIC 159 /* 'public' */
#define DUK_HEAP_STRING_PUBLIC(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_PUBLIC)
#define DUK_HTHREAD_STRING_PUBLIC(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_PUBLIC)
-#define DUK_STRIDX_STATIC 162 /* 'static' */
+#define DUK_STRIDX_STATIC 160 /* 'static' */
#define DUK_HEAP_STRING_STATIC(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_STATIC)
#define DUK_HTHREAD_STRING_STATIC(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_STATIC)
-#define DUK_STRIDX_YIELD 163 /* 'yield' */
+#define DUK_STRIDX_YIELD 161 /* 'yield' */
#define DUK_HEAP_STRING_YIELD(heap) DUK_HEAP_GET_STRING((heap),DUK_STRIDX_YIELD)
#define DUK_HTHREAD_STRING_YIELD(thr) DUK_HTHREAD_GET_STRING((thr),DUK_STRIDX_YIELD)
-#define DUK_HEAP_NUM_STRINGS 164
-#define DUK_STRIDX_START_RESERVED 119
-#define DUK_STRIDX_START_STRICT_RESERVED 155
-#define DUK_STRIDX_END_RESERVED 164 /* exclusive endpoint */
+#define DUK_HEAP_NUM_STRINGS 162
+#define DUK_STRIDX_START_RESERVED 117
+#define DUK_STRIDX_START_STRICT_RESERVED 153
+#define DUK_STRIDX_END_RESERVED 162 /* exclusive endpoint */
/* To convert a heap stridx to a token number, subtract
* DUK_STRIDX_START_RESERVED and add DUK_TOK_START_RESERVED.
*/
#if !defined(DUK_SINGLE_FILE)
-DUK_INTERNAL_DECL const duk_uint8_t duk_strings_data[903];
+DUK_INTERNAL_DECL const duk_uint8_t duk_strings_data[892];
#endif /* !DUK_SINGLE_FILE */
#define DUK_STRDATA_MAX_STRLEN 17
-#define DUK_STRDATA_DATA_LENGTH 903
+#define DUK_STRDATA_DATA_LENGTH 892
#endif /* DUK_USE_ROM_STRINGS */
#if defined(DUK_USE_ROM_OBJECTS)
@@ -2013,10 +2014,14 @@ DUK_INTERNAL_DECL duk_ret_t duk_bi_object_prototype_value_of(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_object_prototype_has_own_property(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_object_prototype_is_prototype_of(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_object_prototype_property_is_enumerable(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_object_prototype_defineaccessor(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_object_prototype_lookupaccessor(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_function_prototype_to_string(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_function_prototype_apply(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_function_prototype_call(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_function_prototype_bind(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_native_function_length(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_native_function_name(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_array_constructor_is_array(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_array_prototype_to_string(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_array_prototype_join_shared(duk_context *ctx);
@@ -2083,10 +2088,13 @@ DUK_INTERNAL_DECL duk_ret_t duk_bi_error_prototype_linenumber_setter(duk_context
DUK_INTERNAL_DECL duk_ret_t duk_bi_error_prototype_to_string(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_math_object_onearg_shared(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_math_object_twoarg_shared(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_math_object_clz32(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_math_object_hypot(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_math_object_imul(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_math_object_max(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_math_object_min(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_math_object_random(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_math_object_sign(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_json_object_parse(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_json_object_stringify(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_duktape_object_info(duk_context *ctx);
@@ -2100,6 +2108,8 @@ DUK_INTERNAL_DECL duk_ret_t duk_bi_thread_yield(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_thread_resume(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_thread_current(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_pointer_prototype_tostring_shared(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_reflect_apply(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_reflect_construct(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_reflect_object_delete_property(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_reflect_object_get(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_reflect_object_has(duk_context *ctx);
@@ -2128,8 +2138,9 @@ DUK_INTERNAL_DECL duk_ret_t duk_bi_textencoder_prototype_encoding_getter(duk_con
DUK_INTERNAL_DECL duk_ret_t duk_bi_textencoder_prototype_encode(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_textdecoder_prototype_shared_getter(duk_context *ctx);
DUK_INTERNAL_DECL duk_ret_t duk_bi_textdecoder_prototype_decode(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_performance_now(duk_context *ctx);
#if !defined(DUK_SINGLE_FILE)
-DUK_INTERNAL_DECL const duk_c_function duk_bi_native_functions[166];
+DUK_INTERNAL_DECL const duk_c_function duk_bi_native_functions[176];
#endif /* !DUK_SINGLE_FILE */
#define DUK_BIDX_GLOBAL 0
#define DUK_BIDX_GLOBAL_ENV 1
@@ -2137,92 +2148,69 @@ DUK_INTERNAL_DECL const duk_c_function duk_bi_native_functions[166];
#define DUK_BIDX_OBJECT_PROTOTYPE 3
#define DUK_BIDX_FUNCTION_CONSTRUCTOR 4
#define DUK_BIDX_FUNCTION_PROTOTYPE 5
-#define DUK_BIDX_ARRAY_CONSTRUCTOR 6
-#define DUK_BIDX_ARRAY_PROTOTYPE 7
-#define DUK_BIDX_STRING_CONSTRUCTOR 8
-#define DUK_BIDX_STRING_PROTOTYPE 9
-#define DUK_BIDX_BOOLEAN_CONSTRUCTOR 10
-#define DUK_BIDX_BOOLEAN_PROTOTYPE 11
-#define DUK_BIDX_NUMBER_CONSTRUCTOR 12
-#define DUK_BIDX_NUMBER_PROTOTYPE 13
-#define DUK_BIDX_DATE_CONSTRUCTOR 14
-#define DUK_BIDX_DATE_PROTOTYPE 15
-#define DUK_BIDX_REGEXP_CONSTRUCTOR 16
-#define DUK_BIDX_REGEXP_PROTOTYPE 17
-#define DUK_BIDX_ERROR_CONSTRUCTOR 18
-#define DUK_BIDX_ERROR_PROTOTYPE 19
-#define DUK_BIDX_EVAL_ERROR_CONSTRUCTOR 20
-#define DUK_BIDX_EVAL_ERROR_PROTOTYPE 21
-#define DUK_BIDX_RANGE_ERROR_CONSTRUCTOR 22
-#define DUK_BIDX_RANGE_ERROR_PROTOTYPE 23
-#define DUK_BIDX_REFERENCE_ERROR_CONSTRUCTOR 24
-#define DUK_BIDX_REFERENCE_ERROR_PROTOTYPE 25
-#define DUK_BIDX_SYNTAX_ERROR_CONSTRUCTOR 26
-#define DUK_BIDX_SYNTAX_ERROR_PROTOTYPE 27
-#define DUK_BIDX_TYPE_ERROR_CONSTRUCTOR 28
-#define DUK_BIDX_TYPE_ERROR_PROTOTYPE 29
-#define DUK_BIDX_URI_ERROR_CONSTRUCTOR 30
-#define DUK_BIDX_URI_ERROR_PROTOTYPE 31
-#define DUK_BIDX_MATH 32
-#define DUK_BIDX_JSON 33
-#define DUK_BIDX_TYPE_ERROR_THROWER 34
-#define DUK_BIDX_DUKTAPE 35
-#define DUK_BIDX_THREAD_CONSTRUCTOR 36
-#define DUK_BIDX_THREAD_PROTOTYPE 37
-#define DUK_BIDX_POINTER_CONSTRUCTOR 38
-#define DUK_BIDX_POINTER_PROTOTYPE 39
-#define DUK_BIDX_DOUBLE_ERROR 40
-#define DUK_BIDX_PROXY_CONSTRUCTOR 41
-#define DUK_BIDX_REFLECT 42
-#define DUK_BIDX_SYMBOL_PROTOTYPE 43
-#define DUK_BIDX_ARRAYBUFFER_CONSTRUCTOR 44
-#define DUK_BIDX_ARRAYBUFFER_PROTOTYPE 45
-#define DUK_BIDX_DATAVIEW_CONSTRUCTOR 46
-#define DUK_BIDX_DATAVIEW_PROTOTYPE 47
-#define DUK_BIDX_TYPEDARRAY_CONSTRUCTOR 48
-#define DUK_BIDX_TYPEDARRAY_PROTOTYPE 49
-#define DUK_BIDX_INT8ARRAY_CONSTRUCTOR 50
-#define DUK_BIDX_INT8ARRAY_PROTOTYPE 51
-#define DUK_BIDX_UINT8ARRAY_CONSTRUCTOR 52
-#define DUK_BIDX_UINT8ARRAY_PROTOTYPE 53
-#define DUK_BIDX_UINT8CLAMPEDARRAY_CONSTRUCTOR 54
-#define DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE 55
-#define DUK_BIDX_INT16ARRAY_CONSTRUCTOR 56
-#define DUK_BIDX_INT16ARRAY_PROTOTYPE 57
-#define DUK_BIDX_UINT16ARRAY_CONSTRUCTOR 58
-#define DUK_BIDX_UINT16ARRAY_PROTOTYPE 59
-#define DUK_BIDX_INT32ARRAY_CONSTRUCTOR 60
-#define DUK_BIDX_INT32ARRAY_PROTOTYPE 61
-#define DUK_BIDX_UINT32ARRAY_CONSTRUCTOR 62
-#define DUK_BIDX_UINT32ARRAY_PROTOTYPE 63
-#define DUK_BIDX_FLOAT32ARRAY_CONSTRUCTOR 64
-#define DUK_BIDX_FLOAT32ARRAY_PROTOTYPE 65
-#define DUK_BIDX_FLOAT64ARRAY_CONSTRUCTOR 66
-#define DUK_BIDX_FLOAT64ARRAY_PROTOTYPE 67
-#define DUK_BIDX_NODEJS_BUFFER_CONSTRUCTOR 68
-#define DUK_BIDX_NODEJS_BUFFER_PROTOTYPE 69
-#define DUK_BIDX_TEXTENCODER_CONSTRUCTOR 70
-#define DUK_BIDX_TEXTENCODER_PROTOTYPE 71
-#define DUK_BIDX_TEXTDECODER_CONSTRUCTOR 72
-#define DUK_BIDX_TEXTDECODER_PROTOTYPE 73
-#define DUK_NUM_BUILTINS 74
-#define DUK_NUM_BIDX_BUILTINS 74
-#define DUK_NUM_ALL_BUILTINS 74
+#define DUK_BIDX_NATIVE_FUNCTION_PROTOTYPE 6
+#define DUK_BIDX_ARRAY_CONSTRUCTOR 7
+#define DUK_BIDX_ARRAY_PROTOTYPE 8
+#define DUK_BIDX_STRING_CONSTRUCTOR 9
+#define DUK_BIDX_STRING_PROTOTYPE 10
+#define DUK_BIDX_BOOLEAN_CONSTRUCTOR 11
+#define DUK_BIDX_BOOLEAN_PROTOTYPE 12
+#define DUK_BIDX_NUMBER_CONSTRUCTOR 13
+#define DUK_BIDX_NUMBER_PROTOTYPE 14
+#define DUK_BIDX_DATE_CONSTRUCTOR 15
+#define DUK_BIDX_DATE_PROTOTYPE 16
+#define DUK_BIDX_REGEXP_CONSTRUCTOR 17
+#define DUK_BIDX_REGEXP_PROTOTYPE 18
+#define DUK_BIDX_ERROR_CONSTRUCTOR 19
+#define DUK_BIDX_ERROR_PROTOTYPE 20
+#define DUK_BIDX_EVAL_ERROR_CONSTRUCTOR 21
+#define DUK_BIDX_EVAL_ERROR_PROTOTYPE 22
+#define DUK_BIDX_RANGE_ERROR_CONSTRUCTOR 23
+#define DUK_BIDX_RANGE_ERROR_PROTOTYPE 24
+#define DUK_BIDX_REFERENCE_ERROR_CONSTRUCTOR 25
+#define DUK_BIDX_REFERENCE_ERROR_PROTOTYPE 26
+#define DUK_BIDX_SYNTAX_ERROR_CONSTRUCTOR 27
+#define DUK_BIDX_SYNTAX_ERROR_PROTOTYPE 28
+#define DUK_BIDX_TYPE_ERROR_CONSTRUCTOR 29
+#define DUK_BIDX_TYPE_ERROR_PROTOTYPE 30
+#define DUK_BIDX_URI_ERROR_CONSTRUCTOR 31
+#define DUK_BIDX_URI_ERROR_PROTOTYPE 32
+#define DUK_BIDX_TYPE_ERROR_THROWER 33
+#define DUK_BIDX_DUKTAPE 34
+#define DUK_BIDX_THREAD_PROTOTYPE 35
+#define DUK_BIDX_POINTER_PROTOTYPE 36
+#define DUK_BIDX_DOUBLE_ERROR 37
+#define DUK_BIDX_SYMBOL_PROTOTYPE 38
+#define DUK_BIDX_ARRAYBUFFER_PROTOTYPE 39
+#define DUK_BIDX_DATAVIEW_PROTOTYPE 40
+#define DUK_BIDX_INT8ARRAY_PROTOTYPE 41
+#define DUK_BIDX_UINT8ARRAY_PROTOTYPE 42
+#define DUK_BIDX_UINT8CLAMPEDARRAY_PROTOTYPE 43
+#define DUK_BIDX_INT16ARRAY_PROTOTYPE 44
+#define DUK_BIDX_UINT16ARRAY_PROTOTYPE 45
+#define DUK_BIDX_INT32ARRAY_PROTOTYPE 46
+#define DUK_BIDX_UINT32ARRAY_PROTOTYPE 47
+#define DUK_BIDX_FLOAT32ARRAY_PROTOTYPE 48
+#define DUK_BIDX_FLOAT64ARRAY_PROTOTYPE 49
+#define DUK_BIDX_NODEJS_BUFFER_PROTOTYPE 50
+#define DUK_NUM_BUILTINS 51
+#define DUK_NUM_BIDX_BUILTINS 51
+#define DUK_NUM_ALL_BUILTINS 76
#if defined(DUK_USE_DOUBLE_LE)
#if !defined(DUK_SINGLE_FILE)
-DUK_INTERNAL_DECL const duk_uint8_t duk_builtins_data[3819];
+DUK_INTERNAL_DECL const duk_uint8_t duk_builtins_data[3972];
#endif /* !DUK_SINGLE_FILE */
-#define DUK_BUILTINS_DATA_LENGTH 3819
+#define DUK_BUILTINS_DATA_LENGTH 3972
#elif defined(DUK_USE_DOUBLE_BE)
#if !defined(DUK_SINGLE_FILE)
-DUK_INTERNAL_DECL const duk_uint8_t duk_builtins_data[3819];
+DUK_INTERNAL_DECL const duk_uint8_t duk_builtins_data[3972];
#endif /* !DUK_SINGLE_FILE */
-#define DUK_BUILTINS_DATA_LENGTH 3819
+#define DUK_BUILTINS_DATA_LENGTH 3972
#elif defined(DUK_USE_DOUBLE_ME)
#if !defined(DUK_SINGLE_FILE)
-DUK_INTERNAL_DECL const duk_uint8_t duk_builtins_data[3819];
+DUK_INTERNAL_DECL const duk_uint8_t duk_builtins_data[3972];
#endif /* !DUK_SINGLE_FILE */
-#define DUK_BUILTINS_DATA_LENGTH 3819
+#define DUK_BUILTINS_DATA_LENGTH 3972
#else
#error invalid endianness defines
#endif
@@ -2337,10 +2325,10 @@ struct duk_bitencoder_ctx {
/*
* Buffer writer (dynamic buffer only)
*
- * Helper for writing to a dynamic buffer with a concept of a "spare" area
+ * Helper for writing to a dynamic buffer with a concept of a "slack" area
* to reduce resizes. You can ensure there is enough space beforehand and
* then write for a while without further checks, relying on a stable data
- * pointer. Spare handling is automatic so call sites only indicate how
+ * pointer. Slack handling is automatic so call sites only indicate how
* much data they need right now.
*
* There are several ways to write using bufwriter. The best approach
@@ -2366,8 +2354,13 @@ struct duk_bufwriter_ctx {
duk_hbuffer_dynamic *buf;
};
-#define DUK_BW_SPARE_ADD 64
-#define DUK_BW_SPARE_SHIFT 4 /* 2^4 -> 1/16 = 6.25% spare */
+#if defined(DUK_USE_PREFER_SIZE)
+#define DUK_BW_SLACK_ADD 64
+#define DUK_BW_SLACK_SHIFT 4 /* 2^4 -> 1/16 = 6.25% slack */
+#else
+#define DUK_BW_SLACK_ADD 64
+#define DUK_BW_SLACK_SHIFT 2 /* 2^2 -> 1/4 = 25% slack */
+#endif
/* Initialization and finalization (compaction), converting to other types. */
@@ -2382,7 +2375,7 @@ struct duk_bufwriter_ctx {
duk_bw_compact((thr), (bw_ctx)); \
} while (0)
#define DUK_BW_PUSH_AS_STRING(thr,bw_ctx) do { \
- duk_push_lstring((duk_context *) (thr), \
+ duk_push_lstring((thr), \
(const char *) (bw_ctx)->p_base, \
(duk_size_t) ((bw_ctx)->p - (bw_ctx)->p_base)); \
} while (0)
@@ -2465,7 +2458,7 @@ struct duk_bufwriter_ctx {
duk_bw_compact((thr), (bw_ctx)); \
} while (0)
-/* Fast write calls which assume you control the spare beforehand.
+/* Fast write calls which assume you control the slack beforehand.
* Multibyte write variants exist and use a temporary write pointer
* because byte writes alias with anything: with a stored pointer
* explicit pointer load/stores get generated (e.g. gcc -Os).
@@ -2528,7 +2521,7 @@ struct duk_bufwriter_ctx {
#define DUK_BW_WRITE_RAW_XUTF8(thr,bw_ctx,cp) do { \
duk_ucodepoint_t duk__cp; \
duk_small_int_t duk__enc_len; \
- duk__cp = (cp); \
+ duk__cp = (duk_ucodepoint_t) (cp); \
DUK_BW_ASSERT_SPACE((thr), (bw_ctx), duk_unicode_get_xutf8_length(duk__cp)); \
duk__enc_len = duk_unicode_encode_xutf8(duk__cp, (bw_ctx)->p); \
(bw_ctx)->p += duk__enc_len; \
@@ -2854,10 +2847,17 @@ DUK_INTERNAL_DECL duk_double_t duk_double_fmax(duk_double_t x, duk_double_t y);
#define DUK_STR_BUFFER_TOO_LONG "buffer too long"
#define DUK_STR_ALLOC_FAILED "alloc failed"
#define DUK_STR_WRONG_BUFFER_TYPE "wrong buffer type"
-#define DUK_STR_ENCODE_FAILED "encode failed"
-#define DUK_STR_DECODE_FAILED "decode failed"
+#define DUK_STR_BASE64_ENCODE_FAILED "base64 encode failed"
+#define DUK_STR_SOURCE_DECODE_FAILED "source decode failed"
+#define DUK_STR_UTF8_DECODE_FAILED "utf-8 decode failed"
+#define DUK_STR_BASE64_DECODE_FAILED "base64 decode failed"
+#define DUK_STR_HEX_DECODE_FAILED "hex decode failed"
+#define DUK_STR_INVALID_BYTECODE "invalid bytecode"
#define DUK_STR_NO_SOURCECODE "no sourcecode"
#define DUK_STR_RESULT_TOO_LONG "result too long"
+#define DUK_STR_INVALID_CFUNC_RC "invalid C function rc"
+#define DUK_STR_INVALID_INSTANCEOF_RVAL "invalid instanceof rval"
+#define DUK_STR_INVALID_INSTANCEOF_RVAL_NOPROTO "instanceof rval has no .prototype"
/* JSON */
#define DUK_STR_FMT_PTR "%p"
@@ -2867,7 +2867,6 @@ DUK_INTERNAL_DECL duk_double_t duk_double_fmax(duk_double_t x, duk_double_t y);
#define DUK_STR_CYCLIC_INPUT "cyclic input"
/* Object property access */
-#define DUK_STR_PROXY_REVOKED "proxy revoked"
#define DUK_STR_INVALID_BASE "invalid base value"
#define DUK_STR_STRICT_CALLER_READ "cannot read strict 'caller'"
#define DUK_STR_PROXY_REJECTED "proxy rejected"
@@ -2876,6 +2875,7 @@ DUK_INTERNAL_DECL duk_double_t duk_double_fmax(duk_double_t x, duk_double_t y);
#define DUK_STR_INVALID_DESCRIPTOR "invalid descriptor"
/* Proxy */
+#define DUK_STR_PROXY_REVOKED "proxy revoked"
#define DUK_STR_INVALID_TRAP_RESULT "invalid trap result"
/* Variables */
@@ -2900,6 +2900,7 @@ DUK_INTERNAL_DECL duk_double_t duk_double_fmax(duk_double_t x, duk_double_t y);
#define DUK_STR_CANNOT_DELETE_IDENTIFIER "cannot delete identifier"
#define DUK_STR_INVALID_EXPRESSION "invalid expression"
#define DUK_STR_INVALID_LVALUE "invalid lvalue"
+#define DUK_STR_INVALID_NEWTARGET "invalid new.target"
#define DUK_STR_EXPECTED_IDENTIFIER "expected identifier"
#define DUK_STR_EMPTY_EXPR_NOT_ALLOWED "empty expression not allowed"
#define DUK_STR_INVALID_FOR "invalid for statement"
@@ -2916,7 +2917,7 @@ DUK_INTERNAL_DECL duk_double_t duk_double_fmax(duk_double_t x, duk_double_t y);
#define DUK_STR_INVALID_GETSET_NAME "invalid getter/setter name"
#define DUK_STR_FUNC_NAME_REQUIRED "function name required"
-/* Regexp */
+/* RegExp */
#define DUK_STR_INVALID_QUANTIFIER "invalid regexp quantifier"
#define DUK_STR_INVALID_QUANTIFIER_NO_ATOM "quantifier without preceding atom"
#define DUK_STR_INVALID_QUANTIFIER_VALUES "quantifier values invalid (qmin > qmax)"
@@ -2935,7 +2936,6 @@ DUK_INTERNAL_DECL duk_double_t duk_double_fmax(duk_double_t x, duk_double_t y);
/* Limits */
#define DUK_STR_VALSTACK_LIMIT "valstack limit"
#define DUK_STR_CALLSTACK_LIMIT "callstack limit"
-#define DUK_STR_CATCHSTACK_LIMIT "catchstack limit"
#define DUK_STR_PROTOTYPE_CHAIN_LIMIT "prototype chain limit"
#define DUK_STR_BOUND_CHAIN_LIMIT "function call bound chain limit"
#define DUK_STR_C_CALLSTACK_LIMIT "C call stack depth limit"
@@ -3114,20 +3114,20 @@ typedef duk_uint32_t duk_instr_t;
/* Opcodes. */
#define DUK_OP_LDREG 0
#define DUK_OP_STREG 1
-#define DUK_OP_LDCONST 2
-#define DUK_OP_LDINT 3
-#define DUK_OP_LDINTX 4
-#define DUK_OP_LDTHIS 5
-#define DUK_OP_LDUNDEF 6
-#define DUK_OP_LDNULL 7
-#define DUK_OP_LDTRUE 8
-#define DUK_OP_LDFALSE 9
-#define DUK_OP_BNOT 10
-#define DUK_OP_LNOT 11
-#define DUK_OP_UNM 12
-#define DUK_OP_UNP 13
-#define DUK_OP_TYPEOF 14
-#define DUK_OP_TYPEOFID 15
+#define DUK_OP_JUMP 2
+#define DUK_OP_LDCONST 3
+#define DUK_OP_LDINT 4
+#define DUK_OP_LDINTX 5
+#define DUK_OP_LDTHIS 6
+#define DUK_OP_LDUNDEF 7
+#define DUK_OP_LDNULL 8
+#define DUK_OP_LDTRUE 9
+#define DUK_OP_LDFALSE 10
+#define DUK_OP_GETVAR 11
+#define DUK_OP_BNOT 12
+#define DUK_OP_LNOT 13
+#define DUK_OP_UNM 14
+#define DUK_OP_UNP 15
#define DUK_OP_EQ 16
#define DUK_OP_EQ_RR 16
#define DUK_OP_EQ_CR 17
@@ -3297,67 +3297,68 @@ typedef duk_uint32_t duk_instr_t;
#define DUK_OP_REGEXP_CR 149
#define DUK_OP_REGEXP_RC 150
#define DUK_OP_REGEXP_CC 151
-#define DUK_OP_CSVAR 152
-#define DUK_OP_CSVAR_RR 152
-#define DUK_OP_CSVAR_CR 153
-#define DUK_OP_CSVAR_RC 154
-#define DUK_OP_CSVAR_CC 155
-#define DUK_OP_CLOSURE 156
-#define DUK_OP_GETVAR 157
-#define DUK_OP_PUTVAR 158
-#define DUK_OP_DELVAR 159
-#define DUK_OP_JUMP 160
-#define DUK_OP_RETREG 161
-#define DUK_OP_RETUNDEF 162
-#define DUK_OP_RETCONST 163
-#define DUK_OP_RETCONSTN 164 /* return const without incref (e.g. number) */
-#define DUK_OP_LABEL 165
-#define DUK_OP_ENDLABEL 166
-#define DUK_OP_BREAK 167
-#define DUK_OP_CONTINUE 168
-#define DUK_OP_TRYCATCH 169
-#define DUK_OP_ENDTRY 170
-#define DUK_OP_ENDCATCH 171
-#define DUK_OP_ENDFIN 172
-#define DUK_OP_THROW 173
-#define DUK_OP_CSREG 174
-#define DUK_OP_EVALCALL 175
-#define DUK_OP_CALL 176 /* must be even */
-#define DUK_OP_TAILCALL 177 /* must be odd */
-#define DUK_OP_NEW 178
-#define DUK_OP_NEWOBJ 179
-#define DUK_OP_NEWARR 180
-#define DUK_OP_MPUTOBJ 181
-#define DUK_OP_MPUTOBJI 182
-#define DUK_OP_INITSET 183
-#define DUK_OP_INITGET 184
-#define DUK_OP_MPUTARR 185
-#define DUK_OP_MPUTARRI 186
-#define DUK_OP_SETALEN 187
-#define DUK_OP_INITENUM 188
-#define DUK_OP_NEXTENUM 189
-#define DUK_OP_INVLHS 190
-#define DUK_OP_DEBUGGER 191
-#define DUK_OP_NOP 192
-#define DUK_OP_INVALID 193
-#define DUK_OP_UNUSED194 194
-#define DUK_OP_UNUSED195 195
-#define DUK_OP_UNUSED196 196
-#define DUK_OP_UNUSED197 197
-#define DUK_OP_UNUSED198 198
-#define DUK_OP_UNUSED199 199
-#define DUK_OP_UNUSED200 200
-#define DUK_OP_UNUSED201 201
-#define DUK_OP_UNUSED202 202
-#define DUK_OP_UNUSED203 203
-#define DUK_OP_UNUSED204 204
-#define DUK_OP_UNUSED205 205
-#define DUK_OP_UNUSED206 206
+#define DUK_OP_CLOSURE 152
+#define DUK_OP_TYPEOF 153
+#define DUK_OP_TYPEOFID 154
+#define DUK_OP_PUTVAR 155
+#define DUK_OP_DELVAR 156
+#define DUK_OP_RETREG 157
+#define DUK_OP_RETUNDEF 158
+#define DUK_OP_RETCONST 159
+#define DUK_OP_RETCONSTN 160 /* return const without incref (e.g. number) */
+#define DUK_OP_LABEL 161
+#define DUK_OP_ENDLABEL 162
+#define DUK_OP_BREAK 163
+#define DUK_OP_CONTINUE 164
+#define DUK_OP_TRYCATCH 165
+#define DUK_OP_ENDTRY 166
+#define DUK_OP_ENDCATCH 167
+#define DUK_OP_ENDFIN 168
+#define DUK_OP_THROW 169
+#define DUK_OP_INVLHS 170
+#define DUK_OP_CSREG 171
+#define DUK_OP_CSVAR 172
+#define DUK_OP_CSVAR_RR 172
+#define DUK_OP_CSVAR_CR 173
+#define DUK_OP_CSVAR_RC 174
+#define DUK_OP_CSVAR_CC 175
+#define DUK_OP_CALL0 176 /* DUK_OP_CALL0 & 0x0F must be zero. */
+#define DUK_OP_CALL1 177
+#define DUK_OP_CALL2 178
+#define DUK_OP_CALL3 179
+#define DUK_OP_CALL4 180
+#define DUK_OP_CALL5 181
+#define DUK_OP_CALL6 182
+#define DUK_OP_CALL7 183
+#define DUK_OP_CALL8 184
+#define DUK_OP_CALL9 185
+#define DUK_OP_CALL10 186
+#define DUK_OP_CALL11 187
+#define DUK_OP_CALL12 188
+#define DUK_OP_CALL13 189
+#define DUK_OP_CALL14 190
+#define DUK_OP_CALL15 191
+#define DUK_OP_NEWOBJ 192
+#define DUK_OP_NEWARR 193
+#define DUK_OP_MPUTOBJ 194
+#define DUK_OP_MPUTOBJI 195
+#define DUK_OP_INITSET 196
+#define DUK_OP_INITGET 197
+#define DUK_OP_MPUTARR 198
+#define DUK_OP_MPUTARRI 199
+#define DUK_OP_SETALEN 200
+#define DUK_OP_INITENUM 201
+#define DUK_OP_NEXTENUM 202
+#define DUK_OP_NEWTARGET 203
+#define DUK_OP_DEBUGGER 204
+#define DUK_OP_NOP 205
+#define DUK_OP_INVALID 206
#define DUK_OP_UNUSED207 207
-#define DUK_OP_UNUSED208 208
-#define DUK_OP_UNUSED209 209
-#define DUK_OP_UNUSED210 210
-#define DUK_OP_UNUSED211 211
+#define DUK_OP_GETPROPC 208
+#define DUK_OP_GETPROPC_RR 208
+#define DUK_OP_GETPROPC_CR 209
+#define DUK_OP_GETPROPC_RC 210
+#define DUK_OP_GETPROPC_CC 211
#define DUK_OP_UNUSED212 212
#define DUK_OP_UNUSED213 213
#define DUK_OP_UNUSED214 214
@@ -3407,14 +3408,24 @@ typedef duk_uint32_t duk_instr_t;
/* XXX: Allocate flags from opcode field? Would take 16 opcode slots
* but avoids shuffling in more cases. Maybe not worth it.
*/
-/* DUK_OP_TRYCATCH flags in A */
-#define DUK_BC_TRYCATCH_FLAG_HAVE_CATCH (1 << 0)
-#define DUK_BC_TRYCATCH_FLAG_HAVE_FINALLY (1 << 1)
-#define DUK_BC_TRYCATCH_FLAG_CATCH_BINDING (1 << 2)
-#define DUK_BC_TRYCATCH_FLAG_WITH_BINDING (1 << 3)
+/* DUK_OP_TRYCATCH flags in A. */
+#define DUK_BC_TRYCATCH_FLAG_HAVE_CATCH (1U << 0)
+#define DUK_BC_TRYCATCH_FLAG_HAVE_FINALLY (1U << 1)
+#define DUK_BC_TRYCATCH_FLAG_CATCH_BINDING (1U << 2)
+#define DUK_BC_TRYCATCH_FLAG_WITH_BINDING (1U << 3)
+
+/* DUK_OP_DECLVAR flags in A; bottom bits are reserved for propdesc flags
+ * (DUK_PROPDESC_FLAG_XXX).
+ */
+#define DUK_BC_DECLVAR_FLAG_FUNC_DECL (1U << 4) /* function declaration */
-/* DUK_OP_DECLVAR flags in A; bottom bits are reserved for propdesc flags (DUK_PROPDESC_FLAG_XXX) */
-#define DUK_BC_DECLVAR_FLAG_FUNC_DECL (1 << 4) /* function declaration */
+/* DUK_OP_CALLn flags, part of opcode field. Three lowest bits must match
+ * DUK_CALL_FLAG_xxx directly.
+ */
+#define DUK_BC_CALL_FLAG_TAILCALL (1U << 0)
+#define DUK_BC_CALL_FLAG_CONSTRUCT (1U << 1)
+#define DUK_BC_CALL_FLAG_CALLED_AS_EVAL (1U << 2)
+#define DUK_BC_CALL_FLAG_INDIRECT (1U << 3)
/* Misc constants and helper macros. */
#define DUK_BC_LDINT_BIAS (1L << 15)
@@ -3597,6 +3608,8 @@ typedef void (*duk_re_range_callback)(void *user, duk_codepoint_t r1, duk_codepo
#define DUK_TOK_MAXVAL 101 /* inclusive */
+#define DUK_TOK_INVALID DUK_SMALL_UINT_MAX
+
/* Convert heap string index to a token (reserved words) */
#define DUK_STRIDX_TO_TOK(x) ((x) - DUK_STRIDX_START_RESERVED + DUK_TOK_START_RESERVED)
@@ -3775,8 +3788,8 @@ typedef void (*duk_re_range_callback)(void *user, duk_codepoint_t r1, duk_codepo
* stale values otherwise.
*/
struct duk_token {
- duk_small_int_t t; /* token type (with reserved word identification) */
- duk_small_int_t t_nores; /* token type (with reserved words as DUK_TOK_IDENTIFER) */
+ duk_small_uint_t t; /* token type (with reserved word identification) */
+ duk_small_uint_t t_nores; /* token type (with reserved words as DUK_TOK_IDENTIFER) */
duk_double_t num; /* numeric value of token */
duk_hstring *str1; /* string 1 of token (borrowed, stored to ctx->slot1_idx) */
duk_hstring *str2; /* string 2 of token (borrowed, stored to ctx->slot2_idx) */
@@ -3791,11 +3804,11 @@ struct duk_token {
/* A regexp token value. */
struct duk_re_token {
- duk_small_int_t t; /* token type */
- duk_small_int_t greedy;
- duk_uint_fast32_t num; /* numeric value (character, count) */
- duk_uint_fast32_t qmin;
- duk_uint_fast32_t qmax;
+ duk_small_uint_t t; /* token type */
+ duk_small_uint_t greedy;
+ duk_uint32_t num; /* numeric value (character, count) */
+ duk_uint32_t qmin;
+ duk_uint32_t qmax;
};
/* A structure for 'snapshotting' a point for rewinding */
@@ -3898,13 +3911,12 @@ DUK_INTERNAL_DECL void duk_lexer_parse_re_ranges(duk_lexer_ctx *lex_ctx, duk_re_
* Chosen so that when a regconst is cast to duk_int32_t, all consts are
* negative values.
*/
-#define DUK_REGCONST_CONST_MARKER 0x80000000UL
-
-/* type to represent a reg/const reference during compilation */
-typedef duk_uint32_t duk_regconst_t;
+#define DUK_REGCONST_CONST_MARKER DUK_INT32_MIN /* = -0x80000000 */
-/* type to represent a straight register reference, with <0 indicating none */
-typedef duk_int32_t duk_reg_t;
+/* Type to represent a reg/const reference during compilation, with <0
+ * indicating a constant. Some call sites also use -1 to indicate 'none'.
+ */
+typedef duk_int32_t duk_regconst_t;
typedef struct {
duk_small_uint_t t; /* DUK_ISPEC_XXX */
@@ -3944,8 +3956,8 @@ struct duk_compiler_instr {
* Compiler state
*/
-#define DUK_LABEL_FLAG_ALLOW_BREAK (1 << 0)
-#define DUK_LABEL_FLAG_ALLOW_CONTINUE (1 << 1)
+#define DUK_LABEL_FLAG_ALLOW_BREAK (1U << 0)
+#define DUK_LABEL_FLAG_ALLOW_CONTINUE (1U << 1)
#define DUK_DECL_TYPE_VAR 0
#define DUK_DECL_TYPE_FUNC 1
@@ -4003,14 +4015,14 @@ struct duk_compiler_func {
duk_idx_t varmap_idx;
/* Temp reg handling. */
- duk_reg_t temp_first; /* first register that is a temporary (below: variables) */
- duk_reg_t temp_next; /* next temporary register to allocate */
- duk_reg_t temp_max; /* highest value of temp_reg (temp_max - 1 is highest used reg) */
+ duk_regconst_t temp_first; /* first register that is a temporary (below: variables) */
+ duk_regconst_t temp_next; /* next temporary register to allocate */
+ duk_regconst_t temp_max; /* highest value of temp_reg (temp_max - 1 is highest used reg) */
/* Shuffle registers if large number of regs/consts. */
- duk_reg_t shuffle1;
- duk_reg_t shuffle2;
- duk_reg_t shuffle3;
+ duk_regconst_t shuffle1;
+ duk_regconst_t shuffle2;
+ duk_regconst_t shuffle3;
/* Stats for current expression being parsed. */
duk_int_t nud_count;
@@ -4026,7 +4038,7 @@ struct duk_compiler_func {
duk_int_t with_depth; /* with stack depth (affects identifier lookups) */
duk_int_t fnum_next; /* inner function numbering */
duk_int_t num_formals; /* number of formal arguments */
- duk_reg_t reg_stmt_value; /* register for writing value of 'non-empty' statements (global or eval code), -1 is marker */
+ duk_regconst_t reg_stmt_value; /* register for writing value of 'non-empty' statements (global or eval code), -1 is marker */
#if defined(DUK_USE_DEBUGGER_SUPPORT)
duk_int_t min_line; /* XXX: typing (duk_hcompfunc has duk_uint32_t) */
duk_int_t max_line;
@@ -4126,9 +4138,9 @@ DUK_INTERNAL_DECL void duk_js_compile(duk_hthread *thr, const duk_uint8_t *src_b
#define DUK_REOP_ASSERT_NOT_WORD_BOUNDARY 19
/* flags */
-#define DUK_RE_FLAG_GLOBAL (1 << 0)
-#define DUK_RE_FLAG_IGNORE_CASE (1 << 1)
-#define DUK_RE_FLAG_MULTILINE (1 << 2)
+#define DUK_RE_FLAG_GLOBAL (1U << 0)
+#define DUK_RE_FLAG_IGNORE_CASE (1U << 1)
+#define DUK_RE_FLAG_MULTILINE (1U << 2)
struct duk_re_matcher_ctx {
duk_hthread *thr;
@@ -4207,6 +4219,9 @@ DUK_INTERNAL_DECL void duk_regexp_match_force_global(duk_hthread *thr); /* hack
/* XXX: macro for shared header fields (avoids some padding issues) */
+#if (DUK_USE_ALIGN_BY == 8) && defined(DUK_USE_PACK_MSVC_PRAGMA)
+#pragma pack(push, 8)
+#endif
struct duk_heaphdr {
duk_uint32_t h_flags;
@@ -4252,7 +4267,16 @@ struct duk_heaphdr {
#if defined(DUK_USE_HEAPPTR16)
duk_uint16_t h_extra16;
#endif
-};
+}
+#if (DUK_USE_ALIGN_BY == 8) && defined(DUK_USE_PACK_GCC_ATTR)
+__attribute__ ((aligned (8)))
+#elif (DUK_USE_ALIGN_BY == 8) && defined(DUK_USE_PACK_CLANG_ATTR)
+__attribute__ ((aligned (8)))
+#endif
+;
+#if (DUK_USE_ALIGN_BY == 8) && defined(DUK_USE_PACK_MSVC_PRAGMA)
+#pragma pack(pop)
+#endif
struct duk_heaphdr_string {
/* 16 bits would be enough for shared heaphdr flags and duk_hstring
@@ -5142,6 +5166,33 @@ struct duk_heaphdr_string {
#endif /* DUK_USE_REFERENCE_COUNTING */
+/*
+ * Some convenience macros that don't have optimized implementations now.
+ */
+
+#define DUK_TVAL_SET_TVAL_UPDREF_NORZ(thr,tv_dst,tv_src) do { \
+ duk_hthread *duk__thr = (thr); \
+ duk_tval *duk__dst = (tv_dst); \
+ duk_tval *duk__src = (tv_src); \
+ DUK_UNREF(duk__thr); \
+ DUK_TVAL_DECREF_NORZ(thr, duk__dst); \
+ DUK_TVAL_SET_TVAL(duk__dst, duk__src); \
+ DUK_TVAL_INCREF(thr, duk__dst); \
+ } while (0)
+
+#define DUK_TVAL_SET_U32_UPDREF_NORZ(thr,tv_dst,val) do { \
+ duk_hthread *duk__thr = (thr); \
+ duk_tval *duk__dst = (tv_dst); \
+ duk_uint32_t duk__val = (duk_uint32_t) (val); \
+ DUK_UNREF(duk__thr); \
+ DUK_TVAL_DECREF_NORZ(thr, duk__dst); \
+ DUK_TVAL_SET_U32(duk__dst, duk__val); \
+ } while (0)
+
+/*
+ * Prototypes
+ */
+
#if defined(DUK_USE_REFERENCE_COUNTING)
#if defined(DUK_USE_FINALIZER_SUPPORT)
DUK_INTERNAL_DECL void duk_refzero_check_slow(duk_hthread *thr);
@@ -5186,6 +5237,8 @@ DUK_INTERNAL_DECL void duk_heaphdr_decref_norz(duk_hthread *thr, duk_heaphdr *h)
#if !defined(DUK_API_INTERNAL_H_INCLUDED)
#define DUK_API_INTERNAL_H_INCLUDED
+#define DUK_INTERNAL_SYMBOL(x) ("\x82" x)
+
/* duk_push_sprintf constants */
#define DUK_PUSH_SPRINTF_INITIAL_SIZE 256L
#define DUK_PUSH_SPRINTF_SANITY_LIMIT (1L * 1024L * 1024L * 1024L)
@@ -5195,186 +5248,197 @@ DUK_INTERNAL_DECL void duk_heaphdr_decref_norz(duk_hthread *thr, duk_heaphdr *h)
*/
#define DUK_ERRCODE_FLAG_NOBLAME_FILELINE (1L << 24)
-/* Valstack resize flags */
-#define DUK_VSRESIZE_FLAG_SHRINK (1 << 0)
-#define DUK_VSRESIZE_FLAG_COMPACT (1 << 1)
-#define DUK_VSRESIZE_FLAG_THROW (1 << 2)
-
/* Current convention is to use duk_size_t for value stack sizes and global indices,
* and duk_idx_t for local frame indices.
*/
-DUK_INTERNAL_DECL
-duk_bool_t duk_valstack_resize_raw(duk_context *ctx,
- duk_size_t min_new_size,
- duk_small_uint_t flags);
+DUK_INTERNAL_DECL DUK_INLINE void duk_valstack_grow_check_throw(duk_hthread *thr, duk_size_t min_bytes);
+DUK_INTERNAL_DECL DUK_INLINE duk_bool_t duk_valstack_grow_check_nothrow(duk_hthread *thr, duk_size_t min_bytes);
+DUK_INTERNAL_DECL void duk_valstack_shrink_check_nothrow(duk_hthread *thr, duk_bool_t snug);
+
+DUK_INTERNAL_DECL void duk_copy_tvals_incref(duk_hthread *thr, duk_tval *tv_dst, duk_tval *tv_src, duk_size_t count);
+
+DUK_INTERNAL_DECL duk_tval *duk_reserve_gap(duk_hthread *thr, duk_idx_t idx_base, duk_idx_t count);
-DUK_INTERNAL_DECL void duk_dup_0(duk_context *ctx);
-DUK_INTERNAL_DECL void duk_dup_1(duk_context *ctx);
-DUK_INTERNAL_DECL void duk_dup_2(duk_context *ctx);
+DUK_INTERNAL_DECL void duk_set_top_unsafe(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL void duk_set_top_and_wipe(duk_hthread *thr, duk_idx_t top, duk_idx_t idx_wipe_start);
+
+DUK_INTERNAL_DECL void duk_dup_0(duk_hthread *thr);
+DUK_INTERNAL_DECL void duk_dup_1(duk_hthread *thr);
+DUK_INTERNAL_DECL void duk_dup_2(duk_hthread *thr);
/* duk_dup_m1() would be same as duk_dup_top() */
-DUK_INTERNAL_DECL void duk_dup_m2(duk_context *ctx);
-DUK_INTERNAL_DECL void duk_dup_m3(duk_context *ctx);
-DUK_INTERNAL_DECL void duk_dup_m4(duk_context *ctx);
+DUK_INTERNAL_DECL void duk_dup_m2(duk_hthread *thr);
+DUK_INTERNAL_DECL void duk_dup_m3(duk_hthread *thr);
+DUK_INTERNAL_DECL void duk_dup_m4(duk_hthread *thr);
-DUK_INTERNAL_DECL void duk_remove_m2(duk_context *ctx);
+DUK_INTERNAL_DECL void duk_remove_unsafe(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL void duk_remove_m2(duk_hthread *thr);
+DUK_INTERNAL_DECL void duk_remove_n(duk_hthread *thr, duk_idx_t idx, duk_idx_t count);
+DUK_INTERNAL_DECL void duk_remove_n_unsafe(duk_hthread *thr, duk_idx_t idx, duk_idx_t count);
DUK_INTERNAL_DECL duk_int_t duk_get_type_tval(duk_tval *tv);
DUK_INTERNAL_DECL duk_uint_t duk_get_type_mask_tval(duk_tval *tv);
#if defined(DUK_USE_VERBOSE_ERRORS) && defined(DUK_USE_PARANOID_ERRORS)
-DUK_INTERNAL_DECL const char *duk_get_type_name(duk_context *ctx, duk_idx_t idx);
+DUK_INTERNAL_DECL const char *duk_get_type_name(duk_hthread *thr, duk_idx_t idx);
#endif
-DUK_INTERNAL_DECL duk_small_uint_t duk_get_class_number(duk_context *ctx, duk_idx_t idx);
+DUK_INTERNAL_DECL duk_small_uint_t duk_get_class_number(duk_hthread *thr, duk_idx_t idx);
-DUK_INTERNAL_DECL duk_tval *duk_get_tval(duk_context *ctx, duk_idx_t idx);
-DUK_INTERNAL_DECL duk_tval *duk_get_tval_or_unused(duk_context *ctx, duk_idx_t idx);
-DUK_INTERNAL_DECL duk_tval *duk_require_tval(duk_context *ctx, duk_idx_t idx);
-DUK_INTERNAL_DECL void duk_push_tval(duk_context *ctx, duk_tval *tv);
+DUK_INTERNAL_DECL duk_tval *duk_get_tval(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL duk_tval *duk_get_tval_or_unused(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL duk_tval *duk_require_tval(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL void duk_push_tval(duk_hthread *thr, duk_tval *tv);
/* Push the current 'this' binding; throw TypeError if binding is not object
* coercible (CheckObjectCoercible).
*/
-DUK_INTERNAL_DECL void duk_push_this_check_object_coercible(duk_context *ctx);
+DUK_INTERNAL_DECL void duk_push_this_check_object_coercible(duk_hthread *thr);
/* duk_push_this() + CheckObjectCoercible() + duk_to_object() */
-DUK_INTERNAL_DECL duk_hobject *duk_push_this_coercible_to_object(duk_context *ctx);
+DUK_INTERNAL_DECL duk_hobject *duk_push_this_coercible_to_object(duk_hthread *thr);
/* duk_push_this() + CheckObjectCoercible() + duk_to_string() */
-DUK_INTERNAL_DECL duk_hstring *duk_push_this_coercible_to_string(duk_context *ctx);
+DUK_INTERNAL_DECL duk_hstring *duk_push_this_coercible_to_string(duk_hthread *thr);
-DUK_INTERNAL_DECL duk_hstring *duk_push_uint_to_hstring(duk_context *ctx, duk_uint_t i);
+DUK_INTERNAL_DECL duk_hstring *duk_push_uint_to_hstring(duk_hthread *thr, duk_uint_t i);
/* Get a borrowed duk_tval pointer to the current 'this' binding. Caller must
* make sure there's an active callstack entry. Note that the returned pointer
* is unstable with regards to side effects.
*/
-DUK_INTERNAL_DECL duk_tval *duk_get_borrowed_this_tval(duk_context *ctx);
+DUK_INTERNAL_DECL duk_tval *duk_get_borrowed_this_tval(duk_hthread *thr);
/* XXX: add fastint support? */
-#define duk_push_u64(ctx,val) \
- duk_push_number((ctx), (duk_double_t) (val))
-#define duk_push_i64(ctx,val) \
- duk_push_number((ctx), (duk_double_t) (val))
+#define duk_push_u64(thr,val) \
+ duk_push_number((thr), (duk_double_t) (val))
+#define duk_push_i64(thr,val) \
+ duk_push_number((thr), (duk_double_t) (val))
/* duk_push_(u)int() is guaranteed to support at least (un)signed 32-bit range */
-#define duk_push_u32(ctx,val) \
- duk_push_uint((ctx), (duk_uint_t) (val))
-#define duk_push_i32(ctx,val) \
- duk_push_int((ctx), (duk_int_t) (val))
+#define duk_push_u32(thr,val) \
+ duk_push_uint((thr), (duk_uint_t) (val))
+#define duk_push_i32(thr,val) \
+ duk_push_int((thr), (duk_int_t) (val))
/* sometimes stack and array indices need to go on the stack */
-#define duk_push_idx(ctx,val) \
- duk_push_int((ctx), (duk_int_t) (val))
-#define duk_push_uarridx(ctx,val) \
- duk_push_uint((ctx), (duk_uint_t) (val))
-#define duk_push_size_t(ctx,val) \
- duk_push_uint((ctx), (duk_uint_t) (val)) /* XXX: assumed to fit for now */
-
-DUK_INTERNAL_DECL duk_bool_t duk_is_string_notsymbol(duk_context *ctx, duk_idx_t idx);
-
-DUK_INTERNAL_DECL duk_hstring *duk_get_hstring(duk_context *ctx, duk_idx_t idx);
-DUK_INTERNAL_DECL duk_hstring *duk_get_hstring_notsymbol(duk_context *ctx, duk_idx_t idx);
-DUK_INTERNAL_DECL const char *duk_get_string_notsymbol(duk_context *ctx, duk_idx_t idx);
-DUK_INTERNAL_DECL duk_hobject *duk_get_hobject(duk_context *ctx, duk_idx_t idx);
-DUK_INTERNAL_DECL duk_hbuffer *duk_get_hbuffer(duk_context *ctx, duk_idx_t idx);
-DUK_INTERNAL_DECL duk_hthread *duk_get_hthread(duk_context *ctx, duk_idx_t idx);
-DUK_INTERNAL_DECL duk_hcompfunc *duk_get_hcompfunc(duk_context *ctx, duk_idx_t idx);
-DUK_INTERNAL_DECL duk_hnatfunc *duk_get_hnatfunc(duk_context *ctx, duk_idx_t idx);
-
-DUK_INTERNAL_DECL void *duk_get_buffer_data_raw(duk_context *ctx, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_len, duk_bool_t throw_flag, duk_bool_t *out_isbuffer);
-
-DUK_INTERNAL_DECL duk_hobject *duk_get_hobject_with_class(duk_context *ctx, duk_idx_t idx, duk_small_uint_t classnum);
-
-DUK_INTERNAL_DECL duk_hobject *duk_get_hobject_promote_mask(duk_context *ctx, duk_idx_t idx, duk_uint_t type_mask);
-DUK_INTERNAL_DECL duk_hobject *duk_require_hobject_promote_mask(duk_context *ctx, duk_idx_t idx, duk_uint_t type_mask);
-DUK_INTERNAL_DECL duk_hobject *duk_require_hobject_accept_mask(duk_context *ctx, duk_idx_t idx, duk_uint_t type_mask);
-#define duk_require_hobject_promote_lfunc(ctx,idx) \
- duk_require_hobject_promote_mask((ctx), (idx), DUK_TYPE_MASK_LIGHTFUNC)
-#define duk_get_hobject_promote_lfunc(ctx,idx) \
- duk_get_hobject_promote_mask((ctx), (idx), DUK_TYPE_MASK_LIGHTFUNC)
+#define duk_push_idx(thr,val) \
+ duk_push_int((thr), (duk_int_t) (val))
+#define duk_push_uarridx(thr,val) \
+ duk_push_uint((thr), (duk_uint_t) (val))
+#define duk_push_size_t(thr,val) \
+ duk_push_uint((thr), (duk_uint_t) (val)) /* XXX: assumed to fit for now */
+
+DUK_INTERNAL_DECL duk_bool_t duk_is_string_notsymbol(duk_hthread *thr, duk_idx_t idx);
+
+DUK_INTERNAL_DECL duk_bool_t duk_is_callable_tval(duk_hthread *thr, duk_tval *tv);
+
+DUK_INTERNAL_DECL duk_hstring *duk_get_hstring(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL duk_hstring *duk_get_hstring_notsymbol(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL const char *duk_get_string_notsymbol(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL duk_hobject *duk_get_hobject(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL duk_hbuffer *duk_get_hbuffer(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL duk_hthread *duk_get_hthread(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL duk_hcompfunc *duk_get_hcompfunc(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL duk_hnatfunc *duk_get_hnatfunc(duk_hthread *thr, duk_idx_t idx);
+
+DUK_INTERNAL_DECL void *duk_get_buffer_data_raw(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_len, duk_bool_t throw_flag, duk_bool_t *out_isbuffer);
+
+DUK_INTERNAL_DECL duk_hobject *duk_get_hobject_with_class(duk_hthread *thr, duk_idx_t idx, duk_small_uint_t classnum);
+
+DUK_INTERNAL_DECL duk_hobject *duk_get_hobject_promote_mask(duk_hthread *thr, duk_idx_t idx, duk_uint_t type_mask);
+DUK_INTERNAL_DECL duk_hobject *duk_require_hobject_promote_mask(duk_hthread *thr, duk_idx_t idx, duk_uint_t type_mask);
+DUK_INTERNAL_DECL duk_hobject *duk_require_hobject_accept_mask(duk_hthread *thr, duk_idx_t idx, duk_uint_t type_mask);
+#define duk_require_hobject_promote_lfunc(thr,idx) \
+ duk_require_hobject_promote_mask((thr), (idx), DUK_TYPE_MASK_LIGHTFUNC)
+#define duk_get_hobject_promote_lfunc(thr,idx) \
+ duk_get_hobject_promote_mask((thr), (idx), DUK_TYPE_MASK_LIGHTFUNC)
#if 0 /*unused*/
-DUK_INTERNAL_DECL void *duk_get_voidptr(duk_context *ctx, duk_idx_t idx);
+DUK_INTERNAL_DECL void *duk_get_voidptr(duk_hthread *thr, duk_idx_t idx);
#endif
-DUK_INTERNAL_DECL duk_hstring *duk_known_hstring(duk_context *ctx, duk_idx_t idx);
-DUK_INTERNAL_DECL duk_hobject *duk_known_hobject(duk_context *ctx, duk_idx_t idx);
-DUK_INTERNAL_DECL duk_hbuffer *duk_known_hbuffer(duk_context *ctx, duk_idx_t idx);
-DUK_INTERNAL_DECL duk_hcompfunc *duk_known_hcompfunc(duk_context *ctx, duk_idx_t idx);
-DUK_INTERNAL_DECL duk_hnatfunc *duk_known_hnatfunc(duk_context *ctx, duk_idx_t idx);
+DUK_INTERNAL_DECL duk_hstring *duk_known_hstring(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL duk_hobject *duk_known_hobject(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL duk_hbuffer *duk_known_hbuffer(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL duk_hcompfunc *duk_known_hcompfunc(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL duk_hnatfunc *duk_known_hnatfunc(duk_hthread *thr, duk_idx_t idx);
-DUK_INTERNAL_DECL duk_double_t duk_to_number_tval(duk_context *ctx, duk_tval *tv);
+DUK_INTERNAL_DECL duk_double_t duk_to_number_tval(duk_hthread *thr, duk_tval *tv);
-DUK_INTERNAL_DECL duk_hstring *duk_to_hstring(duk_context *ctx, duk_idx_t idx);
-DUK_INTERNAL_DECL duk_hstring *duk_to_hstring_m1(duk_context *ctx);
-DUK_INTERNAL_DECL duk_hstring *duk_to_hstring_acceptsymbol(duk_context *ctx, duk_idx_t idx);
+DUK_INTERNAL_DECL duk_hstring *duk_to_hstring(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL duk_hstring *duk_to_hstring_m1(duk_hthread *thr);
+DUK_INTERNAL_DECL duk_hstring *duk_to_hstring_acceptsymbol(duk_hthread *thr, duk_idx_t idx);
-DUK_INTERNAL_DECL duk_hobject *duk_to_hobject(duk_context *ctx, duk_idx_t idx);
+DUK_INTERNAL_DECL duk_hobject *duk_to_hobject(duk_hthread *thr, duk_idx_t idx);
-DUK_INTERNAL_DECL duk_double_t duk_to_number_m1(duk_context *ctx);
-DUK_INTERNAL_DECL duk_double_t duk_to_number_m2(duk_context *ctx);
+DUK_INTERNAL_DECL duk_double_t duk_to_number_m1(duk_hthread *thr);
+DUK_INTERNAL_DECL duk_double_t duk_to_number_m2(duk_hthread *thr);
#if defined(DUK_USE_DEBUGGER_SUPPORT) /* only needed by debugger for now */
-DUK_INTERNAL_DECL duk_hstring *duk_safe_to_hstring(duk_context *ctx, duk_idx_t idx);
+DUK_INTERNAL_DECL duk_hstring *duk_safe_to_hstring(duk_hthread *thr, duk_idx_t idx);
#endif
-DUK_INTERNAL_DECL void duk_push_class_string_tval(duk_context *ctx, duk_tval *tv);
+DUK_INTERNAL_DECL void duk_push_class_string_tval(duk_hthread *thr, duk_tval *tv);
-DUK_INTERNAL_DECL duk_int_t duk_to_int_clamped_raw(duk_context *ctx, duk_idx_t idx, duk_int_t minval, duk_int_t maxval, duk_bool_t *out_clamped); /* out_clamped=NULL, RangeError if outside range */
-DUK_INTERNAL_DECL duk_int_t duk_to_int_clamped(duk_context *ctx, duk_idx_t idx, duk_int_t minval, duk_int_t maxval);
-DUK_INTERNAL_DECL duk_int_t duk_to_int_check_range(duk_context *ctx, duk_idx_t idx, duk_int_t minval, duk_int_t maxval);
+DUK_INTERNAL_DECL duk_int_t duk_to_int_clamped_raw(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval, duk_bool_t *out_clamped); /* out_clamped=NULL, RangeError if outside range */
+DUK_INTERNAL_DECL duk_int_t duk_to_int_clamped(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval);
+DUK_INTERNAL_DECL duk_int_t duk_to_int_check_range(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval);
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
-DUK_INTERNAL_DECL duk_uint8_t duk_to_uint8clamped(duk_context *ctx, duk_idx_t idx);
-#endif
-DUK_INTERNAL_DECL duk_hstring *duk_to_property_key_hstring(duk_context *ctx, duk_idx_t idx);
-
-DUK_INTERNAL_DECL duk_hstring *duk_require_hstring(duk_context *ctx, duk_idx_t idx);
-DUK_INTERNAL_DECL duk_hstring *duk_require_hstring_notsymbol(duk_context *ctx, duk_idx_t idx);
-DUK_INTERNAL_DECL const char *duk_require_lstring_notsymbol(duk_context *ctx, duk_idx_t idx, duk_size_t *out_len);
-DUK_INTERNAL_DECL const char *duk_require_string_notsymbol(duk_context *ctx, duk_idx_t idx);
-DUK_INTERNAL_DECL duk_hobject *duk_require_hobject(duk_context *ctx, duk_idx_t idx);
-DUK_INTERNAL_DECL duk_hbuffer *duk_require_hbuffer(duk_context *ctx, duk_idx_t idx);
-DUK_INTERNAL_DECL duk_hthread *duk_require_hthread(duk_context *ctx, duk_idx_t idx);
-DUK_INTERNAL_DECL duk_hcompfunc *duk_require_hcompfunc(duk_context *ctx, duk_idx_t idx);
-DUK_INTERNAL_DECL duk_hnatfunc *duk_require_hnatfunc(duk_context *ctx, duk_idx_t idx);
-
-DUK_INTERNAL_DECL duk_hobject *duk_require_hobject_with_class(duk_context *ctx, duk_idx_t idx, duk_small_uint_t classnum);
-
-DUK_INTERNAL_DECL void duk_push_hstring(duk_context *ctx, duk_hstring *h);
-DUK_INTERNAL_DECL void duk_push_hstring_stridx(duk_context *ctx, duk_small_uint_t stridx);
-DUK_INTERNAL_DECL void duk_push_hstring_empty(duk_context *ctx);
-DUK_INTERNAL_DECL void duk_push_hobject(duk_context *ctx, duk_hobject *h);
-DUK_INTERNAL_DECL void duk_push_hbuffer(duk_context *ctx, duk_hbuffer *h);
-#define duk_push_hthread(ctx,h) \
- duk_push_hobject((ctx), (duk_hobject *) (h))
-#define duk_push_hnatfunc(ctx,h) \
- duk_push_hobject((ctx), (duk_hobject *) (h))
-DUK_INTERNAL_DECL void duk_push_hobject_bidx(duk_context *ctx, duk_small_int_t builtin_idx);
-DUK_INTERNAL_DECL duk_hobject *duk_push_object_helper(duk_context *ctx, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx);
-DUK_INTERNAL_DECL duk_hobject *duk_push_object_helper_proto(duk_context *ctx, duk_uint_t hobject_flags_and_class, duk_hobject *proto);
-DUK_INTERNAL_DECL duk_hcompfunc *duk_push_hcompfunc(duk_context *ctx);
-DUK_INTERNAL_DECL void duk_push_c_function_noexotic(duk_context *ctx, duk_c_function func, duk_int_t nargs);
-DUK_INTERNAL_DECL void duk_push_c_function_noconstruct_noexotic(duk_context *ctx, duk_c_function func, duk_int_t nargs);
+DUK_INTERNAL_DECL duk_uint8_t duk_to_uint8clamped(duk_hthread *thr, duk_idx_t idx);
+#endif
+DUK_INTERNAL_DECL duk_hstring *duk_to_property_key_hstring(duk_hthread *thr, duk_idx_t idx);
+
+DUK_INTERNAL_DECL duk_hstring *duk_require_hstring(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL duk_hstring *duk_require_hstring_notsymbol(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL const char *duk_require_lstring_notsymbol(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_len);
+DUK_INTERNAL_DECL const char *duk_require_string_notsymbol(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL duk_hobject *duk_require_hobject(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL duk_hbuffer *duk_require_hbuffer(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL duk_hthread *duk_require_hthread(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL duk_hcompfunc *duk_require_hcompfunc(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL duk_hnatfunc *duk_require_hnatfunc(duk_hthread *thr, duk_idx_t idx);
+
+DUK_INTERNAL_DECL duk_hobject *duk_require_hobject_with_class(duk_hthread *thr, duk_idx_t idx, duk_small_uint_t classnum);
+
+DUK_INTERNAL_DECL void duk_push_hstring(duk_hthread *thr, duk_hstring *h);
+DUK_INTERNAL_DECL void duk_push_hstring_stridx(duk_hthread *thr, duk_small_uint_t stridx);
+DUK_INTERNAL_DECL void duk_push_hstring_empty(duk_hthread *thr);
+DUK_INTERNAL_DECL void duk_push_hobject(duk_hthread *thr, duk_hobject *h);
+DUK_INTERNAL_DECL void duk_push_hbuffer(duk_hthread *thr, duk_hbuffer *h);
+#define duk_push_hthread(thr,h) \
+ duk_push_hobject((thr), (duk_hobject *) (h))
+#define duk_push_hnatfunc(thr,h) \
+ duk_push_hobject((thr), (duk_hobject *) (h))
+DUK_INTERNAL_DECL void duk_push_hobject_bidx(duk_hthread *thr, duk_small_int_t builtin_idx);
+DUK_INTERNAL_DECL duk_hobject *duk_push_object_helper(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx);
+DUK_INTERNAL_DECL duk_hobject *duk_push_object_helper_proto(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_hobject *proto);
+DUK_INTERNAL_DECL duk_hcompfunc *duk_push_hcompfunc(duk_hthread *thr);
+DUK_INTERNAL_DECL duk_hboundfunc *duk_push_hboundfunc(duk_hthread *thr);
+DUK_INTERNAL_DECL void duk_push_c_function_builtin(duk_hthread *thr, duk_c_function func, duk_int_t nargs);
+DUK_INTERNAL_DECL void duk_push_c_function_builtin_noconstruct(duk_hthread *thr, duk_c_function func, duk_int_t nargs);
/* XXX: duk_push_harray() and duk_push_hcompfunc() are inconsistent with
* duk_push_hobject() etc which don't create a new value.
*/
-DUK_INTERNAL_DECL duk_harray *duk_push_harray(duk_context *ctx);
-DUK_INTERNAL_DECL duk_harray *duk_push_harray_with_size(duk_context *ctx, duk_uint32_t size);
+DUK_INTERNAL_DECL duk_harray *duk_push_harray(duk_hthread *thr);
+DUK_INTERNAL_DECL duk_harray *duk_push_harray_with_size(duk_hthread *thr, duk_uint32_t size);
+DUK_INTERNAL_DECL duk_tval *duk_push_harray_with_size_outptr(duk_hthread *thr, duk_uint32_t size);
-DUK_INTERNAL_DECL void duk_push_string_funcptr(duk_context *ctx, duk_uint8_t *ptr, duk_size_t sz);
-DUK_INTERNAL_DECL void duk_push_lightfunc_name_raw(duk_context *ctx, duk_c_function func, duk_small_uint_t lf_flags);
-DUK_INTERNAL_DECL void duk_push_lightfunc_name(duk_context *ctx, duk_tval *tv);
-DUK_INTERNAL_DECL void duk_push_lightfunc_tostring(duk_context *ctx, duk_tval *tv);
+DUK_INTERNAL_DECL void duk_push_string_funcptr(duk_hthread *thr, duk_uint8_t *ptr, duk_size_t sz);
+DUK_INTERNAL_DECL void duk_push_lightfunc_name_raw(duk_hthread *thr, duk_c_function func, duk_small_uint_t lf_flags);
+DUK_INTERNAL_DECL void duk_push_lightfunc_name(duk_hthread *thr, duk_tval *tv);
+DUK_INTERNAL_DECL void duk_push_lightfunc_tostring(duk_hthread *thr, duk_tval *tv);
+#if 0 /* not used yet */
+DUK_INTERNAL_DECL void duk_push_hnatfunc_name(duk_hthread *thr, duk_hnatfunc *h);
+#endif
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
-DUK_INTERNAL_DECL duk_hbufobj *duk_push_bufobj_raw(duk_context *ctx, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx);
+DUK_INTERNAL_DECL duk_hbufobj *duk_push_bufobj_raw(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx);
#endif
-DUK_INTERNAL_DECL void *duk_push_fixed_buffer_nozero(duk_context *ctx, duk_size_t len);
-DUK_INTERNAL_DECL void *duk_push_fixed_buffer_zero(duk_context *ctx, duk_size_t len);
+DUK_INTERNAL_DECL void *duk_push_fixed_buffer_nozero(duk_hthread *thr, duk_size_t len);
+DUK_INTERNAL_DECL void *duk_push_fixed_buffer_zero(duk_hthread *thr, duk_size_t len);
-DUK_INTERNAL_DECL const char *duk_push_string_readable(duk_context *ctx, duk_idx_t idx);
-DUK_INTERNAL_DECL const char *duk_push_string_tval_readable(duk_context *ctx, duk_tval *tv);
-DUK_INTERNAL_DECL const char *duk_push_string_tval_readable_error(duk_context *ctx, duk_tval *tv);
+DUK_INTERNAL_DECL const char *duk_push_string_readable(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL const char *duk_push_string_tval_readable(duk_hthread *thr, duk_tval *tv);
+DUK_INTERNAL_DECL const char *duk_push_string_tval_readable_error(duk_hthread *thr, duk_tval *tv);
/* The duk_xxx_prop_stridx_short() variants expect their arguments to be short
* enough to be packed into a single 32-bit integer argument. Argument limits
@@ -5383,112 +5447,135 @@ DUK_INTERNAL_DECL const char *duk_push_string_tval_readable_error(duk_context *c
* arguments and such call sites are also easiest to verify to be correct.
*/
-DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx(duk_context *ctx, duk_idx_t obj_idx, duk_small_uint_t stridx); /* [] -> [val] */
-DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx_short_raw(duk_context *ctx, duk_uint_t packed_args);
-#define duk_get_prop_stridx_short(ctx,obj_idx,stridx) \
+DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* [] -> [val] */
+DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args);
+#define duk_get_prop_stridx_short(thr,obj_idx,stridx) \
(DUK_ASSERT_EXPR((duk_int_t) (obj_idx) >= -0x8000L && (duk_int_t) (obj_idx) <= 0x7fffL), \
DUK_ASSERT_EXPR((duk_int_t) (stridx) >= 0 && (duk_int_t) (stridx) <= 0xffffL), \
- duk_get_prop_stridx_short_raw((ctx), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx))))
-DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx_boolean(duk_context *ctx, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_bool_t *out_has_prop); /* [] -> [] */
+ duk_get_prop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx))))
+DUK_INTERNAL_DECL duk_bool_t duk_get_prop_stridx_boolean(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_bool_t *out_has_prop); /* [] -> [] */
-DUK_INTERNAL_DECL duk_bool_t duk_put_prop_stridx(duk_context *ctx, duk_idx_t obj_idx, duk_small_uint_t stridx); /* [val] -> [] */
-DUK_INTERNAL_DECL duk_bool_t duk_put_prop_stridx_short_raw(duk_context *ctx, duk_uint_t packed_args);
-#define duk_put_prop_stridx_short(ctx,obj_idx,stridx) \
+DUK_INTERNAL_DECL duk_bool_t duk_put_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* [val] -> [] */
+DUK_INTERNAL_DECL duk_bool_t duk_put_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args);
+#define duk_put_prop_stridx_short(thr,obj_idx,stridx) \
(DUK_ASSERT_EXPR((duk_int_t) (obj_idx) >= -0x8000L && (duk_int_t) (obj_idx) <= 0x7fffL), \
DUK_ASSERT_EXPR((duk_int_t) (stridx) >= 0 && (duk_int_t) (stridx) <= 0xffffL), \
- duk_put_prop_stridx_short_raw((ctx), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx))))
+ duk_put_prop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx))))
-DUK_INTERNAL_DECL duk_bool_t duk_del_prop_stridx(duk_context *ctx, duk_idx_t obj_idx, duk_small_uint_t stridx); /* [] -> [] */
+DUK_INTERNAL_DECL duk_bool_t duk_del_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* [] -> [] */
#if 0 /* Too few call sites to be useful. */
-DUK_INTERNAL_DECL duk_bool_t duk_del_prop_stridx_short_raw(duk_context *ctx, duk_uint_t packed_args);
-#define duk_del_prop_stridx_short(ctx,obj_idx,stridx) \
+DUK_INTERNAL_DECL duk_bool_t duk_del_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args);
+#define duk_del_prop_stridx_short(thr,obj_idx,stridx) \
(DUK_ASSERT_EXPR((obj_idx) >= -0x8000L && (obj_idx) <= 0x7fffL), \
DUK_ASSERT_EXPR((stridx) >= 0 && (stridx) <= 0xffffL), \
- duk_del_prop_stridx_short_raw((ctx), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx))))
+ duk_del_prop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx))))
#endif
-#define duk_del_prop_stridx_short(ctx,obj_idx,stridx) \
- duk_del_prop_stridx((ctx), (obj_idx), (stridx))
+#define duk_del_prop_stridx_short(thr,obj_idx,stridx) \
+ duk_del_prop_stridx((thr), (obj_idx), (stridx))
-DUK_INTERNAL_DECL duk_bool_t duk_has_prop_stridx(duk_context *ctx, duk_idx_t obj_idx, duk_small_uint_t stridx); /* [] -> [] */
+DUK_INTERNAL_DECL duk_bool_t duk_has_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* [] -> [] */
#if 0 /* Too few call sites to be useful. */
-DUK_INTERNAL_DECL duk_bool_t duk_has_prop_stridx_short_raw(duk_context *ctx, duk_uint_t packed_args);
-#define duk_has_prop_stridx_short(ctx,obj_idx,stridx) \
+DUK_INTERNAL_DECL duk_bool_t duk_has_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args);
+#define duk_has_prop_stridx_short(thr,obj_idx,stridx) \
(DUK_ASSERT_EXPR((obj_idx) >= -0x8000L && (obj_idx) <= 0x7fffL), \
DUK_ASSERT_EXPR((stridx) >= 0 && (stridx) <= 0xffffL), \
- duk_has_prop_stridx_short_raw((ctx), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx))))
+ duk_has_prop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 16) + ((duk_uint_t) (stridx))))
#endif
-#define duk_has_prop_stridx_short(ctx,obj_idx,stridx) \
- duk_has_prop_stridx((ctx), (obj_idx), (stridx))
+#define duk_has_prop_stridx_short(thr,obj_idx,stridx) \
+ duk_has_prop_stridx((thr), (obj_idx), (stridx))
-DUK_INTERNAL_DECL void duk_xdef_prop(duk_context *ctx, duk_idx_t obj_idx, duk_small_uint_t desc_flags); /* [key val] -> [] */
+DUK_INTERNAL_DECL void duk_xdef_prop(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t desc_flags); /* [key val] -> [] */
-DUK_INTERNAL_DECL void duk_xdef_prop_index(duk_context *ctx, duk_idx_t obj_idx, duk_uarridx_t arr_idx, duk_small_uint_t desc_flags); /* [val] -> [] */
+DUK_INTERNAL_DECL void duk_xdef_prop_index(duk_hthread *thr, duk_idx_t obj_idx, duk_uarridx_t arr_idx, duk_small_uint_t desc_flags); /* [val] -> [] */
/* XXX: Because stridx and desc_flags have a limited range, this call could
* always pack stridx and desc_flags into a single argument.
*/
-DUK_INTERNAL_DECL void duk_xdef_prop_stridx(duk_context *ctx, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_small_uint_t desc_flags); /* [val] -> [] */
-DUK_INTERNAL_DECL void duk_xdef_prop_stridx_short_raw(duk_context *ctx, duk_uint_t packed_args);
-#define duk_xdef_prop_stridx_short(ctx,obj_idx,stridx,desc_flags) \
+DUK_INTERNAL_DECL void duk_xdef_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_small_uint_t desc_flags); /* [val] -> [] */
+DUK_INTERNAL_DECL void duk_xdef_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args);
+#define duk_xdef_prop_stridx_short(thr,obj_idx,stridx,desc_flags) \
(DUK_ASSERT_EXPR((duk_int_t) (obj_idx) >= -0x80L && (duk_int_t) (obj_idx) <= 0x7fL), \
DUK_ASSERT_EXPR((duk_int_t) (stridx) >= 0 && (duk_int_t) (stridx) <= 0xffffL), \
DUK_ASSERT_EXPR((duk_int_t) (desc_flags) >= 0 && (duk_int_t) (desc_flags) <= 0xffL), \
- duk_xdef_prop_stridx_short_raw((ctx), (((duk_uint_t) (obj_idx)) << 24) + (((duk_uint_t) (stridx)) << 8) + (duk_uint_t) (desc_flags)))
+ duk_xdef_prop_stridx_short_raw((thr), (((duk_uint_t) (obj_idx)) << 24) + (((duk_uint_t) (stridx)) << 8) + (duk_uint_t) (desc_flags)))
-#define duk_xdef_prop_wec(ctx,obj_idx) \
- duk_xdef_prop((ctx), (obj_idx), DUK_PROPDESC_FLAGS_WEC)
-#define duk_xdef_prop_index_wec(ctx,obj_idx,arr_idx) \
- duk_xdef_prop_index((ctx), (obj_idx), (arr_idx), DUK_PROPDESC_FLAGS_WEC)
-#define duk_xdef_prop_stridx_wec(ctx,obj_idx,stridx) \
- duk_xdef_prop_stridx((ctx), (obj_idx), (stridx), DUK_PROPDESC_FLAGS_WEC)
-#define duk_xdef_prop_stridx_short_wec(ctx,obj_idx,stridx) \
- duk_xdef_prop_stridx_short((ctx), (obj_idx), (stridx), DUK_PROPDESC_FLAGS_WEC)
+#define duk_xdef_prop_wec(thr,obj_idx) \
+ duk_xdef_prop((thr), (obj_idx), DUK_PROPDESC_FLAGS_WEC)
+#define duk_xdef_prop_index_wec(thr,obj_idx,arr_idx) \
+ duk_xdef_prop_index((thr), (obj_idx), (arr_idx), DUK_PROPDESC_FLAGS_WEC)
+#define duk_xdef_prop_stridx_wec(thr,obj_idx,stridx) \
+ duk_xdef_prop_stridx((thr), (obj_idx), (stridx), DUK_PROPDESC_FLAGS_WEC)
+#define duk_xdef_prop_stridx_short_wec(thr,obj_idx,stridx) \
+ duk_xdef_prop_stridx_short((thr), (obj_idx), (stridx), DUK_PROPDESC_FLAGS_WEC)
-DUK_INTERNAL_DECL void duk_xdef_prop_stridx_builtin(duk_context *ctx, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_small_int_t builtin_idx, duk_small_uint_t desc_flags); /* [] -> [] */
+#if 0 /*unused*/
+DUK_INTERNAL_DECL void duk_xdef_prop_stridx_builtin(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_small_int_t builtin_idx, duk_small_uint_t desc_flags); /* [] -> [] */
+#endif
-DUK_INTERNAL_DECL void duk_xdef_prop_stridx_thrower(duk_context *ctx, duk_idx_t obj_idx, duk_small_uint_t stridx); /* [] -> [] */
+DUK_INTERNAL_DECL void duk_xdef_prop_stridx_thrower(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx); /* [] -> [] */
-DUK_INTERNAL_DECL void duk_pack(duk_context *ctx, duk_idx_t count);
+DUK_INTERNAL_DECL void duk_pack(duk_hthread *thr, duk_idx_t count);
+DUK_INTERNAL_DECL duk_idx_t duk_unpack_array_like(duk_hthread *thr, duk_idx_t idx);
#if 0
-DUK_INTERNAL_DECL void duk_unpack(duk_context *ctx);
+DUK_INTERNAL_DECL void duk_unpack(duk_hthread *thr);
#endif
-DUK_INTERNAL_DECL void duk_require_constructor_call(duk_context *ctx);
-DUK_INTERNAL_DECL void duk_require_constructable(duk_context *ctx, duk_idx_t idx);
-DUK_INTERNAL_DECL void duk_push_symbol_descriptive_string(duk_context *ctx, duk_hstring *h);
+DUK_INTERNAL_DECL void duk_require_constructor_call(duk_hthread *thr);
+DUK_INTERNAL_DECL void duk_require_constructable(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL void duk_push_symbol_descriptive_string(duk_hthread *thr, duk_hstring *h);
+
+DUK_INTERNAL_DECL void duk_resolve_nonbound_function(duk_hthread *thr);
+
+DUK_INTERNAL_DECL duk_idx_t duk_get_top_require_min(duk_hthread *thr, duk_idx_t min_top);
+DUK_INTERNAL_DECL duk_idx_t duk_get_top_index_unsafe(duk_hthread *thr);
+
+DUK_INTERNAL_DECL void duk_pop_n_unsafe(duk_hthread *thr, duk_idx_t count);
+DUK_INTERNAL_DECL void duk_pop_unsafe(duk_hthread *thr);
+DUK_INTERNAL_DECL void duk_pop_2_unsafe(duk_hthread *thr);
+DUK_INTERNAL_DECL void duk_pop_3_unsafe(duk_hthread *thr);
+DUK_INTERNAL_DECL void duk_pop_n_nodecref_unsafe(duk_hthread *thr, duk_idx_t count);
+DUK_INTERNAL_DECL void duk_pop_nodecref_unsafe(duk_hthread *thr);
+DUK_INTERNAL_DECL void duk_pop_2_nodecref_unsafe(duk_hthread *thr);
+DUK_INTERNAL_DECL void duk_pop_3_nodecref_unsafe(duk_hthread *thr);
+DUK_INTERNAL_DECL void duk_pop_undefined(duk_hthread *thr);
-DUK_INTERNAL_DECL void duk_resolve_nonbound_function(duk_context *ctx);
+DUK_INTERNAL_DECL void duk_compact_m1(duk_hthread *thr);
-DUK_INTERNAL_DECL duk_idx_t duk_get_top_require_min(duk_context *ctx, duk_idx_t min_top);
-DUK_INTERNAL_DECL duk_idx_t duk_get_top_index_unsafe(duk_context *ctx);
-DUK_INTERNAL_DECL void duk_pop_n_unsafe(duk_context *ctx, duk_idx_t count);
-DUK_INTERNAL_DECL void duk_pop_n_nodecref_unsafe(duk_context *ctx, duk_idx_t count);
-DUK_INTERNAL_DECL void duk_pop_unsafe(duk_context *ctx);
+DUK_INTERNAL_DECL void duk_seal_freeze_raw(duk_hthread *thr, duk_idx_t obj_idx, duk_bool_t is_freeze);
-DUK_INTERNAL_DECL void duk_compact_m1(duk_context *ctx);
+DUK_INTERNAL_DECL void duk_insert_undefined(duk_hthread *thr, duk_idx_t idx);
+DUK_INTERNAL_DECL void duk_insert_undefined_n(duk_hthread *thr, duk_idx_t idx, duk_idx_t count);
+
+DUK_INTERNAL_DECL void duk_concat_2(duk_hthread *thr);
+
+DUK_INTERNAL_DECL duk_int_t duk_pcall_method_flags(duk_hthread *thr, duk_idx_t nargs, duk_small_uint_t call_flags);
/* Raw internal valstack access macros: access is unsafe so call site
* must have a guarantee that the index is valid. When that is the case,
* using these macro results in faster and smaller code than duk_get_tval().
* Both 'ctx' and 'idx' are evaluted multiple times, but only for asserts.
*/
-#define DUK_ASSERT_VALID_NEGIDX(ctx,idx) \
- (DUK_ASSERT_EXPR((duk_int_t) (idx) < 0), DUK_ASSERT_EXPR(duk_is_valid_index((ctx), (idx))))
-#define DUK_ASSERT_VALID_POSIDX(ctx,idx) \
- (DUK_ASSERT_EXPR((duk_int_t) (idx) >= 0), DUK_ASSERT_EXPR(duk_is_valid_index((ctx), (idx))))
-#define DUK_GET_TVAL_NEGIDX(ctx,idx) \
- (DUK_ASSERT_VALID_NEGIDX((ctx),(idx)), ((duk_hthread *) (ctx))->valstack_top + (idx))
-#define DUK_GET_TVAL_POSIDX(ctx,idx) \
- (DUK_ASSERT_VALID_POSIDX((ctx),(idx)), ((duk_hthread *) (ctx))->valstack_bottom + (idx))
-#define DUK_GET_HOBJECT_NEGIDX(ctx,idx) \
- (DUK_ASSERT_VALID_NEGIDX((ctx),(idx)), DUK_TVAL_GET_OBJECT(((duk_hthread *) (ctx))->valstack_top + (idx)))
-#define DUK_GET_HOBJECT_POSIDX(ctx,idx) \
- (DUK_ASSERT_VALID_POSIDX((ctx),(idx)), DUK_TVAL_GET_OBJECT(((duk_hthread *) (ctx))->valstack_bottom + (idx)))
+#define DUK_ASSERT_VALID_NEGIDX(thr,idx) \
+ (DUK_ASSERT_EXPR((duk_int_t) (idx) < 0), DUK_ASSERT_EXPR(duk_is_valid_index((thr), (idx))))
+#define DUK_ASSERT_VALID_POSIDX(thr,idx) \
+ (DUK_ASSERT_EXPR((duk_int_t) (idx) >= 0), DUK_ASSERT_EXPR(duk_is_valid_index((thr), (idx))))
+#define DUK_GET_TVAL_NEGIDX(thr,idx) \
+ (DUK_ASSERT_VALID_NEGIDX((thr),(idx)), ((duk_hthread *) (thr))->valstack_top + (idx))
+#define DUK_GET_TVAL_POSIDX(thr,idx) \
+ (DUK_ASSERT_VALID_POSIDX((thr),(idx)), ((duk_hthread *) (thr))->valstack_bottom + (idx))
+#define DUK_GET_HOBJECT_NEGIDX(thr,idx) \
+ (DUK_ASSERT_VALID_NEGIDX((thr),(idx)), DUK_TVAL_GET_OBJECT(((duk_hthread *) (thr))->valstack_top + (idx)))
+#define DUK_GET_HOBJECT_POSIDX(thr,idx) \
+ (DUK_ASSERT_VALID_POSIDX((thr),(idx)), DUK_TVAL_GET_OBJECT(((duk_hthread *) (thr))->valstack_bottom + (idx)))
#define DUK_GET_THIS_TVAL_PTR(thr) \
(DUK_ASSERT_EXPR((thr)->valstack_bottom > (thr)->valstack), \
(thr)->valstack_bottom - 1)
+DUK_INTERNAL_DECL duk_double_t duk_time_get_ecmascript_time(duk_hthread *thr);
+DUK_INTERNAL_DECL duk_double_t duk_time_get_ecmascript_time_nofrac(duk_hthread *thr);
+DUK_INTERNAL_DECL duk_double_t duk_time_get_monotonic_time(duk_hthread *thr);
+
#endif /* DUK_API_INTERNAL_H_INCLUDED */
/* #include duk_hstring.h */
/*
@@ -5628,7 +5715,9 @@ DUK_INTERNAL_DECL void duk_compact_m1(duk_context *ctx);
#define DUK_HSTRING_GET_DATA_END(x) \
(DUK_HSTRING_GET_DATA((x)) + (x)->blen)
-/* marker value; in E5 2^32-1 is not a valid array index (2^32-2 is highest valid) */
+/* Marker value; in E5 2^32-1 is not a valid array index (2^32-2 is highest
+ * valid).
+ */
#define DUK_HSTRING_NO_ARRAY_INDEX (0xffffffffUL)
#if defined(DUK_USE_HSTRING_ARRIDX)
@@ -5646,10 +5735,19 @@ DUK_INTERNAL_DECL void duk_compact_m1(duk_context *ctx);
(duk_js_to_arrayindex_hstring_fast((h)))
#endif
+/* XXX: these actually fit into duk_hstring */
+#define DUK_SYMBOL_TYPE_HIDDEN 0
+#define DUK_SYMBOL_TYPE_GLOBAL 1
+#define DUK_SYMBOL_TYPE_LOCAL 2
+#define DUK_SYMBOL_TYPE_WELLKNOWN 3
+
/*
* Misc
*/
+#if (DUK_USE_ALIGN_BY == 8) && defined(DUK_USE_PACK_MSVC_PRAGMA)
+#pragma pack(push, 8)
+#endif
struct duk_hstring {
/* Smaller heaphdr than for other objects, because strings are held
* in string intern table which requires no link pointers. Much of
@@ -5694,7 +5792,16 @@ struct duk_hstring {
* for strings, but fields above should guarantee alignment-by-4
* (but not alignment-by-8).
*/
-};
+}
+#if (DUK_USE_ALIGN_BY == 8) && defined(DUK_USE_PACK_GCC_ATTR)
+__attribute__ ((aligned (8)))
+#elif (DUK_USE_ALIGN_BY == 8) && defined(DUK_USE_PACK_CLANG_ATTR)
+__attribute__ ((aligned (8)))
+#endif
+;
+#if (DUK_USE_ALIGN_BY == 8) && defined(DUK_USE_PACK_MSVC_PRAGMA)
+#pragma pack(pop)
+#endif
/* The external string struct is defined even when the feature is inactive. */
struct duk_hstring_external {
@@ -5714,7 +5821,11 @@ struct duk_hstring_external {
*/
DUK_INTERNAL_DECL duk_ucodepoint_t duk_hstring_char_code_at_raw(duk_hthread *thr, duk_hstring *h, duk_uint_t pos, duk_bool_t surrogate_aware);
+DUK_INTERNAL_DECL duk_bool_t duk_hstring_equals_ascii_cstring(duk_hstring *h, const char *cstr);
DUK_INTERNAL_DECL duk_size_t duk_hstring_get_charlen(duk_hstring *h);
+#if !defined(DUK_USE_HSTRING_LAZY_CLEN)
+DUK_INTERNAL_DECL void duk_hstring_init_charlen(duk_hstring *h);
+#endif
#endif /* DUK_HSTRING_H_INCLUDED */
/* #include duk_hobject.h */
@@ -5761,7 +5872,8 @@ DUK_INTERNAL_DECL duk_size_t duk_hstring_get_charlen(duk_hstring *h);
*/
#define DUK_HOBJECT_FLAG_EXTENSIBLE DUK_HEAPHDR_USER_FLAG(0) /* object is extensible */
#define DUK_HOBJECT_FLAG_CONSTRUCTABLE DUK_HEAPHDR_USER_FLAG(1) /* object is constructable */
-#define DUK_HOBJECT_FLAG_BOUNDFUNC DUK_HEAPHDR_USER_FLAG(2) /* object established using Function.prototype.bind() */
+#define DUK_HOBJECT_FLAG_CALLABLE DUK_HEAPHDR_USER_FLAG(2) /* object is callable */
+#define DUK_HOBJECT_FLAG_BOUNDFUNC DUK_HEAPHDR_USER_FLAG(3) /* object established using Function.prototype.bind() */
#define DUK_HOBJECT_FLAG_COMPFUNC DUK_HEAPHDR_USER_FLAG(4) /* object is a compiled function (duk_hcompfunc) */
#define DUK_HOBJECT_FLAG_NATFUNC DUK_HEAPHDR_USER_FLAG(5) /* object is a native function (duk_hnatfunc) */
#define DUK_HOBJECT_FLAG_BUFOBJ DUK_HEAPHDR_USER_FLAG(6) /* object is a buffer object (duk_hbufobj) (always exotic) */
@@ -5772,12 +5884,12 @@ DUK_INTERNAL_DECL duk_size_t duk_hstring_get_charlen(duk_hstring *h);
#define DUK_HOBJECT_FLAG_NEWENV DUK_HEAPHDR_USER_FLAG(11) /* function: create new environment when called (see duk_hcompfunc) */
#define DUK_HOBJECT_FLAG_NAMEBINDING DUK_HEAPHDR_USER_FLAG(12) /* function: create binding for func name (function templates only, used for named function expressions) */
#define DUK_HOBJECT_FLAG_CREATEARGS DUK_HEAPHDR_USER_FLAG(13) /* function: create an arguments object on function call */
-#define DUK_HOBJECT_FLAG_HAVE_FINALIZER DUK_HEAPHDR_USER_FLAG(14) /* object has a callable finalizer property */
+#define DUK_HOBJECT_FLAG_HAVE_FINALIZER DUK_HEAPHDR_USER_FLAG(14) /* object has a callable (own) finalizer property */
#define DUK_HOBJECT_FLAG_EXOTIC_ARRAY DUK_HEAPHDR_USER_FLAG(15) /* 'Array' object, array length and index exotic behavior */
#define DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ DUK_HEAPHDR_USER_FLAG(16) /* 'String' object, array index exotic behavior */
#define DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS DUK_HEAPHDR_USER_FLAG(17) /* 'Arguments' object and has arguments exotic behavior (non-strict callee) */
-#define DUK_HOBJECT_FLAG_EXOTIC_DUKFUNC DUK_HEAPHDR_USER_FLAG(18) /* Duktape/C (nativefunction) object, exotic 'length' */
-#define DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ DUK_HEAPHDR_USER_FLAG(19) /* 'Proxy' object */
+#define DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ DUK_HEAPHDR_USER_FLAG(18) /* 'Proxy' object */
+#define DUK_HOBJECT_FLAG_SPECIAL_CALL DUK_HEAPHDR_USER_FLAG(19) /* special casing in call behavior, for .call(), .apply(), etc. */
#define DUK_HOBJECT_FLAG_CLASS_BASE DUK_HEAPHDR_USER_FLAG_NUMBER(20)
#define DUK_HOBJECT_FLAG_CLASS_BITS 5
@@ -5884,8 +5996,17 @@ DUK_INTERNAL_DECL duk_size_t duk_hstring_get_charlen(duk_hstring *h);
#define DUK_HOBJECT_IS_BOUNDFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC)
#define DUK_HOBJECT_IS_COMPFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC)
#define DUK_HOBJECT_IS_NATFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC)
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
#define DUK_HOBJECT_IS_BUFOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ)
+#else
+#define DUK_HOBJECT_IS_BUFOBJ(h) 0
+#endif
#define DUK_HOBJECT_IS_THREAD(h) (DUK_HOBJECT_GET_CLASS_NUMBER((h)) == DUK_HOBJECT_CLASS_THREAD)
+#if defined(DUK_USE_ES6_PROXY)
+#define DUK_HOBJECT_IS_PROXY(h) DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ((h))
+#else
+#define DUK_HOBJECT_IS_PROXY(h) 0
+#endif
#define DUK_HOBJECT_IS_NONBOUND_FUNCTION(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, \
DUK_HOBJECT_FLAG_COMPFUNC | \
@@ -5896,16 +6017,12 @@ DUK_INTERNAL_DECL duk_size_t duk_hstring_get_charlen(duk_hstring *h);
DUK_HOBJECT_FLAG_COMPFUNC | \
DUK_HOBJECT_FLAG_NATFUNC)
-#define DUK_HOBJECT_IS_CALLABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, \
- DUK_HOBJECT_FLAG_BOUNDFUNC | \
- DUK_HOBJECT_FLAG_COMPFUNC | \
- DUK_HOBJECT_FLAG_NATFUNC)
+#define DUK_HOBJECT_IS_CALLABLE(h) DUK_HOBJECT_HAS_CALLABLE((h))
/* Object has any exotic behavior(s). */
#define DUK_HOBJECT_EXOTIC_BEHAVIOR_FLAGS (DUK_HOBJECT_FLAG_EXOTIC_ARRAY | \
DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS | \
DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | \
- DUK_HOBJECT_FLAG_EXOTIC_DUKFUNC | \
DUK_HOBJECT_FLAG_BUFOBJ | \
DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ)
#define DUK_HOBJECT_HAS_EXOTIC_BEHAVIOR(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_EXOTIC_BEHAVIOR_FLAGS)
@@ -5913,16 +6030,20 @@ DUK_INTERNAL_DECL duk_size_t duk_hstring_get_charlen(duk_hstring *h);
/* Object has any virtual properties (not counting Proxy behavior). */
#define DUK_HOBJECT_VIRTUAL_PROPERTY_FLAGS (DUK_HOBJECT_FLAG_EXOTIC_ARRAY | \
DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ | \
- DUK_HOBJECT_FLAG_EXOTIC_DUKFUNC | \
DUK_HOBJECT_FLAG_BUFOBJ)
#define DUK_HOBJECT_HAS_VIRTUAL_PROPERTIES(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_VIRTUAL_PROPERTY_FLAGS)
#define DUK_HOBJECT_HAS_EXTENSIBLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE)
#define DUK_HOBJECT_HAS_CONSTRUCTABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE)
+#define DUK_HOBJECT_HAS_CALLABLE(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE)
#define DUK_HOBJECT_HAS_BOUNDFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC)
#define DUK_HOBJECT_HAS_COMPFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC)
#define DUK_HOBJECT_HAS_NATFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC)
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
#define DUK_HOBJECT_HAS_BUFOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ)
+#else
+#define DUK_HOBJECT_HAS_BUFOBJ(h) 0
+#endif
#define DUK_HOBJECT_HAS_FASTREFS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS)
#define DUK_HOBJECT_HAS_ARRAY_PART(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART)
#define DUK_HOBJECT_HAS_STRICT(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT)
@@ -5934,15 +6055,22 @@ DUK_INTERNAL_DECL duk_size_t duk_hstring_get_charlen(duk_hstring *h);
#define DUK_HOBJECT_HAS_EXOTIC_ARRAY(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY)
#define DUK_HOBJECT_HAS_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ)
#define DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS)
-#define DUK_HOBJECT_HAS_EXOTIC_DUKFUNC(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_DUKFUNC)
+#if defined(DUK_USE_ES6_PROXY)
#define DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ)
+#else
+#define DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ(h) 0
+#endif
+#define DUK_HOBJECT_HAS_SPECIAL_CALL(h) DUK_HEAPHDR_CHECK_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL)
#define DUK_HOBJECT_SET_EXTENSIBLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE)
#define DUK_HOBJECT_SET_CONSTRUCTABLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE)
+#define DUK_HOBJECT_SET_CALLABLE(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE)
#define DUK_HOBJECT_SET_BOUNDFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC)
#define DUK_HOBJECT_SET_COMPFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC)
#define DUK_HOBJECT_SET_NATFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC)
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
#define DUK_HOBJECT_SET_BUFOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ)
+#endif
#define DUK_HOBJECT_SET_FASTREFS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS)
#define DUK_HOBJECT_SET_ARRAY_PART(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART)
#define DUK_HOBJECT_SET_STRICT(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT)
@@ -5954,15 +6082,20 @@ DUK_INTERNAL_DECL duk_size_t duk_hstring_get_charlen(duk_hstring *h);
#define DUK_HOBJECT_SET_EXOTIC_ARRAY(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY)
#define DUK_HOBJECT_SET_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ)
#define DUK_HOBJECT_SET_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS)
-#define DUK_HOBJECT_SET_EXOTIC_DUKFUNC(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_DUKFUNC)
+#if defined(DUK_USE_ES6_PROXY)
#define DUK_HOBJECT_SET_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ)
+#endif
+#define DUK_HOBJECT_SET_SPECIAL_CALL(h) DUK_HEAPHDR_SET_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL)
#define DUK_HOBJECT_CLEAR_EXTENSIBLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXTENSIBLE)
#define DUK_HOBJECT_CLEAR_CONSTRUCTABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CONSTRUCTABLE)
+#define DUK_HOBJECT_CLEAR_CALLABLE(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_CALLABLE)
#define DUK_HOBJECT_CLEAR_BOUNDFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BOUNDFUNC)
#define DUK_HOBJECT_CLEAR_COMPFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_COMPFUNC)
#define DUK_HOBJECT_CLEAR_NATFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_NATFUNC)
+#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
#define DUK_HOBJECT_CLEAR_BUFOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_BUFOBJ)
+#endif
#define DUK_HOBJECT_CLEAR_FASTREFS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_FASTREFS)
#define DUK_HOBJECT_CLEAR_ARRAY_PART(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_ARRAY_PART)
#define DUK_HOBJECT_CLEAR_STRICT(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_STRICT)
@@ -5974,25 +6107,29 @@ DUK_INTERNAL_DECL duk_size_t duk_hstring_get_charlen(duk_hstring *h);
#define DUK_HOBJECT_CLEAR_EXOTIC_ARRAY(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARRAY)
#define DUK_HOBJECT_CLEAR_EXOTIC_STRINGOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ)
#define DUK_HOBJECT_CLEAR_EXOTIC_ARGUMENTS(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS)
-#define DUK_HOBJECT_CLEAR_EXOTIC_DUKFUNC(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_DUKFUNC)
+#if defined(DUK_USE_ES6_PROXY)
#define DUK_HOBJECT_CLEAR_EXOTIC_PROXYOBJ(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ)
+#endif
+#define DUK_HOBJECT_CLEAR_SPECIAL_CALL(h) DUK_HEAPHDR_CLEAR_FLAG_BITS(&(h)->hdr, DUK_HOBJECT_FLAG_SPECIAL_CALL)
/* Object can/cannot use FASTREFS, i.e. has no strong reference fields beyond
- * duk_hobject base header.
+ * duk_hobject base header. This is used just for asserts so doesn't need to
+ * be optimized.
*/
#define DUK_HOBJECT_PROHIBITS_FASTREFS(h) \
(DUK_HOBJECT_IS_COMPFUNC((h)) || DUK_HOBJECT_IS_DECENV((h)) || DUK_HOBJECT_IS_OBJENV((h)) || \
- DUK_HOBJECT_IS_BUFOBJ((h)) || DUK_HOBJECT_IS_THREAD((h)))
+ DUK_HOBJECT_IS_BUFOBJ((h)) || DUK_HOBJECT_IS_THREAD((h)) || DUK_HOBJECT_IS_PROXY((h)) || \
+ DUK_HOBJECT_IS_BOUNDFUNC((h)))
#define DUK_HOBJECT_ALLOWS_FASTREFS(h) (!DUK_HOBJECT_PROHIBITS_FASTREFS((h)))
/* Flags used for property attributes in duk_propdesc and packed flags.
* Must fit into 8 bits.
*/
-#define DUK_PROPDESC_FLAG_WRITABLE (1 << 0) /* E5 Section 8.6.1 */
-#define DUK_PROPDESC_FLAG_ENUMERABLE (1 << 1) /* E5 Section 8.6.1 */
-#define DUK_PROPDESC_FLAG_CONFIGURABLE (1 << 2) /* E5 Section 8.6.1 */
-#define DUK_PROPDESC_FLAG_ACCESSOR (1 << 3) /* accessor */
-#define DUK_PROPDESC_FLAG_VIRTUAL (1 << 4) /* property is virtual: used in duk_propdesc, never stored
+#define DUK_PROPDESC_FLAG_WRITABLE (1U << 0) /* E5 Section 8.6.1 */
+#define DUK_PROPDESC_FLAG_ENUMERABLE (1U << 1) /* E5 Section 8.6.1 */
+#define DUK_PROPDESC_FLAG_CONFIGURABLE (1U << 2) /* E5 Section 8.6.1 */
+#define DUK_PROPDESC_FLAG_ACCESSOR (1U << 3) /* accessor */
+#define DUK_PROPDESC_FLAG_VIRTUAL (1U << 4) /* property is virtual: used in duk_propdesc, never stored
* (used by e.g. buffer virtual properties)
*/
#define DUK_PROPDESC_FLAGS_MASK (DUK_PROPDESC_FLAG_WRITABLE | \
@@ -6003,7 +6140,7 @@ DUK_INTERNAL_DECL duk_size_t duk_hstring_get_charlen(duk_hstring *h);
/* Additional flags which are passed in the same flags argument as property
* flags but are not stored in object properties.
*/
-#define DUK_PROPDESC_FLAG_NO_OVERWRITE (1 << 4) /* internal define property: skip write silently if exists */
+#define DUK_PROPDESC_FLAG_NO_OVERWRITE (1U << 4) /* internal define property: skip write silently if exists */
/* Convenience defines for property attributes. */
#define DUK_PROPDESC_FLAGS_NONE 0
@@ -6018,8 +6155,8 @@ DUK_INTERNAL_DECL duk_size_t duk_hstring_get_charlen(duk_hstring *h);
DUK_PROPDESC_FLAG_CONFIGURABLE)
/* Flags for duk_hobject_get_own_propdesc() and variants. */
-#define DUK_GETDESC_FLAG_PUSH_VALUE (1 << 0) /* push value to stack */
-#define DUK_GETDESC_FLAG_IGNORE_PROTOLOOP (1 << 1) /* don't throw for prototype loop */
+#define DUK_GETDESC_FLAG_PUSH_VALUE (1U << 0) /* push value to stack */
+#define DUK_GETDESC_FLAG_IGNORE_PROTOLOOP (1U << 1) /* don't throw for prototype loop */
/*
* Macro for object validity check
@@ -6328,9 +6465,6 @@ DUK_INTERNAL_DECL duk_size_t duk_hstring_get_charlen(duk_hstring *h);
*/
#define DUK_HOBJECT_PROTOTYPE_CHAIN_SANITY 10000L
-/* Maximum traversal depth for "bound function" chains. */
-#define DUK_HOBJECT_BOUND_CHAIN_SANITY 10000L
-
/*
* Ecmascript [[Class]]
*/
@@ -6362,9 +6496,22 @@ DUK_INTERNAL_DECL duk_size_t duk_hstring_get_charlen(duk_hstring *h);
} while (0)
#endif
-/* note: this updates refcounts */
+/* Set prototype, DECREF earlier value, INCREF new value (tolerating NULLs). */
#define DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr,h,p) duk_hobject_set_prototype_updref((thr), (h), (p))
+/* Set initial prototype, assume NULL previous prototype, INCREF new value,
+ * tolerate NULL.
+ */
+#define DUK_HOBJECT_SET_PROTOTYPE_INIT_INCREF(thr,h,proto) do { \
+ duk_hthread *duk__thr = (thr); \
+ duk_hobject *duk__obj = (h); \
+ duk_hobject *duk__proto = (proto); \
+ DUK_UNREF(duk__thr); \
+ DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(duk__thr->heap, duk__obj) == NULL); \
+ DUK_HOBJECT_SET_PROTOTYPE(duk__thr->heap, duk__obj, duk__proto); \
+ DUK_HOBJECT_INCREF_ALLOWNULL(duk__thr, duk__proto); \
+ } while (0)
+
/*
* Finalizer check
*/
@@ -6560,6 +6707,7 @@ DUK_INTERNAL_DECL duk_hobject *duk_hobject_alloc(duk_hthread *thr, duk_uint_t ho
DUK_INTERNAL_DECL duk_harray *duk_harray_alloc(duk_hthread *thr, duk_uint_t hobject_flags);
DUK_INTERNAL_DECL duk_hcompfunc *duk_hcompfunc_alloc(duk_hthread *thr, duk_uint_t hobject_flags);
DUK_INTERNAL_DECL duk_hnatfunc *duk_hnatfunc_alloc(duk_hthread *thr, duk_uint_t hobject_flags);
+DUK_INTERNAL_DECL duk_hboundfunc *duk_hboundfunc_alloc(duk_heap *heap, duk_uint_t hobject_flags);
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
DUK_INTERNAL_DECL duk_hbufobj *duk_hbufobj_alloc(duk_hthread *thr, duk_uint_t hobject_flags);
#endif
@@ -6567,6 +6715,7 @@ DUK_INTERNAL_DECL duk_hthread *duk_hthread_alloc_unchecked(duk_heap *heap, duk_u
DUK_INTERNAL_DECL duk_hthread *duk_hthread_alloc(duk_hthread *thr, duk_uint_t hobject_flags);
DUK_INTERNAL_DECL duk_hdecenv *duk_hdecenv_alloc(duk_hthread *thr, duk_uint_t hobject_flags);
DUK_INTERNAL_DECL duk_hobjenv *duk_hobjenv_alloc(duk_hthread *thr, duk_uint_t hobject_flags);
+DUK_INTERNAL_DECL duk_hproxy *duk_hproxy_alloc(duk_hthread *thr, duk_uint_t hobject_flags);
/* resize */
DUK_INTERNAL_DECL void duk_hobject_realloc_props(duk_hthread *thr,
@@ -6575,11 +6724,19 @@ DUK_INTERNAL_DECL void duk_hobject_realloc_props(duk_hthread *thr,
duk_uint32_t new_a_size,
duk_uint32_t new_h_size,
duk_bool_t abandon_array);
+DUK_INTERNAL_DECL void duk_hobject_resize_entrypart(duk_hthread *thr,
+ duk_hobject *obj,
+ duk_uint32_t new_e_size);
+#if 0 /*unused*/
+DUK_INTERNAL_DECL void duk_hobject_resize_arraypart(duk_hthread *thr,
+ duk_hobject *obj,
+ duk_uint32_t new_a_size);
+#endif
/* low-level property functions */
-DUK_INTERNAL_DECL void duk_hobject_find_existing_entry(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_int_t *e_idx, duk_int_t *h_idx);
+DUK_INTERNAL_DECL duk_bool_t duk_hobject_find_existing_entry(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_int_t *e_idx, duk_int_t *h_idx);
DUK_INTERNAL_DECL duk_tval *duk_hobject_find_existing_entry_tval_ptr(duk_heap *heap, duk_hobject *obj, duk_hstring *key);
-DUK_INTERNAL_DECL duk_tval *duk_hobject_find_existing_entry_tval_ptr_and_attrs(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_int_t *out_attrs);
+DUK_INTERNAL_DECL duk_tval *duk_hobject_find_existing_entry_tval_ptr_and_attrs(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_uint_t *out_attrs);
DUK_INTERNAL_DECL duk_tval *duk_hobject_find_existing_array_entry_tval_ptr(duk_heap *heap, duk_hobject *obj, duk_uarridx_t i);
DUK_INTERNAL_DECL duk_bool_t duk_hobject_get_own_propdesc(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_propdesc *out_desc, duk_small_uint_t flags);
@@ -6596,8 +6753,8 @@ DUK_INTERNAL_DECL duk_bool_t duk_hobject_delprop(duk_hthread *thr, duk_tval *tv_
DUK_INTERNAL_DECL duk_bool_t duk_hobject_hasprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key);
/* internal property functions */
-#define DUK_DELPROP_FLAG_THROW (1 << 0)
-#define DUK_DELPROP_FLAG_FORCE (1 << 1)
+#define DUK_DELPROP_FLAG_THROW (1U << 0)
+#define DUK_DELPROP_FLAG_FORCE (1U << 1)
DUK_INTERNAL_DECL duk_bool_t duk_hobject_delprop_raw(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_small_uint_t flags);
DUK_INTERNAL_DECL duk_bool_t duk_hobject_hasprop_raw(duk_hthread *thr, duk_hobject *obj, duk_hstring *key);
DUK_INTERNAL_DECL void duk_hobject_define_property_internal(duk_hthread *thr, duk_hobject *obj, duk_hstring *key, duk_small_uint_t flags);
@@ -6610,28 +6767,26 @@ DUK_INTERNAL_DECL duk_bool_t duk_hobject_has_finalizer_fast_raw(duk_hobject *obj
#endif
/* helpers for defineProperty() and defineProperties() */
-DUK_INTERNAL_DECL
-void duk_hobject_prepare_property_descriptor(duk_context *ctx,
- duk_idx_t idx_in,
- duk_uint_t *out_defprop_flags,
- duk_idx_t *out_idx_value,
- duk_hobject **out_getter,
- duk_hobject **out_setter);
-DUK_INTERNAL_DECL
-duk_bool_t duk_hobject_define_property_helper(duk_context *ctx,
- duk_uint_t defprop_flags,
- duk_hobject *obj,
- duk_hstring *key,
- duk_idx_t idx_value,
- duk_hobject *get,
- duk_hobject *set,
- duk_bool_t throw_flag);
+DUK_INTERNAL_DECL void duk_hobject_prepare_property_descriptor(duk_hthread *thr,
+ duk_idx_t idx_in,
+ duk_uint_t *out_defprop_flags,
+ duk_idx_t *out_idx_value,
+ duk_hobject **out_getter,
+ duk_hobject **out_setter);
+DUK_INTERNAL_DECL duk_bool_t duk_hobject_define_property_helper(duk_hthread *thr,
+ duk_uint_t defprop_flags,
+ duk_hobject *obj,
+ duk_hstring *key,
+ duk_idx_t idx_value,
+ duk_hobject *get,
+ duk_hobject *set,
+ duk_bool_t throw_flag);
/* Object built-in methods */
-DUK_INTERNAL_DECL void duk_hobject_object_get_own_property_descriptor(duk_context *ctx, duk_idx_t obj_idx);
+DUK_INTERNAL_DECL void duk_hobject_object_get_own_property_descriptor(duk_hthread *thr, duk_idx_t obj_idx);
DUK_INTERNAL_DECL void duk_hobject_object_seal_freeze_helper(duk_hthread *thr, duk_hobject *obj, duk_bool_t is_freeze);
DUK_INTERNAL_DECL duk_bool_t duk_hobject_object_is_sealed_frozen_helper(duk_hthread *thr, duk_hobject *obj, duk_bool_t is_frozen);
-DUK_INTERNAL_DECL duk_bool_t duk_hobject_object_ownprop_helper(duk_context *ctx, duk_small_uint_t required_desc_flags);
+DUK_INTERNAL_DECL duk_bool_t duk_hobject_object_ownprop_helper(duk_hthread *thr, duk_small_uint_t required_desc_flags);
/* internal properties */
DUK_INTERNAL_DECL duk_bool_t duk_hobject_get_internal_value(duk_heap *heap, duk_hobject *obj, duk_tval *tv);
@@ -6642,14 +6797,14 @@ DUK_INTERNAL_DECL void duk_hobject_compact_props(duk_hthread *thr, duk_hobject *
/* ES2015 proxy */
#if defined(DUK_USE_ES6_PROXY)
-DUK_INTERNAL_DECL duk_bool_t duk_hobject_proxy_check(duk_hthread *thr, duk_hobject *obj, duk_hobject **out_target, duk_hobject **out_handler);
-DUK_INTERNAL_DECL duk_hobject *duk_hobject_resolve_proxy_target(duk_hthread *thr, duk_hobject *obj);
+DUK_INTERNAL_DECL duk_bool_t duk_hobject_proxy_check(duk_hobject *obj, duk_hobject **out_target, duk_hobject **out_handler);
+DUK_INTERNAL_DECL duk_hobject *duk_hobject_resolve_proxy_target(duk_hobject *obj);
#endif
/* enumeration */
-DUK_INTERNAL_DECL void duk_hobject_enumerator_create(duk_context *ctx, duk_small_uint_t enum_flags);
-DUK_INTERNAL_DECL duk_ret_t duk_hobject_get_enumerated_keys(duk_context *ctx, duk_small_uint_t enum_flags);
-DUK_INTERNAL_DECL duk_bool_t duk_hobject_enumerator_next(duk_context *ctx, duk_bool_t get_value);
+DUK_INTERNAL_DECL void duk_hobject_enumerator_create(duk_hthread *thr, duk_small_uint_t enum_flags);
+DUK_INTERNAL_DECL duk_ret_t duk_hobject_get_enumerated_keys(duk_hthread *thr, duk_small_uint_t enum_flags);
+DUK_INTERNAL_DECL duk_bool_t duk_hobject_enumerator_next(duk_hthread *thr, duk_bool_t get_value);
/* macros */
DUK_INTERNAL_DECL void duk_hobject_set_prototype_updref(duk_hthread *thr, duk_hobject *h, duk_hobject *p);
@@ -6657,7 +6812,7 @@ DUK_INTERNAL_DECL void duk_hobject_set_prototype_updref(duk_hthread *thr, duk_ho
/* pc2line */
#if defined(DUK_USE_PC2LINE)
DUK_INTERNAL_DECL void duk_hobject_pc2line_pack(duk_hthread *thr, duk_compiler_instr *instrs, duk_uint_fast32_t length);
-DUK_INTERNAL_DECL duk_uint_fast32_t duk_hobject_pc2line_query(duk_context *ctx, duk_idx_t idx_func, duk_uint_fast32_t pc);
+DUK_INTERNAL_DECL duk_uint_fast32_t duk_hobject_pc2line_query(duk_hthread *thr, duk_idx_t idx_func, duk_uint_fast32_t pc);
#endif
/* misc */
@@ -6667,8 +6822,8 @@ DUK_INTERNAL_DECL duk_bool_t duk_hobject_prototype_chain_contains(duk_hthread *t
/* These declarations are needed when related built-in is disabled and
* genbuiltins.py won't automatically emit the declerations.
*/
-DUK_INTERNAL_DECL duk_ret_t duk_bi_object_prototype_to_string(duk_context *ctx);
-DUK_INTERNAL_DECL duk_ret_t duk_bi_function_prototype(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_object_prototype_to_string(duk_hthread *thr);
+DUK_INTERNAL_DECL duk_ret_t duk_bi_function_prototype(duk_hthread *thr);
#endif
#endif /* DUK_HOBJECT_H_INCLUDED */
@@ -6802,6 +6957,13 @@ DUK_INTERNAL_DECL duk_ret_t duk_bi_function_prototype(duk_context *ctx);
#define DUK_HCOMPFUNC_GET_CODE_COUNT(heap,h) \
((duk_size_t) (DUK_HCOMPFUNC_GET_CODE_SIZE((heap), (h)) / sizeof(duk_instr_t)))
+/*
+ * Validity assert
+ */
+
+#define DUK_ASSERT_HCOMPFUNC_VALID(h) do { \
+ DUK_ASSERT((h) != NULL); \
+ } while (0)
/*
* Main struct
@@ -6964,11 +7126,52 @@ struct duk_hnatfunc {
* versa.
*
* Note: cannot place nargs/magic into the heaphdr flags, because
- * duk_hobject takes almost all flags already (and needs the spare).
+ * duk_hobject takes almost all flags already.
*/
};
#endif /* DUK_HNATFUNC_H_INCLUDED */
+/* #include duk_hboundfunc.h */
+/*
+ * Bound function representation.
+ */
+
+#if !defined(DUK_HBOUNDFUNC_H_INCLUDED)
+#define DUK_HBOUNDFUNC_H_INCLUDED
+
+/* Artificial limit for args length. Ensures arithmetic won't overflow
+ * 32 bits when combining bound functions.
+ */
+#define DUK_HBOUNDFUNC_MAX_ARGS 0x20000000UL
+
+#define DUK_ASSERT_HBOUNDFUNC_VALID(h) do { \
+ DUK_ASSERT((h) != NULL); \
+ DUK_ASSERT(DUK_HOBJECT_IS_BOUNDFUNC((duk_hobject *) (h))); \
+ DUK_ASSERT(DUK_TVAL_IS_LIGHTFUNC(&(h)->target) || \
+ (DUK_TVAL_IS_OBJECT(&(h)->target) && \
+ DUK_HOBJECT_IS_CALLABLE(DUK_TVAL_GET_OBJECT(&(h)->target)))); \
+ DUK_ASSERT(!DUK_TVAL_IS_UNUSED(&(h)->this_binding)); \
+ DUK_ASSERT((h)->nargs == 0 || (h)->args != NULL); \
+ } while (0)
+
+struct duk_hboundfunc {
+ /* Shared object part. */
+ duk_hobject obj;
+
+ /* Final target function, stored as duk_tval so that lightfunc can be
+ * represented too.
+ */
+ duk_tval target;
+
+ /* This binding. */
+ duk_tval this_binding;
+
+ /* Arguments to prepend. */
+ duk_tval *args; /* Separate allocation. */
+ duk_idx_t nargs;
+};
+
+#endif /* DUK_HBOUNDFUNC_H_INCLUDED */
/* #include duk_hbufobj.h */
/*
* Heap Buffer object representation. Used for all Buffer variants.
@@ -7106,9 +7309,9 @@ struct duk_hbufobj {
DUK_INTERNAL_DECL duk_uint_t duk_hbufobj_clamp_bytelength(duk_hbufobj *h_bufobj, duk_uint_t len);
DUK_INTERNAL_DECL void duk_hbufobj_push_uint8array_from_plain(duk_hthread *thr, duk_hbuffer *h_buf);
-DUK_INTERNAL_DECL void duk_hbufobj_push_validated_read(duk_context *ctx, duk_hbufobj *h_bufobj, duk_uint8_t *p, duk_small_uint_t elem_size);
-DUK_INTERNAL_DECL void duk_hbufobj_validated_write(duk_context *ctx, duk_hbufobj *h_bufobj, duk_uint8_t *p, duk_small_uint_t elem_size);
-DUK_INTERNAL_DECL void duk_hbufobj_promote_plain(duk_context *ctx, duk_idx_t idx);
+DUK_INTERNAL_DECL void duk_hbufobj_push_validated_read(duk_hthread *thr, duk_hbufobj *h_bufobj, duk_uint8_t *p, duk_small_uint_t elem_size);
+DUK_INTERNAL_DECL void duk_hbufobj_validated_write(duk_hthread *thr, duk_hbufobj *h_bufobj, duk_uint8_t *p, duk_small_uint_t elem_size);
+DUK_INTERNAL_DECL void duk_hbufobj_promote_plain(duk_hthread *thr, duk_idx_t idx);
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
#endif /* DUK_HBUFOBJ_H_INCLUDED */
@@ -7116,8 +7319,9 @@ DUK_INTERNAL_DECL void duk_hbufobj_promote_plain(duk_context *ctx, duk_idx_t idx
/*
* Heap thread object representation.
*
- * duk_hthread is also the 'context' (duk_context) for exposed APIs
- * which mostly operate on the topmost frame of the value stack.
+ * duk_hthread is also the 'context' for public API functions via a
+ * different typedef. Most API calls operate on the topmost frame
+ * of the value stack only.
*/
#if !defined(DUK_HTHREAD_H_INCLUDED)
@@ -7127,61 +7331,46 @@ DUK_INTERNAL_DECL void duk_hbufobj_promote_plain(duk_context *ctx, duk_idx_t idx
* Stack constants
*/
-#define DUK_VALSTACK_GROW_STEP 128 /* roughly 1 kiB */
-#define DUK_VALSTACK_SHRINK_THRESHOLD 256 /* roughly 2 kiB */
-#define DUK_VALSTACK_SHRINK_SPARE 64 /* roughly 0.5 kiB */
-#define DUK_VALSTACK_INITIAL_SIZE 128 /* roughly 1.0 kiB -> but rounds up to DUK_VALSTACK_GROW_STEP in practice */
-#define DUK_VALSTACK_INTERNAL_EXTRA 64 /* internal extra elements assumed on function entry,
- * always added to user-defined 'extra' for e.g. the
- * duk_check_stack() call.
- */
-#define DUK_VALSTACK_API_ENTRY_MINIMUM DUK_API_ENTRY_STACK
- /* number of elements guaranteed to be user accessible
- * (in addition to call arguments) on Duktape/C function entry.
- */
+/* Initial valstack size, roughly 0.7kiB. */
+#define DUK_VALSTACK_INITIAL_SIZE 96U
-/* Note: DUK_VALSTACK_INITIAL_SIZE must be >= DUK_VALSTACK_API_ENTRY_MINIMUM
- * + DUK_VALSTACK_INTERNAL_EXTRA so that the initial stack conforms to spare
- * requirements.
+/* Internal extra elements assumed on function entry, always added to
+ * user-defined 'extra' for e.g. the duk_check_stack() call.
*/
+#define DUK_VALSTACK_INTERNAL_EXTRA 32U
-#define DUK_VALSTACK_DEFAULT_MAX 1000000L
-
-#define DUK_CALLSTACK_GROW_STEP 8 /* roughly 256 bytes */
-#define DUK_CALLSTACK_SHRINK_THRESHOLD 16 /* roughly 512 bytes */
-#define DUK_CALLSTACK_SHRINK_SPARE 8 /* roughly 256 bytes */
-#define DUK_CALLSTACK_INITIAL_SIZE 8
-#define DUK_CALLSTACK_DEFAULT_MAX 10000L
-
-#define DUK_CATCHSTACK_GROW_STEP 4 /* roughly 64 bytes */
-#define DUK_CATCHSTACK_SHRINK_THRESHOLD 8 /* roughly 128 bytes */
-#define DUK_CATCHSTACK_SHRINK_SPARE 4 /* roughly 64 bytes */
-#define DUK_CATCHSTACK_INITIAL_SIZE 4
-#define DUK_CATCHSTACK_DEFAULT_MAX 10000L
+/* Number of elements guaranteed to be user accessible (in addition to call
+ * arguments) on Duktape/C function entry. This is the major public API
+ * commitment.
+ */
+#define DUK_VALSTACK_API_ENTRY_MINIMUM DUK_API_ENTRY_STACK
/*
* Activation defines
*/
-#define DUK_ACT_FLAG_STRICT (1 << 0) /* function executes in strict mode */
-#define DUK_ACT_FLAG_TAILCALLED (1 << 1) /* activation has tail called one or more times */
-#define DUK_ACT_FLAG_CONSTRUCT (1 << 2) /* function executes as a constructor (called via "new") */
-#define DUK_ACT_FLAG_PREVENT_YIELD (1 << 3) /* activation prevents yield (native call or "new") */
-#define DUK_ACT_FLAG_DIRECT_EVAL (1 << 4) /* activation is a direct eval call */
-#define DUK_ACT_FLAG_BREAKPOINT_ACTIVE (1 << 5) /* activation has active breakpoint(s) */
+#define DUK_ACT_FLAG_STRICT (1U << 0) /* function executes in strict mode */
+#define DUK_ACT_FLAG_TAILCALLED (1U << 1) /* activation has tail called one or more times */
+#define DUK_ACT_FLAG_CONSTRUCT (1U << 2) /* function executes as a constructor (called via "new") */
+#define DUK_ACT_FLAG_PREVENT_YIELD (1U << 3) /* activation prevents yield (native call or "new") */
+#define DUK_ACT_FLAG_DIRECT_EVAL (1U << 4) /* activation is a direct eval call */
+#define DUK_ACT_FLAG_CONSTRUCT_PROXY (1U << 5) /* activation is for Proxy 'construct' call, special return value handling */
+#define DUK_ACT_FLAG_BREAKPOINT_ACTIVE (1U << 6) /* activation has active breakpoint(s) */
-#define DUK_ACT_GET_FUNC(act) ((act)->func)
+#define DUK_ACT_GET_FUNC(act) ((act)->func)
/*
* Flags for __FILE__ / __LINE__ registered into tracedata
*/
-#define DUK_TB_FLAG_NOBLAME_FILELINE (1 << 0) /* don't report __FILE__ / __LINE__ as fileName/lineNumber */
+#define DUK_TB_FLAG_NOBLAME_FILELINE (1U << 0) /* don't report __FILE__ / __LINE__ as fileName/lineNumber */
/*
* Catcher defines
*/
+/* XXX: remove catcher type entirely */
+
/* flags field: LLLLLLFT, L = label (24 bits), F = flags (4 bits), T = type (4 bits) */
#define DUK_CAT_TYPE_MASK 0x0000000fUL
#define DUK_CAT_TYPE_BITS 4
@@ -7189,10 +7378,10 @@ DUK_INTERNAL_DECL void duk_hbufobj_promote_plain(duk_context *ctx, duk_idx_t idx
#define DUK_CAT_LABEL_BITS 24
#define DUK_CAT_LABEL_SHIFT 8
-#define DUK_CAT_FLAG_CATCH_ENABLED (1 << 4) /* catch part will catch */
-#define DUK_CAT_FLAG_FINALLY_ENABLED (1 << 5) /* finally part will catch */
-#define DUK_CAT_FLAG_CATCH_BINDING_ENABLED (1 << 6) /* request to create catch binding */
-#define DUK_CAT_FLAG_LEXENV_ACTIVE (1 << 7) /* catch or with binding is currently active */
+#define DUK_CAT_FLAG_CATCH_ENABLED (1U << 4) /* catch part will catch */
+#define DUK_CAT_FLAG_FINALLY_ENABLED (1U << 5) /* finally part will catch */
+#define DUK_CAT_FLAG_CATCH_BINDING_ENABLED (1U << 6) /* request to create catch binding */
+#define DUK_CAT_FLAG_LEXENV_ACTIVE (1U << 7) /* catch or with binding is currently active */
#define DUK_CAT_TYPE_UNKNOWN 0
#define DUK_CAT_TYPE_TCF 1
@@ -7273,25 +7462,39 @@ DUK_INTERNAL_DECL void duk_hbufobj_promote_plain(duk_context *ctx, duk_idx_t idx
* diagnose behavior so it's worth checking even when the check is not 100%.
*/
-#if defined(DUK_USE_PREFER_SIZE)
-#define DUK_ASSERT_CTX_VSSIZE(ctx) /*nop*/
-#else
-#define DUK_ASSERT_CTX_VSSIZE(ctx) \
- DUK_ASSERT((duk_size_t) (((duk_hthread *) (ctx))->valstack_end - ((duk_hthread *) (ctx))->valstack) == \
- ((duk_hthread *) (ctx))->valstack_size)
-#endif
-#define DUK_ASSERT_CTX_VALID(ctx) do { \
- DUK_ASSERT((ctx) != NULL); \
- DUK_ASSERT(DUK_HEAPHDR_GET_TYPE((duk_heaphdr *) (ctx)) == DUK_HTYPE_OBJECT); \
- DUK_ASSERT(DUK_HOBJECT_IS_THREAD((duk_hobject *) (ctx))); \
- DUK_ASSERT(((duk_hthread *) (ctx))->unused1 == 0); \
- DUK_ASSERT(((duk_hthread *) (ctx))->unused2 == 0); \
- DUK_ASSERT(((duk_hthread *) (ctx))->valstack != NULL); \
- DUK_ASSERT(((duk_hthread *) (ctx))->valstack_end >= ((duk_hthread *) (ctx))->valstack); \
- DUK_ASSERT(((duk_hthread *) (ctx))->valstack_top >= ((duk_hthread *) (ctx))->valstack); \
- DUK_ASSERT(((duk_hthread *) (ctx))->valstack_top >= ((duk_hthread *) (ctx))->valstack_bottom); \
- DUK_ASSERT(((duk_hthread *) (ctx))->valstack_end >= ((duk_hthread *) (ctx))->valstack_top); \
- DUK_ASSERT_CTX_VSSIZE((ctx)); \
+/* Assertions for internals. */
+#define DUK_ASSERT_HTHREAD_VALID(thr) do { \
+ DUK_ASSERT((thr) != NULL); \
+ DUK_ASSERT(DUK_HEAPHDR_GET_TYPE((duk_heaphdr *) (thr)) == DUK_HTYPE_OBJECT); \
+ DUK_ASSERT(DUK_HOBJECT_IS_THREAD((duk_hobject *) (thr))); \
+ DUK_ASSERT((thr)->unused1 == 0); \
+ DUK_ASSERT((thr)->unused2 == 0); \
+ } while (0)
+
+/* Assertions for public API calls; a bit stronger. */
+#define DUK_ASSERT_CTX_VALID(thr) do { \
+ DUK_ASSERT((thr) != NULL); \
+ DUK_ASSERT_HTHREAD_VALID((thr)); \
+ DUK_ASSERT((thr)->valstack != NULL); \
+ DUK_ASSERT((thr)->valstack_bottom != NULL); \
+ DUK_ASSERT((thr)->valstack_top != NULL); \
+ DUK_ASSERT((thr)->valstack_end != NULL); \
+ DUK_ASSERT((thr)->valstack_alloc_end != NULL); \
+ DUK_ASSERT((thr)->valstack_alloc_end >= (thr)->valstack); \
+ DUK_ASSERT((thr)->valstack_end >= (thr)->valstack); \
+ DUK_ASSERT((thr)->valstack_top >= (thr)->valstack); \
+ DUK_ASSERT((thr)->valstack_top >= (thr)->valstack_bottom); \
+ DUK_ASSERT((thr)->valstack_end >= (thr)->valstack_top); \
+ DUK_ASSERT((thr)->valstack_alloc_end >= (thr)->valstack_end); \
+ } while (0)
+
+/* Assertions for API call entry specifically. Checks 'ctx' but also may
+ * check internal state (e.g. not in a debugger transport callback).
+ */
+#define DUK_ASSERT_API_ENTRY(thr) do { \
+ DUK_ASSERT_CTX_VALID((thr)); \
+ DUK_ASSERT((thr)->heap != NULL); \
+ DUK_ASSERT((thr)->heap->dbg_calling_transport == 0); \
} while (0)
/*
@@ -7318,16 +7521,15 @@ DUK_INTERNAL_DECL void duk_hbufobj_promote_plain(duk_context *ctx, duk_idx_t idx
* Struct defines
*/
-/* XXX: for a memory-code tradeoff, remove 'func' and make it's access either a function
- * or a macro. This would make the activation 32 bytes long on 32-bit platforms again.
- */
-
-/* Note: it's nice if size is 2^N (at least for 32-bit platforms). */
+/* Fields are ordered for alignment/packing. */
struct duk_activation {
duk_tval tv_func; /* borrowed: full duk_tval for function being executed; for lightfuncs */
duk_hobject *func; /* borrowed: function being executed; for bound function calls, this is the final, real function, NULL for lightfuncs */
+ duk_activation *parent; /* previous (parent) activation (or NULL if none) */
duk_hobject *var_env; /* current variable environment (may be NULL if delayed) */
duk_hobject *lex_env; /* current lexical environment (may be NULL if delayed) */
+ duk_catcher *cat; /* current catcher (or NULL) */
+
#if defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY)
/* Previous value of 'func' caller, restored when unwound. Only in use
* when 'func' is non-strict.
@@ -7336,52 +7538,61 @@ struct duk_activation {
#endif
duk_instr_t *curr_pc; /* next instruction to execute (points to 'func' bytecode, stable pointer), NULL for native calls */
-#if defined(DUK_USE_DEBUGGER_SUPPORT)
- duk_uint32_t prev_line; /* needed for stepping */
-#endif
- duk_small_uint_t flags;
- /* idx_bottom and idx_retval are only used for book-keeping of
- * Ecmascript-initiated calls, to allow returning to an Ecmascript
- * function properly. They are duk_size_t to match the convention
- * that value stack sizes are duk_size_t and local frame indices
- * are duk_idx_t.
+ /* bottom_byteoff and retval_byteoff are only used for book-keeping
+ * of Ecmascript-initiated calls, to allow returning to an Ecmascript
+ * function properly.
*/
/* Bottom of valstack for this activation, used to reset
- * valstack_bottom on return; index is absolute. Note:
- * idx_top not needed because top is set to 'nregs' always
- * when returning to an Ecmascript activation.
+ * valstack_bottom on return; offset is absolute. There's
+ * no need to track 'top' because native call handling deals
+ * with that using locals, and for Ecmascript returns 'nregs'
+ * indicates the necessary top.
*/
- duk_size_t idx_bottom;
+ duk_size_t bottom_byteoff;
/* Return value when returning to this activation (points to caller
- * reg, not callee reg); index is absolute (only set if activation is
+ * reg, not callee reg); offset is absolute (only set if activation is
* not topmost).
*
- * Note: idx_bottom is always set, while idx_retval is only applicable
- * for activations below the topmost one. Currently idx_retval for
- * the topmost activation is considered garbage (and it not initialized
- * on entry or cleared on return; may contain previous or garbage
- * values).
+ * Note: bottom_byteoff is always set, while retval_byteoff is only
+ * applicable for activations below the topmost one. Currently
+ * retval_byteoff for the topmost activation is considered garbage
+ * (and it not initialized on entry or cleared on return; may contain
+ * previous or garbage values).
*/
- duk_size_t idx_retval;
+ duk_size_t retval_byteoff;
- /* Current 'this' binding is the value just below idx_bottom.
+ /* Current 'this' binding is the value just below bottom.
* Previously, 'this' binding was handled with an index to the
* (calling) valstack. This works for everything except tail
- * calls, which must not "cumulate" valstack temps.
+ * calls, which must not "accumulate" valstack temps.
+ */
+
+ /* Value stack reserve (valstack_end) byte offset to be restored
+ * when returning to this activation. Only used by the bytecode
+ * executor.
*/
+ duk_size_t reserve_byteoff;
+
+#if defined(DUK_USE_DEBUGGER_SUPPORT)
+ duk_uint32_t prev_line; /* needed for stepping */
+#endif
+
+ duk_small_uint_t flags;
};
-/* Note: it's nice if size is 2^N (not 4x4 = 16 bytes on 32 bit) */
struct duk_catcher {
+ duk_catcher *parent; /* previous (parent) catcher (or NULL if none) */
duk_hstring *h_varname; /* borrowed reference to catch variable name (or NULL if none) */
/* (reference is valid as long activation exists) */
duk_instr_t *pc_base; /* resume execution from pc_base or pc_base+1 (points to 'func' bytecode, stable pointer) */
- duk_size_t callstack_index; /* callstack index of related activation */
duk_size_t idx_base; /* idx_base and idx_base+1 get completion value and type */
duk_uint32_t flags; /* type and control flags, label number */
+ /* XXX: could pack 'flags' and 'idx_base' to same value in practice,
+ * on 32-bit targets this would make duk_catcher 16 bytes.
+ */
};
struct duk_hthread {
@@ -7406,40 +7617,49 @@ struct duk_hthread {
duk_uint8_t unused1;
duk_uint8_t unused2;
- /* Sanity limits for stack sizes. */
- duk_size_t valstack_max;
- duk_size_t callstack_max;
- duk_size_t catchstack_max;
-
- /* XXX: Valstack, callstack, and catchstack are currently assumed
- * to have non-NULL pointers. Relaxing this would not lead to big
- * benefits (except perhaps for terminated threads).
+ /* XXX: Valstack and callstack are currently assumed to have non-NULL
+ * pointers. Relaxing this would not lead to big benefits (except
+ * perhaps for terminated threads).
*/
- /* Value stack: these are expressed as pointers for faster stack manipulation.
- * [valstack,valstack_top[ is GC-reachable, [valstack_top,valstack_end[ is
- * not GC-reachable but kept initialized as 'undefined'.
+ /* Value stack: these are expressed as pointers for faster stack
+ * manipulation. [valstack,valstack_top[ is GC-reachable,
+ * [valstack_top,valstack_alloc_end[ is not GC-reachable but kept
+ * initialized as 'undefined'. [valstack,valstack_end[ is the
+ * guaranteed/reserved space and the valstack cannot be resized to
+ * a smaller size. [valstack_end,valstack_alloc_end[ is currently
+ * allocated slack that can be used to grow the current guaranteed
+ * space but may be shrunk away without notice.
+ *
+ *
+ * <----------------------- guaranteed --->
+ * <---- slack --->
+ * <--- frame --->
+ * .-------------+=============+----------+--------------.
+ * |xxxxxxxxxxxxx|yyyyyyyyyyyyy|uuuuuuuuuu|uuuuuuuuuuuuuu|
+ * `-------------+=============+----------+--------------'
+ *
+ * ^ ^ ^ ^ ^
+ * | | | | |
+ * valstack bottom top end alloc_end
+ *
+ * xxx = arbitrary values, below current frame
+ * yyy = arbitrary values, inside current frame
+ * uuu = outside active value stack, initialized to 'undefined'
*/
duk_tval *valstack; /* start of valstack allocation */
- duk_tval *valstack_end; /* end of valstack allocation (exclusive) */
+ duk_tval *valstack_end; /* end of valstack reservation/guarantee (exclusive) */
+ duk_tval *valstack_alloc_end; /* end of valstack allocation */
duk_tval *valstack_bottom; /* bottom of current frame */
duk_tval *valstack_top; /* top of current frame (exclusive) */
-#if !defined(DUK_USE_PREFER_SIZE)
- duk_size_t valstack_size; /* cached: valstack_end - valstack (in entries, not bytes) */
-#endif
- /* Call stack. [0,callstack_top[ is GC reachable. */
- duk_activation *callstack;
+ /* Call stack, represented as a linked list starting from the current
+ * activation (or NULL if nothing is active).
+ */
duk_activation *callstack_curr; /* current activation (or NULL if none) */
- duk_size_t callstack_size; /* allocation size */
- duk_size_t callstack_top; /* next to use, highest used is top - 1 (or none if top == 0) */
+ duk_size_t callstack_top; /* number of activation records in callstack (0 if none) */
duk_size_t callstack_preventcount; /* number of activation records in callstack preventing a yield */
- /* Catch stack. [0,catchstack_top[ is GC reachable. */
- duk_catcher *catchstack;
- duk_size_t catchstack_size; /* allocation size */
- duk_size_t catchstack_top; /* next to use, highest used is top - 1 */
-
/* Yield/resume book-keeping. */
duk_hthread *resumer; /* who resumed us (if any) */
@@ -7492,24 +7712,22 @@ DUK_INTERNAL_DECL void duk_hthread_create_builtin_objects(duk_hthread *thr);
DUK_INTERNAL_DECL duk_bool_t duk_hthread_init_stacks(duk_heap *heap, duk_hthread *thr);
DUK_INTERNAL_DECL void duk_hthread_terminate(duk_hthread *thr);
-DUK_INTERNAL_DECL void duk_hthread_callstack_grow(duk_hthread *thr);
-DUK_INTERNAL_DECL void duk_hthread_callstack_shrink_check(duk_hthread *thr);
-DUK_INTERNAL_DECL void duk_hthread_callstack_unwind_norz(duk_hthread *thr, duk_size_t new_top);
-DUK_INTERNAL_DECL void duk_hthread_callstack_unwind(duk_hthread *thr, duk_size_t new_top);
-DUK_INTERNAL_DECL void duk_hthread_catchstack_grow(duk_hthread *thr);
-DUK_INTERNAL_DECL void duk_hthread_catchstack_shrink_check(duk_hthread *thr);
-DUK_INTERNAL_DECL void duk_hthread_catchstack_unwind_norz(duk_hthread *thr, duk_size_t new_top);
-DUK_INTERNAL_DECL void duk_hthread_catchstack_unwind(duk_hthread *thr, duk_size_t new_top);
+DUK_INTERNAL_DECL DUK_INLINE duk_activation *duk_hthread_activation_alloc(duk_hthread *thr);
+DUK_INTERNAL_DECL void duk_hthread_activation_free(duk_hthread *thr, duk_activation *act);
+DUK_INTERNAL_DECL void duk_hthread_activation_unwind_norz(duk_hthread *thr);
+DUK_INTERNAL_DECL void duk_hthread_activation_unwind_reuse_norz(duk_hthread *thr);
+DUK_INTERNAL_DECL duk_activation *duk_hthread_get_activation_for_level(duk_hthread *thr, duk_int_t level);
+
+DUK_INTERNAL_DECL DUK_INLINE duk_catcher *duk_hthread_catcher_alloc(duk_hthread *thr);
+DUK_INTERNAL_DECL void duk_hthread_catcher_free(duk_hthread *thr, duk_catcher *cat);
+DUK_INTERNAL_DECL void duk_hthread_catcher_unwind_norz(duk_hthread *thr, duk_activation *act);
+DUK_INTERNAL_DECL void duk_hthread_catcher_unwind_nolexenv_norz(duk_hthread *thr, duk_activation *act);
#if defined(DUK_USE_FINALIZER_TORTURE)
DUK_INTERNAL_DECL void duk_hthread_valstack_torture_realloc(duk_hthread *thr);
-DUK_INTERNAL_DECL void duk_hthread_callstack_torture_realloc(duk_hthread *thr);
-DUK_INTERNAL_DECL void duk_hthread_catchstack_torture_realloc(duk_hthread *thr);
#endif
DUK_INTERNAL_DECL void *duk_hthread_get_valstack_ptr(duk_heap *heap, void *ud); /* indirect allocs */
-DUK_INTERNAL_DECL void *duk_hthread_get_callstack_ptr(duk_heap *heap, void *ud); /* indirect allocs */
-DUK_INTERNAL_DECL void *duk_hthread_get_catchstack_ptr(duk_heap *heap, void *ud); /* indirect allocs */
#if defined(DUK_USE_DEBUGGER_SUPPORT)
DUK_INTERNAL_DECL duk_uint_fast32_t duk_hthread_get_act_curr_pc(duk_hthread *thr, duk_activation *act);
@@ -7521,7 +7739,7 @@ DUK_INTERNAL_DECL void duk_hthread_sync_and_null_currpc(duk_hthread *thr);
#endif /* DUK_HTHREAD_H_INCLUDED */
/* #include duk_harray.h */
/*
- * Heap Array object representation. Used for actual Array instances.
+ * Array object representation, used for actual Array instances.
*
* All objects with the exotic array behavior (which must coincide with having
* internal class array) MUST be duk_harrays. No other object can be a
@@ -7598,7 +7816,7 @@ struct duk_hdecenv {
*/
duk_hthread *thread;
duk_hobject *varmap;
- duk_size_t regbase;
+ duk_size_t regbase_byteoff;
};
struct duk_hobjenv {
@@ -7674,9 +7892,6 @@ struct duk_hobjenv {
* Field access
*/
-/* Get/set the current user visible size, without accounting for a dynamic
- * buffer's "spare" (= usable size).
- */
#if defined(DUK_USE_BUFLEN16)
/* size stored in duk_heaphdr unused flag bits */
#define DUK_HBUFFER_GET_SIZE(x) ((x)->hdr.h_flags >> 16)
@@ -7796,7 +8011,7 @@ struct duk_hbuffer {
* it is useful for writing robust native code.
*/
- /* Current size (not counting a dynamic buffer's "spare"). */
+ /* Current size. */
#if defined(DUK_USE_BUFLEN16)
/* Stored in duk_heaphdr unused flags. */
#else
@@ -7945,6 +8160,33 @@ DUK_INTERNAL_DECL void duk_hbuffer_resize(duk_hthread *thr, duk_hbuffer_dynamic
DUK_INTERNAL_DECL void duk_hbuffer_reset(duk_hthread *thr, duk_hbuffer_dynamic *buf);
#endif /* DUK_HBUFFER_H_INCLUDED */
+/* #include duk_hproxy.h */
+/*
+ * Proxy object representation.
+ */
+
+#if !defined(DUK_HPROXY_H_INCLUDED)
+#define DUK_HPROXY_H_INCLUDED
+
+#define DUK_ASSERT_HPROXY_VALID(h) do { \
+ DUK_ASSERT((h) != NULL); \
+ DUK_ASSERT((h)->target != NULL); \
+ DUK_ASSERT((h)->handler != NULL); \
+ DUK_ASSERT(DUK_HOBJECT_HAS_EXOTIC_PROXYOBJ((duk_hobject *) (h))); \
+ } while (0)
+
+struct duk_hproxy {
+ /* Shared object part. */
+ duk_hobject obj;
+
+ /* Proxy target object. */
+ duk_hobject *target;
+
+ /* Proxy handlers (traps). */
+ duk_hobject *handler;
+};
+
+#endif /* DUK_HPROXY_H_INCLUDED */
/* #include duk_heap.h */
/*
* Heap structure.
@@ -7962,11 +8204,10 @@ DUK_INTERNAL_DECL void duk_hbuffer_reset(duk_hthread *thr, duk_hbuffer_dynamic *
* Heap flags
*/
-#define DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED (1 << 0) /* mark-and-sweep marking reached a recursion limit and must use multi-pass marking */
-#define DUK_HEAP_FLAG_ERRHANDLER_RUNNING (1 << 1) /* an error handler (user callback to augment/replace error) is running */
-#define DUK_HEAP_FLAG_INTERRUPT_RUNNING (1 << 2) /* executor interrupt running (used to avoid nested interrupts) */
-#define DUK_HEAP_FLAG_FINALIZER_NORESCUE (1 << 3) /* heap destruction ongoing, finalizer rescue no longer possible */
-#define DUK_HEAP_FLAG_DEBUGGER_PAUSED (1 << 4) /* debugger is paused: talk with debug client until step/resume */
+#define DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED (1U << 0) /* mark-and-sweep marking reached a recursion limit and must use multi-pass marking */
+#define DUK_HEAP_FLAG_INTERRUPT_RUNNING (1U << 1) /* executor interrupt running (used to avoid nested interrupts) */
+#define DUK_HEAP_FLAG_FINALIZER_NORESCUE (1U << 2) /* heap destruction ongoing, finalizer rescue no longer possible */
+#define DUK_HEAP_FLAG_DEBUGGER_PAUSED (1U << 3) /* debugger is paused: talk with debug client until step/resume */
#define DUK__HEAP_HAS_FLAGS(heap,bits) ((heap)->flags & (bits))
#define DUK__HEAP_SET_FLAGS(heap,bits) do { \
@@ -7977,19 +8218,16 @@ DUK_INTERNAL_DECL void duk_hbuffer_reset(duk_hthread *thr, duk_hbuffer_dynamic *
} while (0)
#define DUK_HEAP_HAS_MARKANDSWEEP_RECLIMIT_REACHED(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED)
-#define DUK_HEAP_HAS_ERRHANDLER_RUNNING(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_ERRHANDLER_RUNNING)
#define DUK_HEAP_HAS_INTERRUPT_RUNNING(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING)
#define DUK_HEAP_HAS_FINALIZER_NORESCUE(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE)
#define DUK_HEAP_HAS_DEBUGGER_PAUSED(heap) DUK__HEAP_HAS_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED)
#define DUK_HEAP_SET_MARKANDSWEEP_RECLIMIT_REACHED(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED)
-#define DUK_HEAP_SET_ERRHANDLER_RUNNING(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_ERRHANDLER_RUNNING)
#define DUK_HEAP_SET_INTERRUPT_RUNNING(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING)
#define DUK_HEAP_SET_FINALIZER_NORESCUE(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE)
#define DUK_HEAP_SET_DEBUGGER_PAUSED(heap) DUK__HEAP_SET_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED)
#define DUK_HEAP_CLEAR_MARKANDSWEEP_RECLIMIT_REACHED(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_MARKANDSWEEP_RECLIMIT_REACHED)
-#define DUK_HEAP_CLEAR_ERRHANDLER_RUNNING(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_ERRHANDLER_RUNNING)
#define DUK_HEAP_CLEAR_INTERRUPT_RUNNING(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_INTERRUPT_RUNNING)
#define DUK_HEAP_CLEAR_FINALIZER_NORESCUE(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_FINALIZER_NORESCUE)
#define DUK_HEAP_CLEAR_DEBUGGER_PAUSED(heap) DUK__HEAP_CLEAR_FLAGS((heap), DUK_HEAP_FLAG_DEBUGGER_PAUSED)
@@ -8018,22 +8256,22 @@ DUK_INTERNAL_DECL void duk_hbuffer_reset(duk_hthread *thr, duk_hbuffer_dynamic *
/* Emergency mark-and-sweep: try extra hard, even at the cost of
* performance.
*/
-#define DUK_MS_FLAG_EMERGENCY (1 << 0)
+#define DUK_MS_FLAG_EMERGENCY (1U << 0)
/* Voluntary mark-and-sweep: triggered periodically. */
-#define DUK_MS_FLAG_VOLUNTARY (1 << 1)
+#define DUK_MS_FLAG_VOLUNTARY (1U << 1)
/* Postpone rescue decisions for reachable objects with FINALIZED set.
* Used during finalize_list processing to avoid incorrect rescue
* decisions due to finalize_list being a reachability root.
*/
-#define DUK_MS_FLAG_POSTPONE_RESCUE (1 << 2)
+#define DUK_MS_FLAG_POSTPONE_RESCUE (1U << 2)
/* Don't compact objects; needed during object property table resize
* to prevent a recursive resize. It would suffice to protect only the
* current object being resized, but this is not yet implemented.
*/
-#define DUK_MS_FLAG_NO_OBJECT_COMPACTION (1 << 2)
+#define DUK_MS_FLAG_NO_OBJECT_COMPACTION (1U << 3)
/*
* Thread switching
@@ -8052,6 +8290,18 @@ DUK_INTERNAL_DECL void duk_hbuffer_reset(duk_hthread *thr, duk_hbuffer_dynamic *
#endif
/*
+ * Stats
+ */
+
+#if defined(DUK_USE_DEBUG)
+#define DUK_STATS_INC(heap,fieldname) do { \
+ (heap)->fieldname += 1; \
+ } while (0)
+#else
+#define DUK_STATS_INC(heap,fieldname) do {} while (0)
+#endif
+
+/*
* Other heap related defines
*/
@@ -8168,10 +8418,14 @@ typedef void *(*duk_mem_getptr)(duk_heap *heap, void *ud);
/*
* Checked allocation, relative to a thread
+ *
+ * DUK_FREE_CHECKED() doesn't actually throw, but accepts a 'thr' argument
+ * for convenience.
*/
#define DUK_ALLOC_CHECKED(thr,size) duk_heap_mem_alloc_checked((thr), (size))
#define DUK_ALLOC_CHECKED_ZEROED(thr,size) duk_heap_mem_alloc_checked_zeroed((thr), (size))
+#define DUK_FREE_CHECKED(thr,ptr) duk_heap_mem_free((thr)->heap, (ptr))
/*
* Memory constants
@@ -8207,11 +8461,14 @@ typedef void *(*duk_mem_getptr)(duk_heap *heap, void *ud);
/* Milliseconds between status notify and transport peeks. */
#define DUK_HEAP_DBG_RATELIMIT_MILLISECS 200
-/* Step types */
-#define DUK_STEP_TYPE_NONE 0
-#define DUK_STEP_TYPE_INTO 1
-#define DUK_STEP_TYPE_OVER 2
-#define DUK_STEP_TYPE_OUT 3
+/* Debugger pause flags. */
+#define DUK_PAUSE_FLAG_ONE_OPCODE (1U << 0) /* pause when a single opcode has been executed */
+#define DUK_PAUSE_FLAG_ONE_OPCODE_ACTIVE (1U << 1) /* one opcode pause actually active; artifact of current implementation */
+#define DUK_PAUSE_FLAG_LINE_CHANGE (1U << 2) /* pause when current line number changes */
+#define DUK_PAUSE_FLAG_FUNC_ENTRY (1U << 3) /* pause when entering a function */
+#define DUK_PAUSE_FLAG_FUNC_EXIT (1U << 4) /* pause when exiting current function */
+#define DUK_PAUSE_FLAG_CAUGHT_ERROR (1U << 5) /* pause when about to throw an error that is caught */
+#define DUK_PAUSE_FLAG_UNCAUGHT_ERROR (1U << 6) /* pause when about to throw an error that won't be caught */
struct duk_breakpoint {
duk_hstring *filename;
@@ -8307,6 +8564,14 @@ struct duk_heap {
#endif
#endif
+ /* Freelist for duk_activations and duk_catchers. */
+#if defined(DUK_USE_CACHE_ACTIVATION)
+ duk_activation *activation_free;
+#endif
+#if defined(DUK_USE_CACHE_CATCHER)
+ duk_catcher *catcher_free;
+#endif
+
/* Voluntary mark-and-sweep trigger counter. Intentionally signed
* because we continue decreasing the value when voluntary GC cannot
* run.
@@ -8370,6 +8635,14 @@ struct duk_heap {
*/
duk_bool_t creating_error;
+ /* Marker for indicating we're calling a user error augmentation
+ * (errCreate/errThrow) function. Errors created/thrown during
+ * such a call are not augmented.
+ */
+#if defined(DUK_USE_AUGMENT_ERROR_THROW) || defined(DUK_USE_AUGMENT_ERROR_CREATE)
+ duk_bool_t augmenting_error;
+#endif
+
/* Longjmp state. */
duk_ljstate lj;
@@ -8431,23 +8704,25 @@ struct duk_heap {
duk_bool_t dbg_state_dirty; /* resend state next time executor is about to run */
duk_bool_t dbg_force_restart; /* force executor restart to recheck breakpoints; used to handle function returns (see GH-303) */
duk_bool_t dbg_detaching; /* debugger detaching; used to avoid calling detach handler recursively */
- duk_small_uint_t dbg_step_type; /* step type: none, step into, step over, step out */
- duk_hthread *dbg_step_thread; /* borrowed; NULL if no step state (NULLed in unwind) */
- duk_size_t dbg_step_csindex; /* callstack index */
- duk_uint32_t dbg_step_startline; /* starting line number */
+ duk_small_uint_t dbg_pause_flags; /* flags for automatic pause behavior */
+ duk_activation *dbg_pause_act; /* activation related to pause behavior (pause on line change, function entry/exit) */
+ duk_uint32_t dbg_pause_startline; /* starting line number for line change related pause behavior */
duk_breakpoint dbg_breakpoints[DUK_HEAP_MAX_BREAKPOINTS]; /* breakpoints: [0,breakpoint_count[ gc reachable */
duk_small_uint_t dbg_breakpoint_count;
duk_breakpoint *dbg_breakpoints_active[DUK_HEAP_MAX_BREAKPOINTS + 1]; /* currently active breakpoints: NULL term, borrowed pointers */
/* XXX: make active breakpoints actual copies instead of pointers? */
/* These are for rate limiting Status notifications and transport peeking. */
- duk_uint32_t dbg_exec_counter; /* cumulative opcode execution count (overflows are OK) */
- duk_uint32_t dbg_last_counter; /* value of dbg_exec_counter when we last did a Date-based check */
+ duk_uint_t dbg_exec_counter; /* cumulative opcode execution count (overflows are OK) */
+ duk_uint_t dbg_last_counter; /* value of dbg_exec_counter when we last did a Date-based check */
duk_double_t dbg_last_time; /* time when status/peek was last done (Date-based rate limit) */
/* Used to support single-byte stream lookahead. */
duk_bool_t dbg_have_next_byte;
duk_uint8_t dbg_next_byte;
+#endif /* DUK_USE_DEBUGGER_SUPPORT */
+#if defined(DUK_USE_ASSERTIONS)
+ duk_bool_t dbg_calling_transport; /* transport call in progress, calling into Duktape forbidden */
#endif
/* String intern table (weak refs). */
@@ -8478,6 +8753,51 @@ struct duk_heap {
duk_hstring *strs[DUK_HEAP_NUM_STRINGS];
#endif
#endif
+
+ /* Stats. */
+#if defined(DUK_USE_DEBUG)
+ duk_int_t stats_exec_opcodes;
+ duk_int_t stats_exec_interrupt;
+ duk_int_t stats_exec_throw;
+ duk_int_t stats_call_all;
+ duk_int_t stats_call_tailcall;
+ duk_int_t stats_call_ecmatoecma;
+ duk_int_t stats_safecall_all;
+ duk_int_t stats_safecall_nothrow;
+ duk_int_t stats_safecall_throw;
+ duk_int_t stats_ms_try_count;
+ duk_int_t stats_ms_skip_count;
+ duk_int_t stats_ms_emergency_count;
+ duk_int_t stats_strtab_intern_hit;
+ duk_int_t stats_strtab_intern_miss;
+ duk_int_t stats_strtab_resize_check;
+ duk_int_t stats_strtab_resize_grow;
+ duk_int_t stats_strtab_resize_shrink;
+ duk_int_t stats_object_realloc_props;
+ duk_int_t stats_object_abandon_array;
+ duk_int_t stats_getownpropdesc_count;
+ duk_int_t stats_getownpropdesc_hit;
+ duk_int_t stats_getownpropdesc_miss;
+ duk_int_t stats_getpropdesc_count;
+ duk_int_t stats_getpropdesc_hit;
+ duk_int_t stats_getpropdesc_miss;
+ duk_int_t stats_getprop_all;
+ duk_int_t stats_getprop_arrayidx;
+ duk_int_t stats_getprop_bufobjidx;
+ duk_int_t stats_getprop_bufferidx;
+ duk_int_t stats_getprop_bufferlen;
+ duk_int_t stats_getprop_stringidx;
+ duk_int_t stats_getprop_stringlen;
+ duk_int_t stats_getprop_proxy;
+ duk_int_t stats_getprop_arguments;
+ duk_int_t stats_putprop_all;
+ duk_int_t stats_putprop_arrayidx;
+ duk_int_t stats_putprop_bufobjidx;
+ duk_int_t stats_putprop_bufferidx;
+ duk_int_t stats_putprop_proxy;
+ duk_int_t stats_getvar_all;
+ duk_int_t stats_putvar_all;
+#endif
};
/*
@@ -8542,6 +8862,8 @@ DUK_INTERNAL_DECL void *duk_heap_mem_realloc(duk_heap *heap, void *ptr, duk_size
DUK_INTERNAL_DECL void *duk_heap_mem_realloc_indirect(duk_heap *heap, duk_mem_getptr cb, void *ud, duk_size_t newsize);
DUK_INTERNAL_DECL void duk_heap_mem_free(duk_heap *heap, void *ptr);
+DUK_INTERNAL_DECL void duk_heap_free_freelists(duk_heap *heap);
+
#if defined(DUK_USE_FINALIZER_SUPPORT)
DUK_INTERNAL_DECL void duk_heap_run_finalizer(duk_heap *heap, duk_hobject *obj);
DUK_INTERNAL_DECL void duk_heap_process_finalize_list(duk_heap *heap);
@@ -8628,8 +8950,8 @@ DUK_INTERNAL_DECL duk_uint32_t duk_heap_hashstring(duk_heap *heap, const duk_uin
/* The low 8 bits map directly to duk_hobject.h DUK_PROPDESC_FLAG_xxx.
* The remaining flags are specific to the debugger.
*/
-#define DUK_DBG_PROPFLAG_SYMBOL (1 << 8)
-#define DUK_DBG_PROPFLAG_HIDDEN (1 << 9)
+#define DUK_DBG_PROPFLAG_SYMBOL (1U << 8)
+#define DUK_DBG_PROPFLAG_HIDDEN (1U << 9)
#if defined(DUK_USE_DEBUGGER_SUPPORT)
DUK_INTERNAL_DECL void duk_debug_do_detach(duk_heap *heap);
@@ -8700,7 +9022,7 @@ DUK_INTERNAL_DECL duk_bool_t duk_debug_is_attached(duk_heap *heap);
DUK_INTERNAL_DECL duk_bool_t duk_debug_is_paused(duk_heap *heap);
DUK_INTERNAL_DECL void duk_debug_set_paused(duk_heap *heap);
DUK_INTERNAL_DECL void duk_debug_clear_paused(duk_heap *heap);
-DUK_INTERNAL_DECL void duk_debug_clear_step_state(duk_heap *heap);
+DUK_INTERNAL_DECL void duk_debug_clear_pause_state(duk_heap *heap);
#endif /* DUK_USE_DEBUGGER_SUPPORT */
#endif /* DUK_DEBUGGER_H_INCLUDED */
@@ -9063,6 +9385,10 @@ DUK_INTERNAL_DECL duk_bool_t duk_fb_is_full(duk_fixedbuffer *fb);
#define DUK_ERROR_INTERNAL(thr) do { \
duk_err_error_internal((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \
} while (0)
+#define DUK_DCERROR_INTERNAL(thr) do { \
+ DUK_ERROR_INTERNAL((thr)); \
+ return 0; \
+ } while (0)
#define DUK_ERROR_ALLOC_FAILED(thr) do { \
duk_err_error_alloc_failed((thr), DUK_FILE_MACRO, (duk_int_t) DUK_LINE_MACRO); \
} while (0)
@@ -9088,6 +9414,10 @@ DUK_INTERNAL_DECL duk_bool_t duk_fb_is_full(duk_fixedbuffer *fb);
#define DUK_ERROR_RANGE_INVALID_COUNT(thr) do { \
DUK_ERROR_RANGE((thr), DUK_STR_INVALID_COUNT); \
} while (0)
+#define DUK_DCERROR_RANGE_INVALID_COUNT(thr) do { \
+ DUK_ERROR_RANGE_INVALID_COUNT((thr)); \
+ return 0; \
+ } while (0)
#define DUK_ERROR_RANGE_INVALID_LENGTH(thr) do { \
DUK_ERROR_RANGE((thr), DUK_STR_INVALID_LENGTH); \
} while (0)
@@ -9143,6 +9473,10 @@ DUK_INTERNAL_DECL duk_bool_t duk_fb_is_full(duk_fixedbuffer *fb);
#define DUK_ERROR_INTERNAL(thr) do { \
duk_err_error((thr)); \
} while (0)
+#define DUK_DCERROR_INTERNAL(thr) do { \
+ DUK_UNREF((thr)); \
+ return DUK_RET_ERROR; \
+ } while (0)
#define DUK_ERROR_ALLOC_FAILED(thr) do { \
duk_err_error((thr)); \
} while (0)
@@ -9168,6 +9502,10 @@ DUK_INTERNAL_DECL duk_bool_t duk_fb_is_full(duk_fixedbuffer *fb);
#define DUK_ERROR_RANGE_INVALID_COUNT(thr) do { \
duk_err_range((thr)); \
} while (0)
+#define DUK_DCERROR_RANGE_INVALID_COUNT(thr) do { \
+ DUK_UNREF((thr)); \
+ return DUK_RET_RANGE_ERROR; \
+ } while (0)
#define DUK_ERROR_RANGE_INVALID_LENGTH(thr) do { \
duk_err_range((thr)); \
} while (0)
@@ -9293,6 +9631,19 @@ DUK_INTERNAL_DECL duk_bool_t duk_fb_is_full(duk_fixedbuffer *fb);
DUK_ASSERT(thr->valstack_top < thr->valstack_end)
/*
+ * Helper to initialize a memory area (e.g. struct) with garbage when
+ * assertions enabled.
+ */
+
+#if defined(DUK_USE_ASSERTIONS)
+#define DUK_ASSERT_SET_GARBAGE(ptr,size) do { \
+ DUK_MEMSET((void *) (ptr), 0x5a, size); \
+ } while (0)
+#else
+#define DUK_ASSERT_SET_GARBAGE(ptr,size) do {} while (0)
+#endif
+
+/*
* Helper for valstack space
*
* Caller of DUK_ASSERT_VALSTACK_SPACE() estimates the number of free stack entries
@@ -9331,8 +9682,11 @@ DUK_NORETURN(DUK_INTERNAL_DECL void duk_err_create_and_throw(duk_hthread *thr, d
DUK_NORETURN(DUK_INTERNAL_DECL void duk_error_throw_from_negative_rc(duk_hthread *thr, duk_ret_t rc));
+#define DUK_AUGMENT_FLAG_NOBLAME_FILELINE (1U << 0) /* if set, don't blame C file/line for .fileName and .lineNumber */
+#define DUK_AUGMENT_FLAG_SKIP_ONE (1U << 1) /* if set, skip topmost activation in traceback construction */
+
#if defined(DUK_USE_AUGMENT_ERROR_CREATE)
-DUK_INTERNAL_DECL void duk_err_augment_error_create(duk_hthread *thr, duk_hthread *thr_callstack, const char *filename, duk_int_t line, duk_bool_t noblame_fileline);
+DUK_INTERNAL_DECL void duk_err_augment_error_create(duk_hthread *thr, duk_hthread *thr_callstack, const char *filename, duk_int_t line, duk_small_uint_t flags);
#endif
#if defined(DUK_USE_AUGMENT_ERROR_THROW)
DUK_INTERNAL_DECL void duk_err_augment_error_throw(duk_hthread *thr);
@@ -9613,6 +9967,17 @@ extern const duk_uint8_t duk_unicode_caseconv_lc[680];
extern const duk_uint16_t duk_unicode_re_canon_lookup[65536];
#endif
+#if defined(DUK_USE_REGEXP_CANON_BITMAP)
+/*
+ * Automatically generated by extract_caseconv.py, do not edit!
+ */
+
+#define DUK_CANON_BITMAP_BLKSIZE 32
+#define DUK_CANON_BITMAP_BLKSHIFT 5
+#define DUK_CANON_BITMAP_BLKMASK 31
+extern const duk_uint8_t duk_unicode_re_canon_bitmap[256];
+#endif
+
/*
* Extern
*/
@@ -9663,10 +10028,10 @@ DUK_INTERNAL_DECL duk_small_int_t duk_unicode_re_is_wordchar(duk_codepoint_t cp)
#define DUK_JSON_H_INCLUDED
/* Encoding/decoding flags */
-#define DUK_JSON_FLAG_ASCII_ONLY (1 << 0) /* escape any non-ASCII characters */
-#define DUK_JSON_FLAG_AVOID_KEY_QUOTES (1 << 1) /* avoid key quotes when key is an ASCII Identifier */
-#define DUK_JSON_FLAG_EXT_CUSTOM (1 << 2) /* extended types: custom encoding */
-#define DUK_JSON_FLAG_EXT_COMPATIBLE (1 << 3) /* extended types: compatible encoding */
+#define DUK_JSON_FLAG_ASCII_ONLY (1U << 0) /* escape any non-ASCII characters */
+#define DUK_JSON_FLAG_AVOID_KEY_QUOTES (1U << 1) /* avoid key quotes when key is an ASCII Identifier */
+#define DUK_JSON_FLAG_EXT_CUSTOM (1U << 2) /* extended types: custom encoding */
+#define DUK_JSON_FLAG_EXT_COMPATIBLE (1U << 3) /* extended types: compatible encoding */
/* How much stack to require on entry to object/array encode */
#define DUK_JSON_ENC_REQSTACK 32
@@ -9693,8 +10058,8 @@ typedef struct {
duk_small_uint_t flag_ext_compatible;
duk_small_uint_t flag_ext_custom_or_compatible;
#endif
- duk_int_t recursion_depth;
- duk_int_t recursion_limit;
+ duk_uint_t recursion_depth;
+ duk_uint_t recursion_limit;
duk_uint_t mask_for_undefined; /* type bit mask: types which certainly produce 'undefined' */
#if defined(DUK_USE_JX) || defined(DUK_USE_JC)
duk_small_uint_t stridx_custom_undefined;
@@ -9731,20 +10096,22 @@ typedef struct {
#if !defined(DUK_JS_H_INCLUDED)
#define DUK_JS_H_INCLUDED
-/* Flags for call handling. */
-#define DUK_CALL_FLAG_IGNORE_RECLIMIT (1 << 0) /* duk_handle_call_xxx: call ignores C recursion limit (for errhandler calls) */
-#define DUK_CALL_FLAG_CONSTRUCTOR_CALL (1 << 1) /* duk_handle_call_xxx: constructor call (i.e. called as 'new Foo()') */
-#define DUK_CALL_FLAG_IS_RESUME (1 << 2) /* duk_handle_ecma_call_setup: setup for a resume() */
-#define DUK_CALL_FLAG_IS_TAILCALL (1 << 3) /* duk_handle_ecma_call_setup: setup for a tail call */
-#define DUK_CALL_FLAG_DIRECT_EVAL (1 << 4) /* call is a direct eval call */
+/* Flags for call handling. Lowest flags must match bytecode DUK_BC_CALL_FLAG_xxx 1:1. */
+#define DUK_CALL_FLAG_TAILCALL (1U << 0) /* setup for a tail call */
+#define DUK_CALL_FLAG_CONSTRUCT (1U << 1) /* constructor call (i.e. called as 'new Foo()') */
+#define DUK_CALL_FLAG_CALLED_AS_EVAL (1U << 2) /* call was made using the identifier 'eval' */
+#define DUK_CALL_FLAG_ALLOW_ECMATOECMA (1U << 3) /* ecma-to-ecma call with executor reuse is possible */
+#define DUK_CALL_FLAG_DIRECT_EVAL (1U << 4) /* call is a direct eval call */
+#define DUK_CALL_FLAG_CONSTRUCT_PROXY (1U << 5) /* handled via 'construct' proxy trap, check return value invariant(s) */
+#define DUK_CALL_FLAG_DEFAULT_INSTANCE_UPDATED (1U << 6) /* prototype of 'default instance' updated, temporary flag in call handling */
/* Flags for duk_js_equals_helper(). */
-#define DUK_EQUALS_FLAG_SAMEVALUE (1 << 0) /* use SameValue instead of non-strict equality */
-#define DUK_EQUALS_FLAG_STRICT (1 << 1) /* use strict equality instead of non-strict equality */
+#define DUK_EQUALS_FLAG_SAMEVALUE (1U << 0) /* use SameValue instead of non-strict equality */
+#define DUK_EQUALS_FLAG_STRICT (1U << 1) /* use strict equality instead of non-strict equality */
/* Flags for duk_js_compare_helper(). */
-#define DUK_COMPARE_FLAG_NEGATE (1 << 0) /* negate result */
-#define DUK_COMPARE_FLAG_EVAL_LEFT_FIRST (1 << 1) /* eval left argument first */
+#define DUK_COMPARE_FLAG_NEGATE (1U << 0) /* negate result */
+#define DUK_COMPARE_FLAG_EVAL_LEFT_FIRST (1U << 1) /* eval left argument first */
/* conversions, coercions, comparison, etc */
DUK_INTERNAL_DECL duk_bool_t duk_js_toboolean(duk_tval *tv);
@@ -9759,13 +10126,13 @@ DUK_INTERNAL_DECL duk_uarridx_t duk_js_to_arrayindex_string(const duk_uint8_t *s
DUK_INTERNAL_DECL duk_uarridx_t duk_js_to_arrayindex_hstring_fast_known(duk_hstring *h);
DUK_INTERNAL_DECL duk_uarridx_t duk_js_to_arrayindex_hstring_fast(duk_hstring *h);
#endif
-DUK_INTERNAL_DECL duk_bool_t duk_js_equals_helper(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_int_t flags);
+DUK_INTERNAL_DECL duk_bool_t duk_js_equals_helper(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_t flags);
DUK_INTERNAL_DECL duk_small_int_t duk_js_data_compare(const duk_uint8_t *buf1, const duk_uint8_t *buf2, duk_size_t len1, duk_size_t len2);
DUK_INTERNAL_DECL duk_small_int_t duk_js_string_compare(duk_hstring *h1, duk_hstring *h2);
#if 0 /* unused */
DUK_INTERNAL_DECL duk_small_int_t duk_js_buffer_compare(duk_heap *heap, duk_hbuffer *h1, duk_hbuffer *h2);
#endif
-DUK_INTERNAL_DECL duk_bool_t duk_js_compare_helper(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_int_t flags);
+DUK_INTERNAL_DECL duk_bool_t duk_js_compare_helper(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y, duk_small_uint_t flags);
DUK_INTERNAL_DECL duk_bool_t duk_js_instanceof(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y);
DUK_INTERNAL_DECL duk_bool_t duk_js_in(duk_hthread *thr, duk_tval *tv_x, duk_tval *tv_y);
DUK_INTERNAL_DECL duk_small_uint_t duk_js_typeof_stridx(duk_tval *tv_x);
@@ -9809,22 +10176,24 @@ DUK_INTERNAL_DECL void duk_js_putvar_activation(duk_hthread *thr, duk_activation
DUK_INTERNAL_DECL duk_bool_t duk_js_delvar_envrec(duk_hthread *thr, duk_hobject *env, duk_hstring *name);
#endif
DUK_INTERNAL_DECL duk_bool_t duk_js_delvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name);
-DUK_INTERNAL_DECL duk_bool_t duk_js_declvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name, duk_tval *val, duk_small_int_t prop_flags, duk_bool_t is_func_decl);
+DUK_INTERNAL_DECL duk_bool_t duk_js_declvar_activation(duk_hthread *thr, duk_activation *act, duk_hstring *name, duk_tval *val, duk_small_uint_t prop_flags, duk_bool_t is_func_decl);
DUK_INTERNAL_DECL void duk_js_init_activation_environment_records_delayed(duk_hthread *thr, duk_activation *act);
DUK_INTERNAL_DECL void duk_js_close_environment_record(duk_hthread *thr, duk_hobject *env);
-DUK_INTERNAL_DECL duk_hobject *duk_create_activation_environment_record(duk_hthread *thr, duk_hobject *func, duk_size_t idx_bottom);
-DUK_INTERNAL_DECL
-void duk_js_push_closure(duk_hthread *thr,
- duk_hcompfunc *fun_temp,
- duk_hobject *outer_var_env,
- duk_hobject *outer_lex_env,
- duk_bool_t add_auto_proto);
+DUK_INTERNAL_DECL duk_hobject *duk_create_activation_environment_record(duk_hthread *thr, duk_hobject *func, duk_size_t bottom_byteoff);
+DUK_INTERNAL_DECL void duk_js_push_closure(duk_hthread *thr,
+ duk_hcompfunc *fun_temp,
+ duk_hobject *outer_var_env,
+ duk_hobject *outer_lex_env,
+ duk_bool_t add_auto_proto);
/* call handling */
-DUK_INTERNAL_DECL duk_int_t duk_handle_call_protected(duk_hthread *thr, duk_idx_t num_stack_args, duk_small_uint_t call_flags);
-DUK_INTERNAL_DECL void duk_handle_call_unprotected(duk_hthread *thr, duk_idx_t num_stack_args, duk_small_uint_t call_flags);
+DUK_INTERNAL_DECL duk_int_t duk_handle_call_unprotected(duk_hthread *thr, duk_idx_t idx_func, duk_small_uint_t call_flags);
+DUK_INTERNAL_DECL duk_int_t duk_handle_call_unprotected_nargs(duk_hthread *thr, duk_idx_t nargs, duk_small_uint_t call_flags);
DUK_INTERNAL_DECL duk_int_t duk_handle_safe_call(duk_hthread *thr, duk_safe_call_function func, void *udata, duk_idx_t num_stack_args, duk_idx_t num_stack_res);
-DUK_INTERNAL_DECL duk_bool_t duk_handle_ecma_call_setup(duk_hthread *thr, duk_idx_t num_stack_args, duk_small_uint_t call_flags);
+DUK_INTERNAL_DECL void duk_call_construct_postprocess(duk_hthread *thr, duk_small_uint_t proxy_invariant);
+#if defined(DUK_USE_VERBOSE_ERRORS)
+DUK_INTERNAL_DECL void duk_call_setup_propcall_error(duk_hthread *thr, duk_tval *tv_targ, duk_tval *tv_base, duk_tval *tv_key);
+#endif
/* bytecode execution */
DUK_INTERNAL_DECL void duk_js_execute_bytecode(duk_hthread *exec_thr);
@@ -9842,23 +10211,23 @@ DUK_INTERNAL_DECL void duk_js_execute_bytecode(duk_hthread *exec_thr);
/* Output a specified number of digits instead of using the shortest
* form. Used for toPrecision() and toFixed().
*/
-#define DUK_N2S_FLAG_FIXED_FORMAT (1 << 0)
+#define DUK_N2S_FLAG_FIXED_FORMAT (1U << 0)
/* Force exponential format. Used for toExponential(). */
-#define DUK_N2S_FLAG_FORCE_EXP (1 << 1)
+#define DUK_N2S_FLAG_FORCE_EXP (1U << 1)
/* If number would need zero padding (for whole number part), use
* exponential format instead. E.g. if input number is 12300, 3
* digits are generated ("123"), output "1.23e+4" instead of "12300".
* Used for toPrecision().
*/
-#define DUK_N2S_FLAG_NO_ZERO_PAD (1 << 2)
+#define DUK_N2S_FLAG_NO_ZERO_PAD (1U << 2)
/* Digit count indicates number of fractions (i.e. an absolute
* digit index instead of a relative one). Used together with
* DUK_N2S_FLAG_FIXED_FORMAT for toFixed().
*/
-#define DUK_N2S_FLAG_FRACTION_DIGITS (1 << 3)
+#define DUK_N2S_FLAG_FRACTION_DIGITS (1U << 3)
/*
* String-to-number conversion
@@ -9871,64 +10240,64 @@ DUK_INTERNAL_DECL void duk_js_execute_bytecode(duk_hthread *exec_thr);
#define DUK_S2N_MAX_EXPONENT 1000000000
/* Trim white space (= allow leading and trailing whitespace) */
-#define DUK_S2N_FLAG_TRIM_WHITE (1 << 0)
+#define DUK_S2N_FLAG_TRIM_WHITE (1U << 0)
/* Allow exponent */
-#define DUK_S2N_FLAG_ALLOW_EXP (1 << 1)
+#define DUK_S2N_FLAG_ALLOW_EXP (1U << 1)
/* Allow trailing garbage (e.g. treat "123foo" as "123) */
-#define DUK_S2N_FLAG_ALLOW_GARBAGE (1 << 2)
+#define DUK_S2N_FLAG_ALLOW_GARBAGE (1U << 2)
/* Allow leading plus sign */
-#define DUK_S2N_FLAG_ALLOW_PLUS (1 << 3)
+#define DUK_S2N_FLAG_ALLOW_PLUS (1U << 3)
/* Allow leading minus sign */
-#define DUK_S2N_FLAG_ALLOW_MINUS (1 << 4)
+#define DUK_S2N_FLAG_ALLOW_MINUS (1U << 4)
/* Allow 'Infinity' */
-#define DUK_S2N_FLAG_ALLOW_INF (1 << 5)
+#define DUK_S2N_FLAG_ALLOW_INF (1U << 5)
/* Allow fraction part */
-#define DUK_S2N_FLAG_ALLOW_FRAC (1 << 6)
+#define DUK_S2N_FLAG_ALLOW_FRAC (1U << 6)
/* Allow naked fraction (e.g. ".123") */
-#define DUK_S2N_FLAG_ALLOW_NAKED_FRAC (1 << 7)
+#define DUK_S2N_FLAG_ALLOW_NAKED_FRAC (1U << 7)
/* Allow empty fraction (e.g. "123.") */
-#define DUK_S2N_FLAG_ALLOW_EMPTY_FRAC (1 << 8)
+#define DUK_S2N_FLAG_ALLOW_EMPTY_FRAC (1U << 8)
/* Allow empty string to be interpreted as 0 */
-#define DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO (1 << 9)
+#define DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO (1U << 9)
/* Allow leading zeroes (e.g. "0123" -> "123") */
-#define DUK_S2N_FLAG_ALLOW_LEADING_ZERO (1 << 10)
+#define DUK_S2N_FLAG_ALLOW_LEADING_ZERO (1U << 10)
/* Allow automatic detection of hex base ("0x" or "0X" prefix),
* overrides radix argument and forces integer mode.
*/
-#define DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT (1 << 11)
+#define DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT (1U << 11)
/* Allow automatic detection of legacy octal base ("0n"),
* overrides radix argument and forces integer mode.
*/
-#define DUK_S2N_FLAG_ALLOW_AUTO_LEGACY_OCT_INT (1 << 12)
+#define DUK_S2N_FLAG_ALLOW_AUTO_LEGACY_OCT_INT (1U << 12)
/* Allow automatic detection of ES2015 octal base ("0o123"),
* overrides radix argument and forces integer mode.
*/
-#define DUK_S2N_FLAG_ALLOW_AUTO_OCT_INT (1 << 13)
+#define DUK_S2N_FLAG_ALLOW_AUTO_OCT_INT (1U << 13)
/* Allow automatic detection of ES2015 binary base ("0b10001"),
* overrides radix argument and forces integer mode.
*/
-#define DUK_S2N_FLAG_ALLOW_AUTO_BIN_INT (1 << 14)
+#define DUK_S2N_FLAG_ALLOW_AUTO_BIN_INT (1U << 14)
/*
* Prototypes
*/
-DUK_INTERNAL_DECL void duk_numconv_stringify(duk_context *ctx, duk_small_int_t radix, duk_small_int_t digits, duk_small_uint_t flags);
-DUK_INTERNAL_DECL void duk_numconv_parse(duk_context *ctx, duk_small_int_t radix, duk_small_uint_t flags);
+DUK_INTERNAL_DECL void duk_numconv_stringify(duk_hthread *thr, duk_small_int_t radix, duk_small_int_t digits, duk_small_uint_t flags);
+DUK_INTERNAL_DECL void duk_numconv_parse(duk_hthread *thr, duk_small_int_t radix, duk_small_uint_t flags);
#endif /* DUK_NUMCONV_H_INCLUDED */
/* #include duk_bi_protos.h */
@@ -9957,13 +10326,16 @@ DUK_INTERNAL_DECL duk_bool_t duk_bi_date_year_in_valid_range(duk_double_t year);
DUK_INTERNAL_DECL duk_bool_t duk_bi_date_timeval_in_leeway_range(duk_double_t x);
/* Built-in providers */
#if defined(DUK_USE_DATE_NOW_GETTIMEOFDAY)
-DUK_INTERNAL_DECL duk_double_t duk_bi_date_get_now_gettimeofday(duk_context *ctx);
+DUK_INTERNAL_DECL duk_double_t duk_bi_date_get_now_gettimeofday(void);
#endif
#if defined(DUK_USE_DATE_NOW_TIME)
-DUK_INTERNAL_DECL duk_double_t duk_bi_date_get_now_time(duk_context *ctx);
+DUK_INTERNAL_DECL duk_double_t duk_bi_date_get_now_time(void);
#endif
#if defined(DUK_USE_DATE_NOW_WINDOWS)
-DUK_INTERNAL_DECL duk_double_t duk_bi_date_get_now_windows(duk_context *ctx);
+DUK_INTERNAL_DECL duk_double_t duk_bi_date_get_now_windows(void);
+#endif
+#if defined(DUK_USE_DATE_NOW_WINDOWS_SUBMS)
+DUK_INTERNAL_DECL duk_double_t duk_bi_date_get_now_windows_subms(void);
#endif
#if defined(DUK_USE_DATE_TZO_GMTIME_R) || defined(DUK_USE_DATE_TZO_GMTIME_S) || defined(DUK_USE_DATE_TZO_GMTIME)
DUK_INTERNAL_DECL duk_int_t duk_bi_date_get_local_tzoffset_gmtime(duk_double_t d);
@@ -9975,31 +10347,38 @@ DUK_INTERNAL_DECL duk_int_t duk_bi_date_get_local_tzoffset_windows(duk_double_t
DUK_INTERNAL_DECL duk_int_t duk_bi_date_get_local_tzoffset_windows_no_dst(duk_double_t d);
#endif
#if defined(DUK_USE_DATE_PRS_STRPTIME)
-DUK_INTERNAL_DECL duk_bool_t duk_bi_date_parse_string_strptime(duk_context *ctx, const char *str);
+DUK_INTERNAL_DECL duk_bool_t duk_bi_date_parse_string_strptime(duk_hthread *thr, const char *str);
#endif
#if defined(DUK_USE_DATE_PRS_GETDATE)
-DUK_INTERNAL_DECL duk_bool_t duk_bi_date_parse_string_getdate(duk_context *ctx, const char *str);
+DUK_INTERNAL_DECL duk_bool_t duk_bi_date_parse_string_getdate(duk_hthread *thr, const char *str);
#endif
#if defined(DUK_USE_DATE_FMT_STRFTIME)
-DUK_INTERNAL_DECL duk_bool_t duk_bi_date_format_parts_strftime(duk_context *ctx, duk_int_t *parts, duk_int_t tzoffset, duk_small_uint_t flags);
+DUK_INTERNAL_DECL duk_bool_t duk_bi_date_format_parts_strftime(duk_hthread *thr, duk_int_t *parts, duk_int_t tzoffset, duk_small_uint_t flags);
+#endif
+
+#if defined(DUK_USE_GET_MONOTONIC_TIME_CLOCK_GETTIME)
+DUK_INTERNAL_DECL duk_double_t duk_bi_date_get_monotonic_time_clock_gettime(void);
+#endif
+#if defined(DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC)
+DUK_INTERNAL_DECL duk_double_t duk_bi_date_get_monotonic_time_windows_qpc(void);
#endif
DUK_INTERNAL_DECL
-void duk_bi_json_parse_helper(duk_context *ctx,
+void duk_bi_json_parse_helper(duk_hthread *thr,
duk_idx_t idx_value,
duk_idx_t idx_reviver,
duk_small_uint_t flags);
DUK_INTERNAL_DECL
-void duk_bi_json_stringify_helper(duk_context *ctx,
+void duk_bi_json_stringify_helper(duk_hthread *thr,
duk_idx_t idx_value,
duk_idx_t idx_replacer,
duk_idx_t idx_space,
duk_small_uint_t flags);
-DUK_INTERNAL_DECL duk_ret_t duk_textdecoder_decode_utf8_nodejs(duk_context *ctx);
+DUK_INTERNAL_DECL duk_ret_t duk_textdecoder_decode_utf8_nodejs(duk_hthread *thr);
#if defined(DUK_USE_ES6_PROXY)
-DUK_INTERNAL_DECL void duk_proxy_ownkeys_postprocess(duk_context *ctx, duk_hobject *h_proxy_target, duk_uint_t flags);
+DUK_INTERNAL_DECL void duk_proxy_ownkeys_postprocess(duk_hthread *thr, duk_hobject *h_proxy_target, duk_uint_t flags);
#endif
#endif /* DUK_BUILTIN_PROTOS_H_INCLUDED */
@@ -10200,7 +10579,7 @@ DUK_INTERNAL void duk_debug_log(const char *fmt, ...) {
#if defined(DUK_USE_ROM_STRINGS)
#error ROM support not enabled, rerun configure.py with --rom-support
#else /* DUK_USE_ROM_STRINGS */
-DUK_INTERNAL const duk_uint8_t duk_strings_data[903] = {
+DUK_INTERNAL const duk_uint8_t duk_strings_data[892] = {
79,40,209,144,168,105,6,78,54,139,89,185,44,48,46,90,120,8,154,140,35,103,
35,113,193,73,5,52,112,180,104,166,135,52,188,4,98,12,27,146,156,80,211,31,
129,115,150,64,52,220,109,24,18,68,156,24,38,67,114,36,55,9,119,151,132,
@@ -10221,38 +10600,37 @@ DUK_INTERNAL const duk_uint8_t duk_strings_data[903] = {
67,72,49,241,160,227,81,196,52,168,106,39,132,252,183,136,105,80,212,79,2,
249,110,128,126,88,95,133,109,237,237,237,151,235,127,46,249,119,203,190,
186,206,33,181,2,208,61,190,12,19,34,65,19,81,132,108,228,97,1,107,33,12,
-32,45,100,139,134,69,146,100,227,226,231,146,51,192,204,73,140,224,145,221,
-102,241,68,196,157,34,79,143,139,166,233,225,228,227,138,157,173,167,197,
-211,118,214,210,38,238,74,113,67,76,105,187,169,147,154,73,225,228,32,193,
-48,25,100,105,166,113,200,147,44,166,1,40,79,18,150,134,147,141,163,2,72,
-171,115,147,136,4,65,130,96,35,64,194,32,168,89,56,208,48,135,123,144,217,
-146,38,220,229,64,186,16,187,156,105,47,52,238,112,56,153,4,225,145,27,156,
-43,162,192,46,71,220,229,65,22,1,231,220,228,157,72,136,136,220,227,197,
-164,180,52,133,220,228,206,137,23,115,128,137,164,77,206,48,15,62,231,42,8,
-145,181,86,231,10,134,129,104,201,34,125,206,76,17,49,38,141,206,28,13,26,
-201,19,137,204,122,22,66,161,175,164,210,72,199,130,137,1,50,32,145,143,38,
-120,186,195,35,106,51,146,230,8,36,77,109,65,38,226,72,141,18,74,140,35,
-247,247,182,168,209,144,187,223,58,156,104,79,190,183,127,123,105,160,110,
-247,206,167,26,19,239,173,223,222,218,67,75,189,243,169,198,132,251,235,
-183,247,182,154,134,151,123,231,83,141,9,247,215,111,239,109,22,141,22,247,
-206,167,26,19,239,172,223,218,45,26,47,157,78,52,39,223,74,24,144,10,32,
-129,34,20,64,152,142,129,57,179,67,104,68,12,129,161,140,72,156,100,40,40,
-185,152,100,89,38,65,13,196,34,228,67,149,13,2,215,129,149,209,65,104,209,
-77,14,104,144,81,33,170,67,101,48,52,68,113,70,210,88,209,36,233,22,154,86,
-68,196,114,76,232,145,102,120,186,195,156,112,105,225,228,113,71,80,68,162,
-115,101,50,85,200,25,108,116,44,132,178,38,114,137,96,148,136,70,209,134,
-37,222,232,204,228,188,200,209,200,200,99,221,25,150,84,121,34,70,209,107,
-36,227,66,20,160,92,136,164,49,235,35,8,217,201,40,108,201,18,128,68,26,
-201,51,188,2,80,12,67,190,40,168,38,68,190,46,153,5,50,12,207,160,86,129,
-26,83,4,208,34,225,4,88,192,
+32,45,100,137,64,247,175,9,19,155,41,198,130,155,134,69,146,100,227,226,
+231,146,51,192,204,73,140,224,145,221,102,241,68,196,157,34,79,143,139,166,
+233,225,228,227,138,157,173,167,197,211,118,214,210,38,238,74,113,67,76,
+105,187,169,147,154,73,225,228,32,193,48,25,100,105,166,113,200,147,44,166,
+1,40,79,18,150,134,147,141,163,2,72,171,115,147,136,4,65,130,96,35,64,194,
+32,168,89,56,208,48,135,123,144,217,146,39,220,228,193,19,18,101,220,227,
+73,121,167,115,129,196,200,39,12,136,220,225,93,22,1,114,62,231,42,8,176,
+15,62,231,36,234,68,68,70,231,30,45,37,161,164,38,231,24,7,159,115,149,4,
+72,218,171,115,133,67,64,180,100,145,54,231,42,5,208,135,19,152,244,44,133,
+67,95,73,164,145,143,5,18,2,100,65,35,30,76,241,117,134,70,212,103,37,204,
+16,72,154,218,130,77,196,145,63,127,123,106,141,25,11,189,243,169,198,132,
+251,235,119,247,182,154,6,239,124,234,113,161,62,250,221,253,237,164,52,
+187,223,58,156,104,79,190,187,127,123,105,168,105,119,190,117,56,208,159,
+125,118,254,246,209,104,209,111,124,234,113,161,62,250,205,253,162,209,162,
+249,212,227,66,125,244,161,137,0,162,8,18,33,68,9,136,232,19,155,52,54,132,
+64,200,26,24,196,137,198,66,130,139,153,134,69,146,100,16,220,66,46,68,57,
+80,208,45,120,25,93,20,22,141,20,208,230,137,5,18,26,164,54,83,3,68,71,20,
+109,37,141,18,78,145,105,165,100,76,71,36,206,137,22,103,139,172,57,199,6,
+158,30,71,20,117,4,74,39,54,83,37,92,129,150,199,66,200,75,34,103,40,150,9,
+72,132,109,24,98,93,238,140,206,75,204,141,28,140,134,61,209,153,101,71,
+146,36,109,22,178,78,52,33,74,5,200,138,67,30,178,48,141,156,146,134,204,
+145,40,4,65,172,147,59,192,37,0,196,59,226,138,130,100,75,226,233,144,83,
+32,204,250,5,104,17,165,48,77,2,46,16,69,140,
};
#endif /* DUK_USE_ROM_STRINGS */
#if defined(DUK_USE_ROM_OBJECTS)
#error ROM support not enabled, rerun configure.py with --rom-support
#else /* DUK_USE_ROM_OBJECTS */
-/* native functions: 166 */
-DUK_INTERNAL const duk_c_function duk_bi_native_functions[166] = {
+/* native functions: 176 */
+DUK_INTERNAL const duk_c_function duk_bi_native_functions[176] = {
NULL,
duk_bi_array_constructor,
duk_bi_array_constructor_is_array,
@@ -10324,12 +10702,17 @@ DUK_INTERNAL const duk_c_function duk_bi_native_functions[166] = {
duk_bi_global_object_unescape,
duk_bi_json_object_parse,
duk_bi_json_object_stringify,
+ duk_bi_math_object_clz32,
duk_bi_math_object_hypot,
+ duk_bi_math_object_imul,
duk_bi_math_object_max,
duk_bi_math_object_min,
duk_bi_math_object_onearg_shared,
duk_bi_math_object_random,
+ duk_bi_math_object_sign,
duk_bi_math_object_twoarg_shared,
+ duk_bi_native_function_length,
+ duk_bi_native_function_name,
duk_bi_nodejs_buffer_byte_length,
duk_bi_nodejs_buffer_concat,
duk_bi_nodejs_buffer_constructor,
@@ -10360,16 +10743,21 @@ DUK_INTERNAL const duk_c_function duk_bi_native_functions[166] = {
duk_bi_object_constructor_prevent_extensions,
duk_bi_object_constructor_seal_freeze_shared,
duk_bi_object_getprototype_shared,
+ duk_bi_object_prototype_defineaccessor,
duk_bi_object_prototype_has_own_property,
duk_bi_object_prototype_is_prototype_of,
+ duk_bi_object_prototype_lookupaccessor,
duk_bi_object_prototype_property_is_enumerable,
duk_bi_object_prototype_to_locale_string,
duk_bi_object_prototype_to_string,
duk_bi_object_prototype_value_of,
duk_bi_object_setprototype_shared,
+ duk_bi_performance_now,
duk_bi_pointer_constructor,
duk_bi_pointer_prototype_tostring_shared,
duk_bi_proxy_constructor,
+ duk_bi_reflect_apply,
+ duk_bi_reflect_construct,
duk_bi_reflect_object_delete_property,
duk_bi_reflect_object_get,
duk_bi_reflect_object_has,
@@ -10421,541 +10809,556 @@ DUK_INTERNAL const duk_c_function duk_bi_native_functions[166] = {
duk_bi_uint8array_plainof,
};
#if defined(DUK_USE_DOUBLE_LE)
-DUK_INTERNAL const duk_uint8_t duk_builtins_data[3819] = {
-144,148,105,221,32,68,52,228,62,12,104,200,165,134,148,248,81,77,61,191,
-135,35,154,103,34,72,6,157,159,197,145,77,245,126,52,130,106,234,163,196,
-52,226,18,51,161,26,113,1,60,37,64,190,18,49,116,116,33,26,113,1,92,136,26,
-98,112,145,139,163,165,8,211,136,14,228,72,82,68,141,17,56,72,197,209,212,
-132,105,196,5,242,88,108,193,126,18,49,116,117,161,26,113,1,60,158,30,78,
-18,49,116,118,33,26,113,1,29,164,80,78,198,46,142,212,36,68,51,71,232,59,
-147,60,93,110,79,15,39,9,24,186,33,13,63,111,185,16,211,206,251,114,98,17,
-171,160,11,199,197,215,196,66,26,102,38,68,53,212,77,136,104,255,5,114,120,
-121,7,192,70,32,192,67,95,249,59,13,13,127,228,248,134,191,242,133,208,215,
-254,81,204,67,95,249,75,33,13,127,229,61,84,53,255,149,52,80,215,254,85,
-217,67,95,249,91,121,13,90,181,168,134,143,152,95,38,75,207,132,104,156,50,
-70,33,163,225,66,249,50,94,124,25,4,225,146,49,14,24,28,196,0,0,0,0,0,0,15,
-135,252,204,0,0,0,0,0,0,15,7,252,188,72,6,176,77,225,28,24,103,14,33,197,
-138,113,227,28,152,231,46,65,205,19,194,84,11,225,35,23,68,231,138,228,64,
-211,19,132,140,93,19,162,59,145,33,73,18,52,68,225,35,23,68,233,139,228,
-176,217,130,252,36,98,232,157,81,60,158,30,78,18,49,116,78,184,142,210,40,
-39,99,23,68,236,201,59,114,142,224,126,14,138,152,30,67,188,23,143,139,175,
-131,194,135,228,72,85,144,83,60,53,163,208,76,60,68,211,197,78,60,116,243,
-200,80,60,149,19,202,82,60,181,51,204,84,60,213,83,206,86,60,240,190,76,
-151,159,8,209,56,100,137,232,133,242,100,188,248,50,9,195,36,79,73,26,238,
-108,129,15,4,100,78,33,179,207,160,41,224,140,137,194,173,192,158,120,128,
-168,151,26,14,55,58,64,132,75,133,67,81,50,103,8,18,50,9,195,39,105,20,101,
-136,36,50,9,195,39,105,20,11,174,99,220,210,54,121,114,4,145,162,112,201,
-218,69,25,130,9,17,162,112,201,218,69,2,235,152,247,52,141,158,100,128,196,
-144,128,242,102,136,17,70,146,66,3,201,160,32,0,130,225,48,113,137,62,62,
-46,155,167,135,147,142,47,24,147,79,205,68,48,98,79,142,179,120,248,185,
-228,140,241,193,146,66,138,31,55,71,126,129,51,18,124,117,155,199,197,207,
-36,103,142,52,12,36,184,100,129,129,41,32,205,221,175,3,10,36,4,201,188,64,
-112,200,84,52,156,124,92,242,70,120,223,48,64,100,42,26,78,62,46,121,35,52,
-18,91,212,2,72,128,95,20,128,197,137,9,146,113,73,8,190,36,169,27,62,18,
-243,35,100,135,54,92,66,4,34,92,145,0,178,15,132,64,132,75,133,139,178,70,
-240,137,6,34,92,37,230,70,201,1,89,56,36,4,81,49,46,25,5,76,73,241,214,111,
-31,23,60,145,158,57,44,48,46,92,184,100,160,145,46,2,0,201,168,207,198,230,
-144,117,60,176,48,156,160,48,188,192,7,28,18,227,172,222,62,46,121,35,60,
-113,200,26,137,113,241,116,221,60,60,156,113,121,4,20,124,92,242,70,120,
-226,37,194,54,140,36,64,21,147,146,68,24,32,57,0,125,78,84,0,160,123,215,
-140,146,1,4,5,175,40,124,8,20,52,121,51,228,24,96,129,209,46,2,49,6,20,135,
-33,20,53,50,128,194,65,4,12,39,52,64,155,31,48,112,72,6,247,62,16,1,31,73,
-30,25,240,60,73,82,70,68,138,0,89,29,5,156,96,2,201,104,17,35,160,18,78,
-140,228,16,26,79,90,4,73,43,192,244,108,142,130,206,89,240,58,26,50,95,142,
-43,159,65,107,4,167,196,52,100,191,28,87,63,128,15,255,240,164,169,35,136,
-6,128,146,115,9,0,210,7,43,163,194,0,71,128,105,65,176,15,128,105,131,21,
-11,153,35,0,211,134,137,7,65,18,33,244,23,18,14,130,39,34,131,30,113,15,
-224,3,255,254,12,80,81,133,139,153,193,28,17,224,156,50,119,15,131,75,23,
-51,130,112,201,199,185,13,159,116,248,228,68,219,66,149,83,83,238,3,11,238,
-0,48,142,8,240,19,239,144,40,71,4,120,39,12,156,4,252,4,11,19,134,78,61,
-200,108,248,9,248,9,3,9,205,16,39,225,62,7,67,70,75,241,197,241,154,5,172,
-18,159,16,209,146,252,113,124,102,144,106,220,32,44,156,19,152,240,68,158,
-66,2,176,19,17,252,164,7,137,30,176,8,158,116,3,72,128,136,143,232,32,44,
-150,129,19,210,128,89,61,104,159,169,1,50,160,101,56,161,166,246,160,46,
-110,226,221,98,71,130,4,137,222,0,140,221,197,184,64,89,56,183,88,145,224,
-129,34,119,128,23,55,114,143,121,35,193,2,68,239,2,17,155,184,183,8,11,39,
-40,247,146,60,16,36,78,240,32,73,197,12,247,128,26,36,121,1,63,49,2,165,48,
-70,114,229,145,51,250,205,2,8,209,203,150,68,207,235,52,130,16,209,46,131,
-36,188,70,128,210,160,101,56,251,16,131,28,7,35,38,218,50,234,103,130,97,
-103,129,6,73,0,79,88,11,237,84,11,161,32,127,255,255,255,255,255,247,191,
-137,235,16,221,170,129,116,36,0,16,0,0,0,0,0,0,12,196,0,0,0,0,0,0,15,135,
-242,61,123,164,137,162,164,218,67,74,134,162,120,128,0,0,0,0,0,1,224,254,
-71,173,33,129,52,84,155,72,105,80,212,79,16,0,0,0,0,0,0,60,63,199,36,38,
-218,0,0,0,0,0,0,0,0,4,29,78,224,140,38,216,140,46,228,0,243,119,10,139,144,
-123,82,6,205,220,37,222,230,145,179,64,23,180,32,92,221,199,196,130,68,144,
-230,237,200,131,44,24,43,193,25,18,185,0,251,73,138,199,240,27,93,106,192,
-57,41,54,210,0,0,0,0,0,0,62,31,241,58,155,192,12,155,184,48,76,156,148,226,
-134,154,240,32,201,187,147,67,9,201,78,40,105,175,2,225,47,3,18,155,184,
-183,8,11,39,6,9,147,146,156,80,211,94,7,37,55,113,110,16,22,78,77,12,39,37,
-56,161,166,188,16,48,215,130,14,30,240,66,213,93,35,11,124,0,230,36,249,52,
-48,151,192,22,98,79,133,162,215,204,16,17,178,16,199,24,147,237,38,34,246,
-139,95,48,64,70,200,68,16,98,79,140,115,102,123,33,20,89,137,62,210,98,103,
-92,217,158,200,70,14,98,79,131,4,201,100,35,138,49,39,218,76,67,232,38,75,
-33,32,49,137,62,12,24,178,18,68,152,147,237,38,33,244,24,178,18,132,24,147,
-225,221,72,202,200,75,22,98,79,180,152,143,215,82,50,178,19,5,24,147,227,
-16,218,76,146,178,19,70,152,147,237,38,38,117,13,164,201,43,33,56,81,137,
-62,72,130,115,71,43,33,60,105,137,62,210,98,151,72,39,52,114,178,20,7,152,
-147,227,16,181,162,68,19,154,57,89,10,36,140,73,246,147,19,58,133,173,18,
-32,156,209,202,200,82,34,98,79,147,67,9,151,52,156,113,75,34,78,208,1,228,
-73,242,104,97,46,16,62,68,159,24,133,173,18,32,156,209,202,217,83,37,34,79,
-180,152,153,212,45,104,145,4,230,142,86,202,160,169,18,124,145,4,230,142,
-86,215,213,27,34,79,180,152,165,210,9,205,28,173,175,172,42,68,159,24,134,
-210,100,149,183,245,198,200,147,237,38,38,117,13,164,201,43,111,236,8,145,
-39,195,186,145,149,185,246,69,200,147,237,38,35,245,212,140,173,207,180,30,
-68,159,6,9,146,217,91,21,34,79,180,152,135,208,76,150,202,224,137,18,124,
-99,155,51,219,95,116,92,137,62,210,98,103,92,217,158,218,251,194,228,73,
-240,180,90,249,130,2,54,223,223,29,34,79,180,152,139,218,45,124,193,1,27,
-111,240,33,204,73,243,4,4,108,134,8,60,137,62,96,128,141,178,193,193,154,3,
-147,32,227,36,0,0,0,0,0,0,0,0,99,115,245,195,19,159,176,75,175,159,176,24,
-172,253,129,49,121,251,2,176,66,92,130,235,16,18,100,148,251,36,106,123,64,
-65,158,3,147,160,108,202,62,68,165,107,243,227,113,198,211,62,39,20,108,
-115,226,241,130,106,113,224,78,162,4,242,130,236,197,60,37,64,190,18,49,
-116,114,37,40,157,76,9,229,37,217,138,185,16,52,196,225,35,23,71,34,82,137,
-213,64,158,84,93,152,187,145,33,73,18,52,68,225,35,23,71,34,82,137,213,192,
-158,86,93,152,175,146,195,102,11,240,145,139,163,145,41,68,235,32,79,44,46,
-204,83,201,225,228,225,35,23,71,34,82,137,214,192,158,90,93,152,163,180,
-138,9,216,197,209,200,148,161,194,32,30,18,3,74,184,164,88,85,248,42,0,78,
-173,186,58,16,5,149,109,110,236,90,192,144,1,245,109,210,129,222,115,245,
-252,132,93,204,126,23,171,113,180,137,3,250,8,173,149,28,87,220,252,55,86,
-227,104,232,18,0,119,41,48,171,222,94,217,248,46,189,16,6,11,81,21,62,200,
-66,80,3,246,80,140,244,118,180,160,102,157,191,179,79,80,115,31,133,236,
-161,25,233,64,205,59,127,102,158,160,246,63,41,248,30,75,12,11,151,242,233,
-187,146,156,80,211,114,96,54,230,41,20,129,128,50,211,16,16,2,116,180,196,
-129,1,36,55,76,74,16,19,3,116,196,193,65,48,55,75,80,128,65,6,51,211,20,
-128,130,34,23,166,39,6,39,75,76,80,1,146,239,211,20,16,165,91,157,29,49,66,
-10,124,61,211,209,175,1,173,198,211,20,48,139,113,180,180,197,36,42,220,
-109,29,13,49,74,6,192,95,72,188,6,196,55,74,188,6,247,91,80,136,26,32,104,
-220,205,56,1,98,234,52,122,98,136,14,72,110,152,162,132,148,35,61,49,70,7,
-48,55,76,81,194,206,52,104,180,197,45,192,80,175,4,100,77,10,2,101,56,161,
-166,65,113,162,98,8,3,131,7,169,35,36,57,176,0,0,0,0,0,40,116,208,45,158,
-10,225,223,132,17,13,43,176,228,3,0,167,129,32,17,133,134,32,25,80,220,40,
-240,25,26,44,32,240,24,200,44,24,240,56,156,199,128,83,193,17,7,4,13,128,0,
-10,79,202,28,223,195,1,197,72,196,141,159,220,7,48,33,7,8,3,152,49,117,60,
-240,76,47,60,9,224,187,56,43,224,221,64,172,156,36,98,232,228,96,220,145,
-139,163,182,134,237,146,49,116,118,206,6,141,104,105,136,32,14,4,128,160,
-123,215,140,147,32,145,57,178,156,104,41,228,151,168,225,144,168,105,56,
-248,185,228,140,241,190,100,209,244,80,210,116,151,134,12,73,241,214,111,
-31,23,60,145,158,56,50,72,81,67,230,232,239,209,7,24,147,227,226,233,186,
-120,121,56,226,241,137,116,189,52,6,34,92,37,230,70,201,1,89,56,36,154,110,
-25,49,23,196,149,35,103,194,94,100,108,144,230,203,136,73,174,234,63,52,
-252,212,87,0,131,138,4,12,137,114,168,37,166,144,230,37,5,7,19,39,22,70,
-154,103,143,252,4,11,37,160,68,164,139,7,24,3,152,182,20,28,76,156,89,26,
-105,158,63,240,5,7,19,39,28,82,200,147,143,253,0,193,161,74,72,199,253,132,
-176,230,36,248,134,207,98,138,99,4,24,147,229,16,217,236,81,75,98,12,73,
-241,13,158,142,181,20,198,137,49,39,202,33,179,209,214,162,151,4,24,147,
-226,27,61,61,42,41,142,18,98,79,148,67,103,167,165,69,46,138,49,39,194,173,
-192,158,158,149,20,188,40,196,159,10,183,2,122,218,148,82,248,121,18,124,
-67,103,177,77,177,130,36,73,242,136,108,246,41,181,177,18,36,248,134,207,
-71,90,155,99,68,200,147,229,16,217,232,235,83,107,130,36,73,241,13,158,158,
-149,54,199,9,145,39,202,33,179,211,210,166,215,69,72,147,225,86,224,79,79,
-74,155,94,21,34,79,133,91,129,61,109,74,109,126,14,56,7,6,20,28,76,156,89,
-26,105,158,63,240,5,7,19,39,28,82,200,147,143,253,0,193,161,74,72,199,253,
-130,235,191,232,8,149,2,8,196,24,164,137,141,200,8,71,161,196,201,45,167,
-146,59,68,89,24,70,206,0,0,0,0,0,0,7,129,249,142,49,232,71,161,196,201,45,
-167,146,59,68,89,24,70,206,0,0,0,0,0,0,7,129,249,141,201,8,71,161,196,201,
-45,167,146,59,68,89,24,70,206,0,0,0,0,0,0,7,129,250,138,2,214,225,113,235,
-2,27,128,0,10,66,3,189,96,67,120,226,224,0,2,148,140,113,145,66,61,14,38,
-73,109,60,145,218,34,200,194,54,112,0,0,0,0,0,0,60,15,204,110,80,66,61,14,
-38,73,109,60,145,218,34,200,194,54,112,0,0,0,0,0,0,60,15,204,113,147,66,61,
-14,38,73,109,60,145,218,34,200,194,54,112,0,0,0,0,0,0,60,15,204,110,88,66,
-61,14,38,73,109,60,145,218,34,200,194,54,112,0,0,0,0,0,0,0,16,12,113,149,
-66,61,14,38,73,109,60,145,218,34,200,194,54,112,0,0,0,0,0,0,0,16,12,110,96,
-66,61,14,38,73,109,60,145,218,34,200,194,54,112,0,0,0,0,0,0,0,16,12,113,
-151,66,61,14,38,73,109,60,145,218,34,200,194,54,112,0,0,0,0,0,0,0,16,12,
-110,104,66,61,14,38,73,109,60,145,218,34,200,194,54,112,0,0,0,0,0,0,4,16,
-12,113,153,66,61,14,38,73,109,60,145,218,34,200,194,54,112,0,0,0,0,0,0,4,
-16,12,110,112,66,61,14,38,73,109,60,145,218,34,200,194,54,112,0,0,0,0,0,0,
-4,16,12,113,155,66,61,14,38,73,109,60,145,218,34,200,194,54,112,0,0,0,0,0,
-0,4,16,12,110,120,66,61,14,38,73,109,60,145,218,34,200,194,54,112,0,0,0,0,
-0,0,4,16,12,113,157,66,61,14,38,73,109,60,145,218,34,200,194,54,112,0,0,0,
-0,0,0,4,16,12,110,128,66,61,14,38,73,109,60,145,218,34,200,194,54,112,0,0,
-0,0,0,0,8,16,12,113,159,66,61,14,38,73,109,60,145,218,34,200,194,54,112,0,
-0,0,0,0,0,8,16,8,58,32,128,24,78,104,129,61,82,2,145,46,17,162,112,208,211,
-107,200,16,137,112,52,41,73,29,113,2,131,137,147,139,35,77,51,234,80,14,39,
-49,224,137,40,35,100,141,9,136,19,18,0,125,162,58,217,236,81,64,68,72,1,
-241,13,158,197,20,150,50,36,0,251,68,117,179,209,214,234,201,69,16,100,72,
-1,246,136,235,103,163,173,208,146,138,68,23,18,0,124,67,103,163,173,213,
-146,138,76,23,18,0,124,67,103,163,173,208,146,138,84,25,18,0,125,162,58,
-217,233,233,117,100,162,138,50,36,0,251,68,117,179,211,210,232,73,69,34,
-139,137,0,62,33,179,211,210,234,201,69,38,139,137,0,62,33,179,211,210,232,
-73,69,42,139,137,0,62,21,110,4,250,178,81,70,23,18,0,124,42,220,9,244,36,
-162,145,134,68,128,31,6,234,5,100,234,201,69,28,100,72,1,240,110,160,86,78,
-132,148,82,56,168,144,3,237,17,214,207,171,37,22,128,42,36,0,251,68,117,
-179,232,73,69,164,9,137,0,62,33,179,234,201,69,168,9,137,0,62,33,179,232,
-73,69,172,10,180,81,50,118,136,235,103,177,77,129,54,138,38,78,33,179,216,
-166,210,198,218,40,153,59,68,117,179,209,214,234,201,77,144,109,162,137,
-147,180,71,91,61,29,110,132,148,218,32,203,69,19,39,16,217,232,235,117,100,
-166,211,6,90,40,153,56,134,207,71,91,161,37,54,168,54,209,68,201,218,35,
-173,158,158,151,86,74,108,163,109,20,76,157,162,58,217,233,233,116,36,166,
-209,70,90,40,153,56,134,207,79,75,171,37,54,154,50,209,68,201,196,54,122,
-122,93,9,41,181,81,150,138,38,78,21,110,4,250,178,83,102,25,104,162,100,
-225,86,224,79,161,37,54,140,54,209,68,201,193,186,129,89,58,178,83,103,27,
-104,162,100,224,221,64,172,157,9,41,180,113,118,138,38,78,209,29,108,250,
-178,83,136,2,237,20,76,157,162,58,217,244,36,167,18,5,90,40,153,56,134,207,
-171,37,56,160,42,209,68,201,196,54,125,9,41,197,141,78,197,141,86,192,0,
-133,66,215,173,96,49,33,64,46,84,8,14,39,49,224,137,40,18,4,19,159,141,100,
-1,100,180,8,148,146,0,91,69,19,38,202,8,58,64,28,209,160,130,52,78,26,26,
-110,255,80,64,196,104,156,50,125,4,144,116,192,57,165,97,4,104,156,52,52,
-221,254,64,20,160,152,23,223,228,32,148,25,174,137,58,23,51,191,200,84,12,
-50,9,195,39,196,80,
+DUK_INTERNAL const duk_uint8_t duk_builtins_data[3972] = {
+144,148,105,223,160,68,52,228,62,12,104,200,165,132,52,167,194,138,105,242,
+252,57,28,211,57,18,64,52,238,62,44,138,111,171,241,164,19,87,125,30,33,
+167,16,145,159,8,211,136,9,225,42,5,240,145,139,163,163,8,211,136,10,228,
+64,211,19,132,140,93,29,56,70,156,64,119,34,66,146,36,104,137,194,70,46,
+142,172,35,78,32,47,146,195,102,11,240,145,139,163,175,8,211,136,9,228,240,
+242,112,145,139,163,179,8,211,136,8,237,34,130,118,49,116,118,225,26,48,0,
+1,80,29,201,158,46,183,39,135,147,132,140,93,16,132,76,66,33,8,66,16,132,
+33,8,66,34,33,154,112,0,1,73,247,35,79,91,237,198,174,192,47,31,23,95,17,
+13,51,19,35,93,68,216,209,128,0,10,192,174,79,15,32,248,8,196,24,8,107,192,
+0,5,98,118,27,94,0,0,43,19,227,94,0,0,43,20,46,215,128,0,10,197,28,198,188,
+0,0,86,41,100,53,224,0,2,177,79,85,175,0,0,21,138,154,45,120,0,0,172,85,
+217,107,192,0,5,98,182,243,86,193,106,52,127,66,249,50,94,124,35,68,225,
+146,49,13,31,170,23,201,146,243,224,200,39,12,145,136,67,134,11,49,0,0,0,0,
+0,0,3,225,255,51,0,0,0,0,0,0,3,193,255,47,18,1,172,19,120,71,10,25,196,136,
+113,162,156,136,199,42,57,204,144,115,132,240,149,2,248,72,197,209,58,2,
+185,16,52,196,225,35,23,68,233,14,228,72,82,68,141,17,56,72,197,209,58,130,
+249,44,54,96,191,9,24,186,39,88,79,39,135,147,132,140,93,19,176,35,180,138,
+9,216,197,209,59,82,79,31,40,242,1,248,58,42,96,121,14,232,94,62,46,190,15,
+38,31,145,33,86,65,76,242,150,143,69,48,242,179,79,45,56,243,51,207,53,64,
+243,116,79,57,72,243,180,207,61,80,243,245,79,65,88,244,34,249,50,94,124,
+35,68,225,146,39,163,23,201,146,243,224,200,39,12,145,61,40,183,146,37,116,
+88,6,136,158,244,241,174,230,202,80,135,130,50,39,16,217,231,208,20,240,70,
+68,225,86,224,79,60,64,84,75,141,7,27,157,32,66,37,194,161,168,153,51,132,
+9,25,4,225,147,180,138,50,196,18,25,4,225,147,180,138,5,215,49,238,105,27,
+60,185,2,72,209,56,100,237,34,140,193,4,136,209,56,100,237,34,129,117,204,
+123,154,70,207,50,64,98,72,64,121,51,68,8,163,73,33,1,228,208,16,0,65,112,
+152,56,196,159,31,23,77,211,195,201,199,23,150,73,169,234,34,24,49,39,199,
+89,188,124,92,242,70,120,224,201,33,69,15,155,163,196,64,153,137,62,58,205,
+227,226,231,146,51,199,26,6,18,92,130,64,192,148,144,102,240,23,129,133,18,
+2,100,224,160,56,100,42,26,78,62,46,121,35,60,112,216,32,50,21,13,39,31,23,
+60,145,154,9,46,18,1,36,64,47,148,64,98,196,132,201,57,68,132,95,18,84,141,
+159,9,121,145,178,67,155,46,73,2,17,46,72,128,89,7,199,32,66,37,194,197,
+217,35,120,228,131,17,46,18,243,35,100,128,172,156,98,2,40,152,151,32,130,
+166,36,248,235,55,143,139,158,72,207,28,150,24,23,46,92,130,80,72,151,21,0,
+100,213,103,229,245,8,186,190,144,24,78,136,24,94,152,3,142,9,113,214,111,
+31,23,60,145,158,57,164,13,68,184,248,186,110,158,30,78,56,188,226,10,62,
+46,121,35,60,113,18,225,27,70,18,32,10,201,208,32,134,214,208,200,84,52,
+156,49,39,50,71,107,107,152,129,13,173,161,144,168,105,57,34,78,100,142,
+214,215,49,16,134,214,210,220,229,81,252,49,39,50,71,107,107,158,65,13,173,
+165,185,202,163,249,34,78,100,142,214,215,60,146,12,16,28,128,62,175,42,6,
+143,36,136,16,64,90,242,135,192,129,67,71,147,62,65,5,215,231,214,6,215,62,
+180,8,49,1,3,162,92,4,98,12,41,14,67,40,106,229,1,132,130,8,24,78,104,129,
+54,62,96,224,144,13,238,124,32,2,62,146,60,51,224,120,146,164,140,137,20,0,
+178,58,11,56,192,5,146,208,34,71,64,36,157,25,200,32,52,158,180,8,146,87,
+129,232,217,29,5,156,179,224,116,52,100,191,28,87,62,130,214,9,79,136,104,
+201,126,56,174,127,0,31,255,225,73,82,71,16,13,1,36,230,18,1,164,14,87,71,
+132,0,143,0,210,131,96,31,0,211,6,42,23,50,70,1,167,13,18,14,130,36,67,232,
+46,36,29,4,78,69,6,60,226,31,192,7,255,252,24,192,163,11,23,51,130,56,35,
+193,56,100,243,31,6,150,46,103,4,225,147,143,114,27,63,57,241,200,169,194,
+133,42,166,175,240,6,23,240,0,97,28,17,224,39,233,32,80,142,8,240,78,25,56,
+9,250,136,22,39,12,156,123,144,217,240,19,245,18,6,19,154,32,79,214,124,14,
+134,140,151,227,139,237,52,11,88,37,62,33,163,37,248,226,251,77,32,213,184,
+64,89,56,39,49,224,137,61,196,5,96,38,35,251,200,15,18,61,96,17,62,40,6,
+145,1,17,31,228,64,89,45,2,39,205,0,178,122,209,63,162,2,101,64,202,113,67,
+77,247,64,92,221,197,186,196,143,4,9,19,208,1,25,187,139,112,128,178,113,
+110,177,35,193,2,68,244,0,46,110,229,30,242,71,130,4,137,232,4,35,55,113,
+110,16,22,78,81,239,36,120,32,72,158,128,64,147,138,25,249,0,52,72,242,2,
+127,2,5,74,96,140,229,203,34,103,250,154,4,17,163,151,44,137,159,234,105,4,
+33,162,93,6,73,123,13,1,165,64,202,113,251,33,6,64,14,71,78,20,101,213,207,
+4,194,207,2,12,162,0,158,176,23,218,168,23,66,64,255,255,255,255,255,255,
+239,127,19,214,33,187,85,2,232,72,0,32,0,0,0,0,0,0,25,136,0,0,0,0,0,0,31,
+15,228,122,247,73,19,69,73,180,134,149,13,68,241,0,0,0,0,0,0,3,193,252,143,
+90,67,2,104,169,54,144,210,161,168,158,32,0,0,0,0,0,0,120,127,142,73,78,20,
+0,0,0,0,0,0,0,0,8,58,189,233,24,77,217,24,93,240,1,230,238,21,23,32,247,68,
+13,155,184,75,189,205,35,102,128,47,114,64,185,187,143,137,4,137,33,205,
+222,17,6,96,48,87,130,50,37,114,1,246,147,21,143,224,54,186,213,128,114,90,
+112,164,0,0,0,0,0,0,124,63,226,117,119,128,25,55,112,96,153,57,41,197,13,
+53,224,65,147,119,38,134,19,146,156,80,211,94,5,194,94,6,37,55,113,110,16,
+22,78,12,19,39,37,56,161,166,188,14,74,110,226,220,32,44,156,154,24,78,74,
+113,67,77,120,32,97,175,4,28,61,224,133,172,186,70,22,248,1,204,73,242,104,
+97,47,128,44,196,159,11,69,175,152,32,35,100,33,142,49,39,218,76,69,237,22,
+190,96,128,141,144,136,32,196,159,24,230,204,246,66,40,179,18,125,164,196,
+206,185,179,61,144,140,28,196,159,6,9,146,200,71,20,98,79,180,152,135,208,
+76,150,66,64,99,18,124,24,49,100,36,137,49,39,218,76,67,232,49,100,37,8,49,
+39,195,186,145,149,144,150,44,196,159,105,49,31,174,164,101,100,38,10,49,
+39,198,33,180,153,37,100,38,141,49,39,218,76,76,234,27,73,146,86,66,112,
+163,18,124,145,4,230,142,86,66,120,211,18,125,164,197,46,144,78,104,229,
+100,40,15,49,39,198,33,107,68,136,39,52,114,178,20,73,24,147,237,38,38,117,
+11,90,36,65,57,163,149,144,164,68,196,159,38,134,19,46,105,56,226,150,68,
+157,160,3,200,147,228,208,194,92,32,124,137,62,49,11,90,36,65,57,163,149,
+178,166,74,68,159,105,49,51,168,90,209,34,9,205,28,173,149,65,82,36,249,34,
+9,205,28,173,175,170,54,68,159,105,49,75,164,19,154,57,91,95,88,84,137,62,
+49,13,164,201,43,111,235,141,145,39,218,76,76,234,27,73,146,86,223,216,17,
+34,79,135,117,35,43,115,236,139,145,39,218,76,71,235,169,25,91,159,104,60,
+137,62,12,19,37,178,182,42,68,159,105,49,15,160,153,45,149,193,18,36,248,
+199,54,103,182,190,232,185,18,125,164,196,206,185,179,61,181,247,133,200,
+147,225,104,181,243,4,4,109,191,190,58,68,159,105,49,23,180,90,249,130,2,
+54,223,224,67,152,147,230,8,8,217,12,16,121,18,124,193,1,27,101,131,131,56,
+7,38,193,198,72,0,0,0,0,0,0,0,0,198,231,240,134,39,63,136,151,95,63,136,49,
+89,252,66,98,243,248,133,96,132,185,5,224,32,36,201,41,248,200,213,249,0,
+131,64,7,39,192,218,148,124,137,74,216,231,198,227,141,182,124,78,40,217,
+231,197,227,4,213,227,192,159,72,10,5,21,218,138,120,74,129,124,36,98,232,
+228,74,81,62,160,20,10,107,181,21,114,32,105,137,194,70,46,142,68,165,19,
+235,1,64,170,187,81,119,34,66,146,36,104,137,194,70,46,142,68,165,19,236,1,
+64,174,187,81,95,37,134,204,23,225,35,23,71,34,82,137,246,128,160,89,93,
+168,167,147,195,201,194,70,46,142,68,165,19,238,1,64,182,187,81,71,105,20,
+19,177,139,163,145,41,68,16,7,6,15,82,70,72,115,96,0,0,0,0,0,93,105,160,91,
+60,149,195,200,194,8,134,149,216,114,1,128,83,192,144,8,194,195,16,12,168,
+110,20,120,12,141,22,16,120,12,100,22,12,120,28,78,99,192,41,224,136,115,
+36,14,100,197,213,245,193,48,189,112,40,2,237,96,175,131,117,2,178,112,145,
+139,163,145,131,114,70,46,142,218,27,182,72,197,209,219,56,26,53,161,166,
+28,1,204,178,10,14,38,78,44,141,52,207,31,0,0,21,64,129,100,180,8,148,145,
+92,203,176,160,226,100,226,200,211,76,241,240,0,1,84,2,131,137,147,142,41,
+100,73,199,192,0,5,88,6,13,10,82,70,62,0,0,42,66,88,115,18,124,67,103,177,
+69,49,130,12,73,242,136,108,246,40,165,177,6,36,248,134,207,71,90,138,99,
+68,152,147,229,16,217,232,235,81,75,130,12,73,241,13,158,158,149,20,199,9,
+49,39,202,33,179,211,210,162,151,69,24,147,225,86,224,79,79,74,138,94,20,
+98,79,133,91,129,61,109,74,41,124,60,137,62,33,179,216,166,216,193,18,36,
+249,68,54,123,20,218,216,137,18,124,67,103,163,173,77,177,162,100,73,242,
+136,108,244,117,169,181,193,18,36,248,134,207,79,74,155,99,132,200,147,229,
+16,217,233,233,83,107,162,164,73,240,171,112,39,167,165,77,175,10,145,39,
+194,173,192,158,182,165,54,191,153,51,72,71,161,196,201,45,167,146,59,68,
+89,24,70,206,0,0,0,0,0,0,7,129,249,153,51,104,71,161,196,201,45,167,146,59,
+68,89,24,70,206,0,0,0,0,0,0,7,129,249,153,51,136,71,161,196,201,45,167,146,
+59,68,89,24,70,206,0,0,0,0,0,0,7,129,249,153,51,168,71,161,196,201,45,167,
+146,59,68,89,24,70,206,0,0,0,0,0,0,0,2,1,153,51,200,71,161,196,201,45,167,
+146,59,68,89,24,70,206,0,0,0,0,0,0,0,2,1,153,51,232,71,161,196,201,45,167,
+146,59,68,89,24,70,206,0,0,0,0,0,0,0,130,1,153,52,8,71,161,196,201,45,167,
+146,59,68,89,24,70,206,0,0,0,0,0,0,0,130,1,153,52,40,71,161,196,201,45,167,
+146,59,68,89,24,70,206,0,0,0,0,0,0,0,130,1,153,52,72,71,161,196,201,45,167,
+146,59,68,89,24,70,206,0,0,0,0,0,0,1,2,1,135,52,102,32,76,72,1,246,136,235,
+103,177,69,1,17,32,7,196,54,123,20,82,88,200,144,3,237,17,214,207,71,91,
+171,37,20,65,145,32,7,218,35,173,158,142,183,66,74,41,16,92,72,1,241,13,
+158,142,183,86,74,41,48,92,72,1,241,13,158,142,183,66,74,41,80,100,72,1,
+246,136,235,103,167,165,213,146,138,40,200,144,3,237,17,214,207,79,75,161,
+37,20,138,46,36,0,248,134,207,79,75,171,37,20,154,46,36,0,248,134,207,79,
+75,161,37,20,170,46,36,0,248,85,184,19,234,201,69,24,92,72,1,240,171,112,
+39,208,146,138,70,25,18,0,124,27,168,21,147,171,37,20,113,145,32,7,193,186,
+129,89,58,18,81,72,226,162,64,15,180,71,91,62,172,148,90,0,168,144,3,237,
+17,214,207,161,37,22,144,38,36,0,248,134,207,171,37,22,160,38,36,0,248,134,
+207,161,37,22,176,42,209,68,201,218,35,173,158,197,54,4,218,40,153,56,134,
+207,98,155,75,27,104,162,100,237,17,214,207,71,91,171,37,54,65,182,138,38,
+78,209,29,108,244,117,186,18,83,104,131,45,20,76,156,67,103,163,173,213,
+146,155,76,25,104,162,100,226,27,61,29,110,132,148,218,160,219,69,19,39,
+104,142,182,122,122,93,89,41,178,141,180,81,50,118,136,235,103,167,165,208,
+146,155,69,25,104,162,100,226,27,61,61,46,172,148,218,104,203,69,19,39,16,
+217,233,233,116,36,166,213,70,90,40,153,56,85,184,19,234,201,77,152,101,
+162,137,147,133,91,129,62,132,148,218,48,219,69,19,39,6,234,5,100,234,201,
+77,156,109,162,137,147,131,117,2,178,116,36,166,209,197,218,40,153,59,68,
+117,179,234,201,78,32,11,180,81,50,118,136,235,103,208,146,156,72,21,104,
+162,100,226,27,62,172,148,226,128,171,69,19,39,16,217,244,36,167,22,53,123,
+102,53,155,80,2,21,11,94,201,128,196,133,0,185,80,32,56,156,199,130,36,160,
+72,16,78,126,54,48,5,146,208,34,82,72,1,109,20,76,155,120,28,34,1,225,32,
+52,171,138,69,133,95,130,160,4,234,219,163,161,0,89,86,214,238,197,172,9,0,
+31,86,221,40,29,231,63,95,200,69,220,199,225,122,183,27,72,144,63,160,138,
+217,81,197,125,207,195,117,110,54,142,129,32,7,114,147,10,189,229,237,159,
+130,235,209,0,96,181,17,83,236,132,37,0,63,101,8,207,71,107,74,6,105,219,
+251,52,245,7,49,248,94,202,17,158,148,12,211,183,246,105,234,15,99,242,159,
+129,228,176,192,185,127,46,155,185,41,197,13,55,38,3,127,255,20,138,160,
+192,25,106,8,8,1,58,90,130,64,128,146,27,168,37,8,9,129,186,130,96,160,152,
+27,165,171,64,32,131,25,234,10,64,65,17,11,212,19,133,18,243,167,165,163,
+32,24,157,45,65,64,6,75,191,80,80,66,149,110,116,117,5,8,41,240,247,79,72,
+188,8,134,81,122,84,1,173,198,212,20,48,139,113,180,181,5,36,42,220,109,29,
+13,65,74,6,192,95,76,188,6,196,55,78,188,6,247,91,86,136,26,32,104,220,205,
+72,1,98,234,52,122,130,136,18,72,51,117,68,3,146,27,168,40,161,37,8,207,80,
+81,129,204,13,212,20,112,179,141,26,45,65,75,112,20,43,193,25,19,66,128,
+153,78,40,105,144,92,104,152,131,124,27,253,128,0,10,116,3,68,146,163,9,
+128,0,10,102,3,138,145,137,27,60,0,0,82,129,7,2,4,16,7,2,70,143,178,203,
+164,237,35,14,25,10,134,147,143,139,158,72,207,28,54,77,47,109,13,55,113,
+120,96,196,159,29,102,241,241,115,201,25,227,131,36,133,20,62,110,143,17,
+16,113,137,62,62,46,155,167,135,147,142,47,44,151,79,221,64,98,37,194,94,
+100,108,144,21,147,140,73,168,228,19,17,124,73,82,54,124,37,230,70,201,14,
+108,185,36,155,14,243,243,83,212,69,131,132,4,12,137,114,168,37,166,145,7,
+10,4,28,200,14,12,40,56,153,56,178,52,211,60,124,0,0,85,0,160,226,100,227,
+138,89,18,113,240,0,1,86,1,131,66,148,145,143,128,0,10,144,93,134,0,0,43,
+80,17,42,4,17,136,49,73,19,49,134,16,143,67,137,146,91,79,36,118,136,178,
+48,141,156,0,0,0,0,0,0,15,3,243,49,135,16,143,67,137,146,91,79,36,118,136,
+178,48,141,156,0,0,0,0,0,0,15,3,245,20,5,173,194,227,214,4,55,0,0,21,196,7,
+122,192,134,241,197,192,0,5,121,25,140,64,132,122,28,76,146,218,121,35,180,
+69,145,132,108,224,0,0,0,0,0,0,120,31,153,140,72,132,122,28,76,146,218,121,
+35,180,69,145,132,108,224,0,0,0,0,0,0,0,32,25,140,80,132,122,28,76,146,218,
+121,35,180,69,145,132,108,224,0,0,0,0,0,0,0,32,25,140,88,132,122,28,76,146,
+218,121,35,180,69,145,132,108,224,0,0,0,0,0,0,8,32,25,140,96,132,122,28,76,
+146,218,121,35,180,69,145,132,108,224,0,0,0,0,0,0,8,32,25,140,104,132,122,
+28,76,146,218,121,35,180,69,145,132,108,224,0,0,0,0,0,0,8,32,25,140,112,
+132,122,28,76,146,218,121,35,180,69,145,132,108,224,0,0,0,0,0,0,16,32,16,
+113,225,0,48,156,209,2,122,244,5,34,92,35,68,225,161,166,218,16,33,18,224,
+104,82,146,59,50,5,7,19,39,22,70,154,103,215,32,28,78,99,193,18,80,70,131,
+165,1,205,34,8,35,68,225,161,166,239,255,4,12,70,137,195,39,248,73,7,78,3,
+154,102,16,70,137,195,67,77,223,248,1,74,9,129,125,255,130,9,65,154,232,
+147,161,115,59,255,5,64,195,32,156,50,126,197,14,2,3,107,173,213,0,
};
#elif defined(DUK_USE_DOUBLE_BE)
-DUK_INTERNAL const duk_uint8_t duk_builtins_data[3819] = {
-144,148,105,221,32,68,52,228,62,12,104,200,165,134,148,248,81,77,61,191,
-135,35,154,103,34,72,6,157,159,197,145,77,245,126,52,130,106,234,163,196,
-52,226,18,51,161,26,113,1,60,37,64,190,18,49,116,116,33,26,113,1,92,136,26,
-98,112,145,139,163,165,8,211,136,14,228,72,82,68,141,17,56,72,197,209,212,
-132,105,196,5,242,88,108,193,126,18,49,116,117,161,26,113,1,60,158,30,78,
-18,49,116,118,33,26,113,1,29,164,80,78,198,46,142,212,36,68,51,71,232,59,
-147,60,93,110,79,15,39,9,24,186,33,13,63,111,185,16,211,206,251,114,98,17,
-171,160,11,199,197,215,196,66,26,102,38,68,53,212,77,136,104,255,5,114,120,
-121,7,192,70,32,192,67,95,249,59,13,13,127,228,248,134,191,242,133,208,215,
-254,81,204,67,95,249,75,33,13,127,229,61,84,53,255,149,52,80,215,254,85,
-217,67,95,249,91,121,13,90,181,168,134,143,152,95,38,75,207,132,104,156,50,
-70,33,163,225,66,249,50,94,124,25,4,225,146,49,14,24,28,196,7,255,128,0,0,
-0,0,0,12,204,7,255,0,0,0,0,0,0,12,188,72,6,176,77,225,28,24,103,14,33,197,
-138,113,227,28,152,231,46,65,205,19,194,84,11,225,35,23,68,231,138,228,64,
-211,19,132,140,93,19,162,59,145,33,73,18,52,68,225,35,23,68,233,139,228,
-176,217,130,252,36,98,232,157,81,60,158,30,78,18,49,116,78,184,142,210,40,
-39,99,23,68,236,201,59,114,142,224,126,14,138,152,30,67,188,23,143,139,175,
-131,194,135,228,72,85,144,83,60,53,163,208,76,60,68,211,197,78,60,116,243,
-200,80,60,149,19,202,82,60,181,51,204,84,60,213,83,206,86,60,240,190,76,
-151,159,8,209,56,100,137,232,133,242,100,188,248,50,9,195,36,79,73,26,238,
-108,129,15,4,100,78,33,179,207,160,41,224,140,137,194,173,192,158,120,128,
-168,151,26,14,55,58,64,132,75,133,67,81,50,103,8,18,50,9,195,39,105,20,101,
-136,36,50,9,195,39,105,20,11,174,99,220,210,54,121,114,4,145,162,112,201,
-218,69,25,130,9,17,162,112,201,218,69,2,235,152,247,52,141,158,100,128,196,
-144,128,242,102,136,17,70,146,66,3,201,160,32,0,130,225,48,113,137,62,62,
-46,155,167,135,147,142,47,24,147,79,205,68,48,98,79,142,179,120,248,185,
-228,140,241,193,146,66,138,31,55,71,126,129,51,18,124,117,155,199,197,207,
-36,103,142,52,12,36,184,100,129,129,41,32,205,221,175,3,10,36,4,201,188,64,
-112,200,84,52,156,124,92,242,70,120,223,48,64,100,42,26,78,62,46,121,35,52,
-18,91,212,2,72,128,95,20,128,197,137,9,146,113,73,8,190,36,169,27,62,18,
-243,35,100,135,54,92,66,4,34,92,145,0,178,15,132,64,132,75,133,139,178,70,
-240,137,6,34,92,37,230,70,201,1,89,56,36,4,81,49,46,25,5,76,73,241,214,111,
-31,23,60,145,158,57,44,48,46,92,184,100,160,145,46,2,0,201,168,207,198,230,
-144,117,60,176,48,156,160,48,188,192,7,28,18,227,172,222,62,46,121,35,60,
-113,200,26,137,113,241,116,221,60,60,156,113,121,4,20,124,92,242,70,120,
-226,37,194,54,140,36,64,21,147,146,68,24,32,57,0,125,78,84,0,160,123,215,
-140,146,1,4,5,175,40,124,8,20,52,121,51,228,24,96,129,209,46,2,49,6,20,135,
-33,20,53,50,128,194,65,4,12,39,52,64,155,31,48,112,72,6,247,62,16,1,31,73,
-30,25,240,60,73,82,70,68,138,0,89,29,5,156,96,2,201,104,17,35,160,18,78,
-140,228,16,26,79,90,4,73,43,192,244,108,142,130,206,89,240,58,26,50,95,142,
-43,159,65,107,4,167,196,52,100,191,28,87,63,128,15,255,240,164,169,35,136,
-6,128,146,115,9,0,210,7,43,163,194,0,71,128,105,65,176,15,128,105,131,21,
-11,153,35,0,211,134,137,7,65,18,33,244,23,18,14,130,39,34,131,30,113,15,
-224,3,255,254,12,80,81,133,139,153,193,28,17,224,156,50,119,15,131,75,23,
-51,130,112,201,199,185,13,159,116,248,228,68,219,66,149,83,83,238,3,11,238,
-0,48,142,8,240,19,239,144,40,71,4,120,39,12,156,4,252,4,11,19,134,78,61,
-200,108,248,9,248,9,3,9,205,16,39,225,62,7,67,70,75,241,197,241,154,5,172,
-18,159,16,209,146,252,113,124,102,144,106,220,32,44,156,19,152,240,68,158,
-66,2,176,19,17,252,164,7,137,30,176,8,158,116,3,72,128,136,143,232,32,44,
-150,129,19,210,128,89,61,104,159,169,1,50,160,101,56,161,166,246,160,46,
-110,226,221,98,71,130,4,137,222,0,140,221,197,184,64,89,56,183,88,145,224,
-129,34,119,128,23,55,114,143,121,35,193,2,68,239,2,17,155,184,183,8,11,39,
-40,247,146,60,16,36,78,240,32,73,197,12,247,128,26,36,121,1,63,49,2,165,48,
-70,114,229,145,51,250,205,2,8,209,203,150,68,207,235,52,130,16,209,46,131,
-36,188,70,128,210,160,101,56,251,16,131,28,7,35,38,218,50,234,103,130,97,
-103,129,6,73,0,79,88,11,237,84,11,161,32,63,247,255,255,255,255,255,255,
-137,235,16,221,170,129,116,36,0,0,0,0,0,0,0,0,28,196,7,255,128,0,0,0,0,0,2,
-61,123,164,137,162,164,218,67,74,134,162,120,128,255,224,0,0,0,0,0,0,71,
-173,33,129,52,84,155,72,105,80,212,79,16,63,252,0,0,0,0,0,0,7,36,38,218,0,
-0,0,0,0,0,0,0,4,29,78,224,140,38,216,140,46,228,0,243,119,10,139,144,123,
-82,6,205,220,37,222,230,145,179,64,23,180,32,92,221,199,196,130,68,144,230,
-237,200,131,44,24,43,193,25,18,185,0,251,73,138,199,240,27,93,106,192,57,
-41,54,210,31,254,0,0,0,0,0,0,49,58,155,192,12,155,184,48,76,156,148,226,
-134,154,240,32,201,187,147,67,9,201,78,40,105,175,2,225,47,3,18,155,184,
-183,8,11,39,6,9,147,146,156,80,211,94,7,37,55,113,110,16,22,78,77,12,39,37,
-56,161,166,188,16,48,215,130,14,30,240,66,213,93,35,11,124,0,230,36,249,52,
-48,151,192,22,98,79,133,162,215,204,16,17,178,16,199,24,147,237,38,34,246,
-139,95,48,64,70,200,68,16,98,79,140,115,102,123,33,20,89,137,62,210,98,103,
-92,217,158,200,70,14,98,79,131,4,201,100,35,138,49,39,218,76,67,232,38,75,
-33,32,49,137,62,12,24,178,18,68,152,147,237,38,33,244,24,178,18,132,24,147,
-225,221,72,202,200,75,22,98,79,180,152,143,215,82,50,178,19,5,24,147,227,
-16,218,76,146,178,19,70,152,147,237,38,38,117,13,164,201,43,33,56,81,137,
-62,72,130,115,71,43,33,60,105,137,62,210,98,151,72,39,52,114,178,20,7,152,
-147,227,16,181,162,68,19,154,57,89,10,36,140,73,246,147,19,58,133,173,18,
-32,156,209,202,200,82,34,98,79,147,67,9,151,52,156,113,75,34,78,208,1,228,
-73,242,104,97,46,16,62,68,159,24,133,173,18,32,156,209,202,217,83,37,34,79,
-180,152,153,212,45,104,145,4,230,142,86,202,160,169,18,124,145,4,230,142,
-86,215,213,27,34,79,180,152,165,210,9,205,28,173,175,172,42,68,159,24,134,
-210,100,149,183,245,198,200,147,237,38,38,117,13,164,201,43,111,236,8,145,
-39,195,186,145,149,185,246,69,200,147,237,38,35,245,212,140,173,207,180,30,
-68,159,6,9,146,217,91,21,34,79,180,152,135,208,76,150,202,224,137,18,124,
-99,155,51,219,95,116,92,137,62,210,98,103,92,217,158,218,251,194,228,73,
-240,180,90,249,130,2,54,223,223,29,34,79,180,152,139,218,45,124,193,1,27,
-111,240,33,204,73,243,4,4,108,134,8,60,137,62,96,128,141,178,193,193,154,3,
-147,32,227,36,0,0,0,0,0,0,0,0,99,115,245,195,19,159,176,75,175,159,176,24,
-172,253,129,49,121,251,2,176,66,92,130,235,16,18,100,148,251,36,106,123,64,
-65,158,3,147,160,108,202,62,68,165,107,243,227,113,198,211,62,39,20,108,
-115,226,241,130,106,113,224,78,162,4,242,130,236,197,60,37,64,190,18,49,
-116,114,37,40,157,76,9,229,37,217,138,185,16,52,196,225,35,23,71,34,82,137,
-213,64,158,84,93,152,187,145,33,73,18,52,68,225,35,23,71,34,82,137,213,192,
-158,86,93,152,175,146,195,102,11,240,145,139,163,145,41,68,235,32,79,44,46,
-204,83,201,225,228,225,35,23,71,34,82,137,214,192,158,90,93,152,163,180,
-138,9,216,197,209,200,148,161,194,32,30,18,2,0,45,248,84,88,162,187,72,78,
-173,186,58,16,16,0,154,236,110,237,85,69,129,245,109,210,128,127,204,92,
-133,253,244,115,222,23,171,113,180,137,0,255,220,85,29,148,174,11,248,55,
-86,227,104,232,18,1,254,222,91,216,169,55,40,112,46,189,16,16,2,72,126,213,
-17,11,70,3,246,80,140,244,118,180,160,31,243,80,79,51,63,157,230,133,236,
-161,25,233,64,63,246,160,158,102,127,59,205,41,248,30,75,12,11,151,242,233,
-187,146,156,80,211,114,96,54,230,41,20,129,128,50,211,16,16,2,116,180,196,
-129,1,36,55,76,74,16,19,3,116,196,193,65,48,55,75,80,128,65,6,51,211,20,
-128,130,34,23,166,39,6,39,75,76,80,1,146,239,211,20,16,165,91,157,29,49,66,
-10,124,61,211,209,175,1,173,198,211,20,48,139,113,180,180,197,36,42,220,
-109,29,13,49,74,6,192,95,72,188,6,196,55,74,188,6,247,91,80,136,26,32,104,
-220,205,56,1,98,234,52,122,98,136,14,72,110,152,162,132,148,35,61,49,70,7,
-48,55,76,81,194,206,52,104,180,197,45,192,80,175,4,100,77,10,2,101,56,161,
-166,65,113,162,98,8,3,131,7,169,35,36,57,176,16,52,232,64,0,0,0,0,45,158,
-10,225,223,132,17,13,43,176,228,3,0,167,129,32,17,133,134,32,25,80,220,40,
-240,25,26,44,32,240,24,200,44,24,240,56,156,199,128,83,193,17,7,4,13,128,0,
-10,79,202,28,223,195,1,197,72,196,141,159,220,7,48,33,7,8,3,152,49,117,60,
-240,76,47,60,9,224,187,56,43,224,221,64,172,156,36,98,232,228,96,220,145,
-139,163,182,134,237,146,49,116,118,206,6,141,104,105,136,32,14,4,128,160,
-123,215,140,147,32,145,57,178,156,104,41,228,151,168,225,144,168,105,56,
-248,185,228,140,241,190,100,209,244,80,210,116,151,134,12,73,241,214,111,
-31,23,60,145,158,56,50,72,81,67,230,232,239,209,7,24,147,227,226,233,186,
-120,121,56,226,241,137,116,189,52,6,34,92,37,230,70,201,1,89,56,36,154,110,
-25,49,23,196,149,35,103,194,94,100,108,144,230,203,136,73,174,234,63,52,
-252,212,87,0,131,138,4,12,137,114,168,37,166,144,230,37,5,7,19,39,22,70,
-154,103,143,252,4,11,37,160,68,164,139,7,24,3,152,182,20,28,76,156,89,26,
-105,158,63,240,5,7,19,39,28,82,200,147,143,253,0,193,161,74,72,199,253,132,
-176,230,36,248,134,207,98,138,99,4,24,147,229,16,217,236,81,75,98,12,73,
-241,13,158,142,181,20,198,137,49,39,202,33,179,209,214,162,151,4,24,147,
-226,27,61,61,42,41,142,18,98,79,148,67,103,167,165,69,46,138,49,39,194,173,
-192,158,158,149,20,188,40,196,159,10,183,2,122,218,148,82,248,121,18,124,
-67,103,177,77,177,130,36,73,242,136,108,246,41,181,177,18,36,248,134,207,
-71,90,155,99,68,200,147,229,16,217,232,235,83,107,130,36,73,241,13,158,158,
-149,54,199,9,145,39,202,33,179,211,210,166,215,69,72,147,225,86,224,79,79,
-74,155,94,21,34,79,133,91,129,61,109,74,109,126,14,56,7,6,20,28,76,156,89,
-26,105,158,63,240,5,7,19,39,28,82,200,147,143,253,0,193,161,74,72,199,253,
-130,235,191,232,8,149,2,8,196,24,164,137,141,200,8,71,161,196,201,45,167,
-146,59,68,89,24,70,206,1,255,128,0,0,0,0,0,1,142,49,232,71,161,196,201,45,
-167,146,59,68,89,24,70,206,1,255,128,0,0,0,0,0,1,141,201,8,71,161,196,201,
-45,167,146,59,68,89,24,70,206,1,255,128,0,0,0,0,0,2,138,2,214,225,113,235,
-2,27,128,0,10,66,3,189,96,67,120,226,224,0,2,148,140,113,145,66,61,14,38,
-73,109,60,145,218,34,200,194,54,112,15,252,0,0,0,0,0,0,12,110,80,66,61,14,
-38,73,109,60,145,218,34,200,194,54,112,15,252,0,0,0,0,0,0,12,113,147,66,61,
-14,38,73,109,60,145,218,34,200,194,54,112,15,252,0,0,0,0,0,0,12,110,88,66,
-61,14,38,73,109,60,145,218,34,200,194,54,112,16,0,0,0,0,0,0,0,12,113,149,
-66,61,14,38,73,109,60,145,218,34,200,194,54,112,16,0,0,0,0,0,0,0,12,110,96,
-66,61,14,38,73,109,60,145,218,34,200,194,54,112,16,0,0,0,0,0,0,0,12,113,
-151,66,61,14,38,73,109,60,145,218,34,200,194,54,112,16,0,0,0,0,0,0,0,12,
-110,104,66,61,14,38,73,109,60,145,218,34,200,194,54,112,16,4,0,0,0,0,0,0,
-12,113,153,66,61,14,38,73,109,60,145,218,34,200,194,54,112,16,4,0,0,0,0,0,
-0,12,110,112,66,61,14,38,73,109,60,145,218,34,200,194,54,112,16,4,0,0,0,0,
-0,0,12,113,155,66,61,14,38,73,109,60,145,218,34,200,194,54,112,16,4,0,0,0,
-0,0,0,12,110,120,66,61,14,38,73,109,60,145,218,34,200,194,54,112,16,4,0,0,
-0,0,0,0,12,113,157,66,61,14,38,73,109,60,145,218,34,200,194,54,112,16,4,0,
-0,0,0,0,0,12,110,128,66,61,14,38,73,109,60,145,218,34,200,194,54,112,16,8,
-0,0,0,0,0,0,12,113,159,66,61,14,38,73,109,60,145,218,34,200,194,54,112,16,
-8,0,0,0,0,0,0,8,58,32,128,24,78,104,129,61,82,2,145,46,17,162,112,208,211,
-107,200,16,137,112,52,41,73,29,113,2,131,137,147,139,35,77,51,234,80,14,39,
-49,224,137,40,35,100,141,9,136,19,18,0,125,162,58,217,236,81,64,68,72,1,
-241,13,158,197,20,150,50,36,0,251,68,117,179,209,214,234,201,69,16,100,72,
-1,246,136,235,103,163,173,208,146,138,68,23,18,0,124,67,103,163,173,213,
-146,138,76,23,18,0,124,67,103,163,173,208,146,138,84,25,18,0,125,162,58,
-217,233,233,117,100,162,138,50,36,0,251,68,117,179,211,210,232,73,69,34,
-139,137,0,62,33,179,211,210,234,201,69,38,139,137,0,62,33,179,211,210,232,
-73,69,42,139,137,0,62,21,110,4,250,178,81,70,23,18,0,124,42,220,9,244,36,
-162,145,134,68,128,31,6,234,5,100,234,201,69,28,100,72,1,240,110,160,86,78,
-132,148,82,56,168,144,3,237,17,214,207,171,37,22,128,42,36,0,251,68,117,
-179,232,73,69,164,9,137,0,62,33,179,234,201,69,168,9,137,0,62,33,179,232,
-73,69,172,10,180,81,50,118,136,235,103,177,77,129,54,138,38,78,33,179,216,
-166,210,198,218,40,153,59,68,117,179,209,214,234,201,77,144,109,162,137,
-147,180,71,91,61,29,110,132,148,218,32,203,69,19,39,16,217,232,235,117,100,
-166,211,6,90,40,153,56,134,207,71,91,161,37,54,168,54,209,68,201,218,35,
-173,158,158,151,86,74,108,163,109,20,76,157,162,58,217,233,233,116,36,166,
-209,70,90,40,153,56,134,207,79,75,171,37,54,154,50,209,68,201,196,54,122,
-122,93,9,41,181,81,150,138,38,78,21,110,4,250,178,83,102,25,104,162,100,
-225,86,224,79,161,37,54,140,54,209,68,201,193,186,129,89,58,178,83,103,27,
-104,162,100,224,221,64,172,157,9,41,180,113,118,138,38,78,209,29,108,250,
-178,83,136,2,237,20,76,157,162,58,217,244,36,167,18,5,90,40,153,56,134,207,
-171,37,56,160,42,209,68,201,196,54,125,9,41,197,141,78,197,141,86,192,0,
-133,66,215,173,96,49,33,64,46,84,8,14,39,49,224,137,40,18,4,19,159,141,100,
-1,100,180,8,148,146,0,91,69,19,38,202,8,58,64,28,209,160,130,52,78,26,26,
-110,255,80,64,196,104,156,50,125,4,144,116,192,57,165,97,4,104,156,52,52,
-221,254,64,20,160,152,23,223,228,32,148,25,174,137,58,23,51,191,200,84,12,
-50,9,195,39,196,80,
+DUK_INTERNAL const duk_uint8_t duk_builtins_data[3972] = {
+144,148,105,223,160,68,52,228,62,12,104,200,165,132,52,167,194,138,105,242,
+252,57,28,211,57,18,64,52,238,62,44,138,111,171,241,164,19,87,125,30,33,
+167,16,145,159,8,211,136,9,225,42,5,240,145,139,163,163,8,211,136,10,228,
+64,211,19,132,140,93,29,56,70,156,64,119,34,66,146,36,104,137,194,70,46,
+142,172,35,78,32,47,146,195,102,11,240,145,139,163,175,8,211,136,9,228,240,
+242,112,145,139,163,179,8,211,136,8,237,34,130,118,49,116,118,225,26,48,0,
+1,80,29,201,158,46,183,39,135,147,132,140,93,16,132,76,66,33,8,66,16,132,
+33,8,66,34,33,154,112,0,1,73,247,35,79,91,237,198,174,192,47,31,23,95,17,
+13,51,19,35,93,68,216,209,128,0,10,192,174,79,15,32,248,8,196,24,8,107,192,
+0,5,98,118,27,94,0,0,43,19,227,94,0,0,43,20,46,215,128,0,10,197,28,198,188,
+0,0,86,41,100,53,224,0,2,177,79,85,175,0,0,21,138,154,45,120,0,0,172,85,
+217,107,192,0,5,98,182,243,86,193,106,52,127,66,249,50,94,124,35,68,225,
+146,49,13,31,170,23,201,146,243,224,200,39,12,145,136,67,134,11,49,1,255,
+224,0,0,0,0,0,3,51,1,255,192,0,0,0,0,0,3,47,18,1,172,19,120,71,10,25,196,
+136,113,162,156,136,199,42,57,204,144,115,132,240,149,2,248,72,197,209,58,
+2,185,16,52,196,225,35,23,68,233,14,228,72,82,68,141,17,56,72,197,209,58,
+130,249,44,54,96,191,9,24,186,39,88,79,39,135,147,132,140,93,19,176,35,180,
+138,9,216,197,209,59,82,79,31,40,242,1,248,58,42,96,121,14,232,94,62,46,
+190,15,38,31,145,33,86,65,76,242,150,143,69,48,242,179,79,45,56,243,51,207,
+53,64,243,116,79,57,72,243,180,207,61,80,243,245,79,65,88,244,34,249,50,94,
+124,35,68,225,146,39,163,23,201,146,243,224,200,39,12,145,61,40,183,146,37,
+116,88,6,136,158,244,241,174,230,202,80,135,130,50,39,16,217,231,208,20,
+240,70,68,225,86,224,79,60,64,84,75,141,7,27,157,32,66,37,194,161,168,153,
+51,132,9,25,4,225,147,180,138,50,196,18,25,4,225,147,180,138,5,215,49,238,
+105,27,60,185,2,72,209,56,100,237,34,140,193,4,136,209,56,100,237,34,129,
+117,204,123,154,70,207,50,64,98,72,64,121,51,68,8,163,73,33,1,228,208,16,0,
+65,112,152,56,196,159,31,23,77,211,195,201,199,23,150,73,169,234,34,24,49,
+39,199,89,188,124,92,242,70,120,224,201,33,69,15,155,163,196,64,153,137,62,
+58,205,227,226,231,146,51,199,26,6,18,92,130,64,192,148,144,102,240,23,129,
+133,18,2,100,224,160,56,100,42,26,78,62,46,121,35,60,112,216,32,50,21,13,
+39,31,23,60,145,154,9,46,18,1,36,64,47,148,64,98,196,132,201,57,68,132,95,
+18,84,141,159,9,121,145,178,67,155,46,73,2,17,46,72,128,89,7,199,32,66,37,
+194,197,217,35,120,228,131,17,46,18,243,35,100,128,172,156,98,2,40,152,151,
+32,130,166,36,248,235,55,143,139,158,72,207,28,150,24,23,46,92,130,80,72,
+151,21,0,100,213,103,229,245,8,186,190,144,24,78,136,24,94,152,3,142,9,113,
+214,111,31,23,60,145,158,57,164,13,68,184,248,186,110,158,30,78,56,188,226,
+10,62,46,121,35,60,113,18,225,27,70,18,32,10,201,208,32,134,214,208,200,84,
+52,156,49,39,50,71,107,107,152,129,13,173,161,144,168,105,57,34,78,100,142,
+214,215,49,16,134,214,210,220,229,81,252,49,39,50,71,107,107,158,65,13,173,
+165,185,202,163,249,34,78,100,142,214,215,60,146,12,16,28,128,62,175,42,6,
+143,36,136,16,64,90,242,135,192,129,67,71,147,62,65,5,215,231,214,6,215,62,
+180,8,49,1,3,162,92,4,98,12,41,14,67,40,106,229,1,132,130,8,24,78,104,129,
+54,62,96,224,144,13,238,124,32,2,62,146,60,51,224,120,146,164,140,137,20,0,
+178,58,11,56,192,5,146,208,34,71,64,36,157,25,200,32,52,158,180,8,146,87,
+129,232,217,29,5,156,179,224,116,52,100,191,28,87,62,130,214,9,79,136,104,
+201,126,56,174,127,0,31,255,225,73,82,71,16,13,1,36,230,18,1,164,14,87,71,
+132,0,143,0,210,131,96,31,0,211,6,42,23,50,70,1,167,13,18,14,130,36,67,232,
+46,36,29,4,78,69,6,60,226,31,192,7,255,252,24,192,163,11,23,51,130,56,35,
+193,56,100,243,31,6,150,46,103,4,225,147,143,114,27,63,57,241,200,169,194,
+133,42,166,175,240,6,23,240,0,97,28,17,224,39,233,32,80,142,8,240,78,25,56,
+9,250,136,22,39,12,156,123,144,217,240,19,245,18,6,19,154,32,79,214,124,14,
+134,140,151,227,139,237,52,11,88,37,62,33,163,37,248,226,251,77,32,213,184,
+64,89,56,39,49,224,137,61,196,5,96,38,35,251,200,15,18,61,96,17,62,40,6,
+145,1,17,31,228,64,89,45,2,39,205,0,178,122,209,63,162,2,101,64,202,113,67,
+77,247,64,92,221,197,186,196,143,4,9,19,208,1,25,187,139,112,128,178,113,
+110,177,35,193,2,68,244,0,46,110,229,30,242,71,130,4,137,232,4,35,55,113,
+110,16,22,78,81,239,36,120,32,72,158,128,64,147,138,25,249,0,52,72,242,2,
+127,2,5,74,96,140,229,203,34,103,250,154,4,17,163,151,44,137,159,234,105,4,
+33,162,93,6,73,123,13,1,165,64,202,113,251,33,6,64,14,71,78,20,101,213,207,
+4,194,207,2,12,162,0,158,176,23,218,168,23,66,64,127,239,255,255,255,255,
+255,255,19,214,33,187,85,2,232,72,0,0,0,0,0,0,0,0,57,136,15,255,0,0,0,0,0,
+0,4,122,247,73,19,69,73,180,134,149,13,68,241,1,255,192,0,0,0,0,0,0,143,90,
+67,2,104,169,54,144,210,161,168,158,32,127,248,0,0,0,0,0,0,14,73,78,20,0,0,
+0,0,0,0,0,0,8,58,189,233,24,77,217,24,93,240,1,230,238,21,23,32,247,68,13,
+155,184,75,189,205,35,102,128,47,114,64,185,187,143,137,4,137,33,205,222,
+17,6,96,48,87,130,50,37,114,1,246,147,21,143,224,54,186,213,128,114,90,112,
+164,63,252,0,0,0,0,0,0,98,117,119,128,25,55,112,96,153,57,41,197,13,53,224,
+65,147,119,38,134,19,146,156,80,211,94,5,194,94,6,37,55,113,110,16,22,78,
+12,19,39,37,56,161,166,188,14,74,110,226,220,32,44,156,154,24,78,74,113,67,
+77,120,32,97,175,4,28,61,224,133,172,186,70,22,248,1,204,73,242,104,97,47,
+128,44,196,159,11,69,175,152,32,35,100,33,142,49,39,218,76,69,237,22,190,
+96,128,141,144,136,32,196,159,24,230,204,246,66,40,179,18,125,164,196,206,
+185,179,61,144,140,28,196,159,6,9,146,200,71,20,98,79,180,152,135,208,76,
+150,66,64,99,18,124,24,49,100,36,137,49,39,218,76,67,232,49,100,37,8,49,39,
+195,186,145,149,144,150,44,196,159,105,49,31,174,164,101,100,38,10,49,39,
+198,33,180,153,37,100,38,141,49,39,218,76,76,234,27,73,146,86,66,112,163,
+18,124,145,4,230,142,86,66,120,211,18,125,164,197,46,144,78,104,229,100,40,
+15,49,39,198,33,107,68,136,39,52,114,178,20,73,24,147,237,38,38,117,11,90,
+36,65,57,163,149,144,164,68,196,159,38,134,19,46,105,56,226,150,68,157,160,
+3,200,147,228,208,194,92,32,124,137,62,49,11,90,36,65,57,163,149,178,166,
+74,68,159,105,49,51,168,90,209,34,9,205,28,173,149,65,82,36,249,34,9,205,
+28,173,175,170,54,68,159,105,49,75,164,19,154,57,91,95,88,84,137,62,49,13,
+164,201,43,111,235,141,145,39,218,76,76,234,27,73,146,86,223,216,17,34,79,
+135,117,35,43,115,236,139,145,39,218,76,71,235,169,25,91,159,104,60,137,62,
+12,19,37,178,182,42,68,159,105,49,15,160,153,45,149,193,18,36,248,199,54,
+103,182,190,232,185,18,125,164,196,206,185,179,61,181,247,133,200,147,225,
+104,181,243,4,4,109,191,190,58,68,159,105,49,23,180,90,249,130,2,54,223,
+224,67,152,147,230,8,8,217,12,16,121,18,124,193,1,27,101,131,131,56,7,38,
+193,198,72,0,0,0,0,0,0,0,0,198,231,240,134,39,63,136,151,95,63,136,49,89,
+252,66,98,243,248,133,96,132,185,5,224,32,36,201,41,248,200,213,249,0,131,
+64,7,39,192,218,148,124,137,74,216,231,198,227,141,182,124,78,40,217,231,
+197,227,4,213,227,192,159,72,10,5,21,218,138,120,74,129,124,36,98,232,228,
+74,81,62,160,20,10,107,181,21,114,32,105,137,194,70,46,142,68,165,19,235,1,
+64,170,187,81,119,34,66,146,36,104,137,194,70,46,142,68,165,19,236,1,64,
+174,187,81,95,37,134,204,23,225,35,23,71,34,82,137,246,128,160,89,93,168,
+167,147,195,201,194,70,46,142,68,165,19,238,1,64,182,187,81,71,105,20,19,
+177,139,163,145,41,68,16,7,6,15,82,70,72,115,96,32,105,221,0,0,0,0,0,91,60,
+149,195,200,194,8,134,149,216,114,1,128,83,192,144,8,194,195,16,12,168,110,
+20,120,12,141,22,16,120,12,100,22,12,120,28,78,99,192,41,224,136,115,36,14,
+100,197,213,245,193,48,189,112,40,2,237,96,175,131,117,2,178,112,145,139,
+163,145,131,114,70,46,142,218,27,182,72,197,209,219,56,26,53,161,166,28,1,
+204,178,10,14,38,78,44,141,52,207,31,0,0,21,64,129,100,180,8,148,145,92,
+203,176,160,226,100,226,200,211,76,241,240,0,1,84,2,131,137,147,142,41,100,
+73,199,192,0,5,88,6,13,10,82,70,62,0,0,42,66,88,115,18,124,67,103,177,69,
+49,130,12,73,242,136,108,246,40,165,177,6,36,248,134,207,71,90,138,99,68,
+152,147,229,16,217,232,235,81,75,130,12,73,241,13,158,158,149,20,199,9,49,
+39,202,33,179,211,210,162,151,69,24,147,225,86,224,79,79,74,138,94,20,98,
+79,133,91,129,61,109,74,41,124,60,137,62,33,179,216,166,216,193,18,36,249,
+68,54,123,20,218,216,137,18,124,67,103,163,173,77,177,162,100,73,242,136,
+108,244,117,169,181,193,18,36,248,134,207,79,74,155,99,132,200,147,229,16,
+217,233,233,83,107,162,164,73,240,171,112,39,167,165,77,175,10,145,39,194,
+173,192,158,182,165,54,191,153,51,72,71,161,196,201,45,167,146,59,68,89,24,
+70,206,1,255,128,0,0,0,0,0,1,153,51,104,71,161,196,201,45,167,146,59,68,89,
+24,70,206,1,255,128,0,0,0,0,0,1,153,51,136,71,161,196,201,45,167,146,59,68,
+89,24,70,206,1,255,128,0,0,0,0,0,1,153,51,168,71,161,196,201,45,167,146,59,
+68,89,24,70,206,2,0,0,0,0,0,0,0,1,153,51,200,71,161,196,201,45,167,146,59,
+68,89,24,70,206,2,0,0,0,0,0,0,0,1,153,51,232,71,161,196,201,45,167,146,59,
+68,89,24,70,206,2,0,128,0,0,0,0,0,1,153,52,8,71,161,196,201,45,167,146,59,
+68,89,24,70,206,2,0,128,0,0,0,0,0,1,153,52,40,71,161,196,201,45,167,146,59,
+68,89,24,70,206,2,0,128,0,0,0,0,0,1,153,52,72,71,161,196,201,45,167,146,59,
+68,89,24,70,206,2,1,0,0,0,0,0,0,1,135,52,102,32,76,72,1,246,136,235,103,
+177,69,1,17,32,7,196,54,123,20,82,88,200,144,3,237,17,214,207,71,91,171,37,
+20,65,145,32,7,218,35,173,158,142,183,66,74,41,16,92,72,1,241,13,158,142,
+183,86,74,41,48,92,72,1,241,13,158,142,183,66,74,41,80,100,72,1,246,136,
+235,103,167,165,213,146,138,40,200,144,3,237,17,214,207,79,75,161,37,20,
+138,46,36,0,248,134,207,79,75,171,37,20,154,46,36,0,248,134,207,79,75,161,
+37,20,170,46,36,0,248,85,184,19,234,201,69,24,92,72,1,240,171,112,39,208,
+146,138,70,25,18,0,124,27,168,21,147,171,37,20,113,145,32,7,193,186,129,89,
+58,18,81,72,226,162,64,15,180,71,91,62,172,148,90,0,168,144,3,237,17,214,
+207,161,37,22,144,38,36,0,248,134,207,171,37,22,160,38,36,0,248,134,207,
+161,37,22,176,42,209,68,201,218,35,173,158,197,54,4,218,40,153,56,134,207,
+98,155,75,27,104,162,100,237,17,214,207,71,91,171,37,54,65,182,138,38,78,
+209,29,108,244,117,186,18,83,104,131,45,20,76,156,67,103,163,173,213,146,
+155,76,25,104,162,100,226,27,61,29,110,132,148,218,160,219,69,19,39,104,
+142,182,122,122,93,89,41,178,141,180,81,50,118,136,235,103,167,165,208,146,
+155,69,25,104,162,100,226,27,61,61,46,172,148,218,104,203,69,19,39,16,217,
+233,233,116,36,166,213,70,90,40,153,56,85,184,19,234,201,77,152,101,162,
+137,147,133,91,129,62,132,148,218,48,219,69,19,39,6,234,5,100,234,201,77,
+156,109,162,137,147,131,117,2,178,116,36,166,209,197,218,40,153,59,68,117,
+179,234,201,78,32,11,180,81,50,118,136,235,103,208,146,156,72,21,104,162,
+100,226,27,62,172,148,226,128,171,69,19,39,16,217,244,36,167,22,53,123,102,
+53,155,80,2,21,11,94,201,128,196,133,0,185,80,32,56,156,199,130,36,160,72,
+16,78,126,54,48,5,146,208,34,82,72,1,109,20,76,155,120,28,34,1,225,32,32,2,
+223,133,69,138,43,180,132,234,219,163,161,1,0,9,174,198,238,213,84,88,31,
+86,221,40,7,252,197,200,95,223,71,61,225,122,183,27,72,144,15,253,197,81,
+217,74,224,191,131,117,110,54,142,129,32,31,237,229,189,138,147,114,135,2,
+235,209,1,0,36,135,237,81,16,180,96,63,101,8,207,71,107,74,1,255,53,4,243,
+51,249,222,104,94,202,17,158,148,3,255,106,9,230,103,243,188,210,159,129,
+228,176,192,185,127,46,155,185,41,197,13,55,38,3,127,255,20,138,160,192,25,
+106,8,8,1,58,90,130,64,128,146,27,168,37,8,9,129,186,130,96,160,152,27,165,
+171,64,32,131,25,234,10,64,65,17,11,212,19,133,18,243,167,165,163,32,24,
+157,45,65,64,6,75,191,80,80,66,149,110,116,117,5,8,41,240,247,79,72,188,8,
+134,81,122,84,1,173,198,212,20,48,139,113,180,181,5,36,42,220,109,29,13,65,
+74,6,192,95,76,188,6,196,55,78,188,6,247,91,86,136,26,32,104,220,205,72,1,
+98,234,52,122,130,136,18,72,51,117,68,3,146,27,168,40,161,37,8,207,80,81,
+129,204,13,212,20,112,179,141,26,45,65,75,112,20,43,193,25,19,66,128,153,
+78,40,105,144,92,104,152,131,124,27,253,128,0,10,116,3,68,146,163,9,128,0,
+10,102,3,138,145,137,27,60,0,0,82,129,7,2,4,16,7,2,70,143,178,203,164,237,
+35,14,25,10,134,147,143,139,158,72,207,28,54,77,47,109,13,55,113,120,96,
+196,159,29,102,241,241,115,201,25,227,131,36,133,20,62,110,143,17,16,113,
+137,62,62,46,155,167,135,147,142,47,44,151,79,221,64,98,37,194,94,100,108,
+144,21,147,140,73,168,228,19,17,124,73,82,54,124,37,230,70,201,14,108,185,
+36,155,14,243,243,83,212,69,131,132,4,12,137,114,168,37,166,145,7,10,4,28,
+200,14,12,40,56,153,56,178,52,211,60,124,0,0,85,0,160,226,100,227,138,89,
+18,113,240,0,1,86,1,131,66,148,145,143,128,0,10,144,93,134,0,0,43,80,17,42,
+4,17,136,49,73,19,49,134,16,143,67,137,146,91,79,36,118,136,178,48,141,156,
+3,255,0,0,0,0,0,0,3,49,135,16,143,67,137,146,91,79,36,118,136,178,48,141,
+156,3,255,0,0,0,0,0,0,5,20,5,173,194,227,214,4,55,0,0,21,196,7,122,192,134,
+241,197,192,0,5,121,25,140,64,132,122,28,76,146,218,121,35,180,69,145,132,
+108,224,31,248,0,0,0,0,0,0,25,140,72,132,122,28,76,146,218,121,35,180,69,
+145,132,108,224,32,0,0,0,0,0,0,0,25,140,80,132,122,28,76,146,218,121,35,
+180,69,145,132,108,224,32,0,0,0,0,0,0,0,25,140,88,132,122,28,76,146,218,
+121,35,180,69,145,132,108,224,32,8,0,0,0,0,0,0,25,140,96,132,122,28,76,146,
+218,121,35,180,69,145,132,108,224,32,8,0,0,0,0,0,0,25,140,104,132,122,28,
+76,146,218,121,35,180,69,145,132,108,224,32,8,0,0,0,0,0,0,25,140,112,132,
+122,28,76,146,218,121,35,180,69,145,132,108,224,32,16,0,0,0,0,0,0,16,113,
+225,0,48,156,209,2,122,244,5,34,92,35,68,225,161,166,218,16,33,18,224,104,
+82,146,59,50,5,7,19,39,22,70,154,103,215,32,28,78,99,193,18,80,70,131,165,
+1,205,34,8,35,68,225,161,166,239,255,4,12,70,137,195,39,248,73,7,78,3,154,
+102,16,70,137,195,67,77,223,248,1,74,9,129,125,255,130,9,65,154,232,147,
+161,115,59,255,5,64,195,32,156,50,126,197,14,2,3,107,173,213,0,
};
#elif defined(DUK_USE_DOUBLE_ME)
-DUK_INTERNAL const duk_uint8_t duk_builtins_data[3819] = {
-144,148,105,221,32,68,52,228,62,12,104,200,165,134,148,248,81,77,61,191,
-135,35,154,103,34,72,6,157,159,197,145,77,245,126,52,130,106,234,163,196,
-52,226,18,51,161,26,113,1,60,37,64,190,18,49,116,116,33,26,113,1,92,136,26,
-98,112,145,139,163,165,8,211,136,14,228,72,82,68,141,17,56,72,197,209,212,
-132,105,196,5,242,88,108,193,126,18,49,116,117,161,26,113,1,60,158,30,78,
-18,49,116,118,33,26,113,1,29,164,80,78,198,46,142,212,36,68,51,71,232,59,
-147,60,93,110,79,15,39,9,24,186,33,13,63,111,185,16,211,206,251,114,98,17,
-171,160,11,199,197,215,196,66,26,102,38,68,53,212,77,136,104,255,5,114,120,
-121,7,192,70,32,192,67,95,249,59,13,13,127,228,248,134,191,242,133,208,215,
-254,81,204,67,95,249,75,33,13,127,229,61,84,53,255,149,52,80,215,254,85,
-217,67,95,249,91,121,13,90,181,168,134,143,152,95,38,75,207,132,104,156,50,
-70,33,163,225,66,249,50,94,124,25,4,225,146,49,14,24,28,196,0,0,15,135,240,
-0,0,0,12,204,0,0,15,7,240,0,0,0,12,188,72,6,176,77,225,28,24,103,14,33,197,
-138,113,227,28,152,231,46,65,205,19,194,84,11,225,35,23,68,231,138,228,64,
-211,19,132,140,93,19,162,59,145,33,73,18,52,68,225,35,23,68,233,139,228,
-176,217,130,252,36,98,232,157,81,60,158,30,78,18,49,116,78,184,142,210,40,
-39,99,23,68,236,201,59,114,142,224,126,14,138,152,30,67,188,23,143,139,175,
-131,194,135,228,72,85,144,83,60,53,163,208,76,60,68,211,197,78,60,116,243,
-200,80,60,149,19,202,82,60,181,51,204,84,60,213,83,206,86,60,240,190,76,
-151,159,8,209,56,100,137,232,133,242,100,188,248,50,9,195,36,79,73,26,238,
-108,129,15,4,100,78,33,179,207,160,41,224,140,137,194,173,192,158,120,128,
-168,151,26,14,55,58,64,132,75,133,67,81,50,103,8,18,50,9,195,39,105,20,101,
-136,36,50,9,195,39,105,20,11,174,99,220,210,54,121,114,4,145,162,112,201,
-218,69,25,130,9,17,162,112,201,218,69,2,235,152,247,52,141,158,100,128,196,
-144,128,242,102,136,17,70,146,66,3,201,160,32,0,130,225,48,113,137,62,62,
-46,155,167,135,147,142,47,24,147,79,205,68,48,98,79,142,179,120,248,185,
-228,140,241,193,146,66,138,31,55,71,126,129,51,18,124,117,155,199,197,207,
-36,103,142,52,12,36,184,100,129,129,41,32,205,221,175,3,10,36,4,201,188,64,
-112,200,84,52,156,124,92,242,70,120,223,48,64,100,42,26,78,62,46,121,35,52,
-18,91,212,2,72,128,95,20,128,197,137,9,146,113,73,8,190,36,169,27,62,18,
-243,35,100,135,54,92,66,4,34,92,145,0,178,15,132,64,132,75,133,139,178,70,
-240,137,6,34,92,37,230,70,201,1,89,56,36,4,81,49,46,25,5,76,73,241,214,111,
-31,23,60,145,158,57,44,48,46,92,184,100,160,145,46,2,0,201,168,207,198,230,
-144,117,60,176,48,156,160,48,188,192,7,28,18,227,172,222,62,46,121,35,60,
-113,200,26,137,113,241,116,221,60,60,156,113,121,4,20,124,92,242,70,120,
-226,37,194,54,140,36,64,21,147,146,68,24,32,57,0,125,78,84,0,160,123,215,
-140,146,1,4,5,175,40,124,8,20,52,121,51,228,24,96,129,209,46,2,49,6,20,135,
-33,20,53,50,128,194,65,4,12,39,52,64,155,31,48,112,72,6,247,62,16,1,31,73,
-30,25,240,60,73,82,70,68,138,0,89,29,5,156,96,2,201,104,17,35,160,18,78,
-140,228,16,26,79,90,4,73,43,192,244,108,142,130,206,89,240,58,26,50,95,142,
-43,159,65,107,4,167,196,52,100,191,28,87,63,128,15,255,240,164,169,35,136,
-6,128,146,115,9,0,210,7,43,163,194,0,71,128,105,65,176,15,128,105,131,21,
-11,153,35,0,211,134,137,7,65,18,33,244,23,18,14,130,39,34,131,30,113,15,
-224,3,255,254,12,80,81,133,139,153,193,28,17,224,156,50,119,15,131,75,23,
-51,130,112,201,199,185,13,159,116,248,228,68,219,66,149,83,83,238,3,11,238,
-0,48,142,8,240,19,239,144,40,71,4,120,39,12,156,4,252,4,11,19,134,78,61,
-200,108,248,9,248,9,3,9,205,16,39,225,62,7,67,70,75,241,197,241,154,5,172,
-18,159,16,209,146,252,113,124,102,144,106,220,32,44,156,19,152,240,68,158,
-66,2,176,19,17,252,164,7,137,30,176,8,158,116,3,72,128,136,143,232,32,44,
-150,129,19,210,128,89,61,104,159,169,1,50,160,101,56,161,166,246,160,46,
-110,226,221,98,71,130,4,137,222,0,140,221,197,184,64,89,56,183,88,145,224,
-129,34,119,128,23,55,114,143,121,35,193,2,68,239,2,17,155,184,183,8,11,39,
-40,247,146,60,16,36,78,240,32,73,197,12,247,128,26,36,121,1,63,49,2,165,48,
-70,114,229,145,51,250,205,2,8,209,203,150,68,207,235,52,130,16,209,46,131,
-36,188,70,128,210,160,101,56,251,16,131,28,7,35,38,218,50,234,103,130,97,
-103,129,6,73,0,79,88,11,237,84,11,161,32,127,255,247,191,255,255,255,255,
-137,235,16,221,170,129,116,36,0,0,0,0,0,16,0,0,12,196,0,0,15,135,240,0,0,0,
-2,61,123,164,137,162,164,218,67,74,134,162,120,128,0,1,224,254,0,0,0,0,71,
-173,33,129,52,84,155,72,105,80,212,79,16,0,0,60,63,192,0,0,0,7,36,38,218,0,
-0,0,0,0,0,0,0,4,29,78,224,140,38,216,140,46,228,0,243,119,10,139,144,123,
-82,6,205,220,37,222,230,145,179,64,23,180,32,92,221,199,196,130,68,144,230,
-237,200,131,44,24,43,193,25,18,185,0,251,73,138,199,240,27,93,106,192,57,
-41,54,210,0,0,62,31,192,0,0,0,49,58,155,192,12,155,184,48,76,156,148,226,
-134,154,240,32,201,187,147,67,9,201,78,40,105,175,2,225,47,3,18,155,184,
-183,8,11,39,6,9,147,146,156,80,211,94,7,37,55,113,110,16,22,78,77,12,39,37,
-56,161,166,188,16,48,215,130,14,30,240,66,213,93,35,11,124,0,230,36,249,52,
-48,151,192,22,98,79,133,162,215,204,16,17,178,16,199,24,147,237,38,34,246,
-139,95,48,64,70,200,68,16,98,79,140,115,102,123,33,20,89,137,62,210,98,103,
-92,217,158,200,70,14,98,79,131,4,201,100,35,138,49,39,218,76,67,232,38,75,
-33,32,49,137,62,12,24,178,18,68,152,147,237,38,33,244,24,178,18,132,24,147,
-225,221,72,202,200,75,22,98,79,180,152,143,215,82,50,178,19,5,24,147,227,
-16,218,76,146,178,19,70,152,147,237,38,38,117,13,164,201,43,33,56,81,137,
-62,72,130,115,71,43,33,60,105,137,62,210,98,151,72,39,52,114,178,20,7,152,
-147,227,16,181,162,68,19,154,57,89,10,36,140,73,246,147,19,58,133,173,18,
-32,156,209,202,200,82,34,98,79,147,67,9,151,52,156,113,75,34,78,208,1,228,
-73,242,104,97,46,16,62,68,159,24,133,173,18,32,156,209,202,217,83,37,34,79,
-180,152,153,212,45,104,145,4,230,142,86,202,160,169,18,124,145,4,230,142,
-86,215,213,27,34,79,180,152,165,210,9,205,28,173,175,172,42,68,159,24,134,
-210,100,149,183,245,198,200,147,237,38,38,117,13,164,201,43,111,236,8,145,
-39,195,186,145,149,185,246,69,200,147,237,38,35,245,212,140,173,207,180,30,
-68,159,6,9,146,217,91,21,34,79,180,152,135,208,76,150,202,224,137,18,124,
-99,155,51,219,95,116,92,137,62,210,98,103,92,217,158,218,251,194,228,73,
-240,180,90,249,130,2,54,223,223,29,34,79,180,152,139,218,45,124,193,1,27,
-111,240,33,204,73,243,4,4,108,134,8,60,137,62,96,128,141,178,193,193,154,3,
-147,32,227,36,0,0,0,0,0,0,0,0,99,115,245,195,19,159,176,75,175,159,176,24,
-172,253,129,49,121,251,2,176,66,92,130,235,16,18,100,148,251,36,106,123,64,
-65,158,3,147,160,108,202,62,68,165,107,243,227,113,198,211,62,39,20,108,
-115,226,241,130,106,113,224,78,162,4,242,130,236,197,60,37,64,190,18,49,
-116,114,37,40,157,76,9,229,37,217,138,185,16,52,196,225,35,23,71,34,82,137,
-213,64,158,84,93,152,187,145,33,73,18,52,68,225,35,23,71,34,82,137,213,192,
-158,86,93,152,175,146,195,102,11,240,145,139,163,145,41,68,235,32,79,44,46,
-204,83,201,225,228,225,35,23,71,34,82,137,214,192,158,90,93,152,163,180,
-138,9,216,197,209,200,148,161,194,32,30,18,0,85,248,42,3,74,184,164,88,78,
-173,186,58,16,44,90,192,144,5,149,109,110,193,245,109,210,128,132,93,204,
-127,222,115,245,252,23,171,113,180,137,1,28,87,220,255,250,8,173,148,55,86,
-227,104,232,18,3,222,94,217,248,119,41,48,168,46,189,16,62,200,66,80,6,11,
-81,21,3,246,80,140,244,118,180,160,79,80,115,31,230,157,191,179,5,236,161,
-25,233,64,158,160,246,63,205,59,127,102,41,248,30,75,12,11,151,242,233,187,
-146,156,80,211,114,96,54,230,41,20,129,128,50,211,16,16,2,116,180,196,129,
-1,36,55,76,74,16,19,3,116,196,193,65,48,55,75,80,128,65,6,51,211,20,128,
-130,34,23,166,39,6,39,75,76,80,1,146,239,211,20,16,165,91,157,29,49,66,10,
-124,61,211,209,175,1,173,198,211,20,48,139,113,180,180,197,36,42,220,109,
-29,13,49,74,6,192,95,72,188,6,196,55,74,188,6,247,91,80,136,26,32,104,220,
-205,56,1,98,234,52,122,98,136,14,72,110,152,162,132,148,35,61,49,70,7,48,
-55,76,81,194,206,52,104,180,197,45,192,80,175,4,100,77,10,2,101,56,161,166,
-65,113,162,98,8,3,131,7,169,35,36,57,176,0,40,116,208,0,0,0,0,45,158,10,
-225,223,132,17,13,43,176,228,3,0,167,129,32,17,133,134,32,25,80,220,40,240,
-25,26,44,32,240,24,200,44,24,240,56,156,199,128,83,193,17,7,4,13,128,0,10,
-79,202,28,223,195,1,197,72,196,141,159,220,7,48,33,7,8,3,152,49,117,60,240,
-76,47,60,9,224,187,56,43,224,221,64,172,156,36,98,232,228,96,220,145,139,
-163,182,134,237,146,49,116,118,206,6,141,104,105,136,32,14,4,128,160,123,
-215,140,147,32,145,57,178,156,104,41,228,151,168,225,144,168,105,56,248,
-185,228,140,241,190,100,209,244,80,210,116,151,134,12,73,241,214,111,31,23,
-60,145,158,56,50,72,81,67,230,232,239,209,7,24,147,227,226,233,186,120,121,
-56,226,241,137,116,189,52,6,34,92,37,230,70,201,1,89,56,36,154,110,25,49,
-23,196,149,35,103,194,94,100,108,144,230,203,136,73,174,234,63,52,252,212,
-87,0,131,138,4,12,137,114,168,37,166,144,230,37,5,7,19,39,22,70,154,103,
-143,252,4,11,37,160,68,164,139,7,24,3,152,182,20,28,76,156,89,26,105,158,
-63,240,5,7,19,39,28,82,200,147,143,253,0,193,161,74,72,199,253,132,176,230,
-36,248,134,207,98,138,99,4,24,147,229,16,217,236,81,75,98,12,73,241,13,158,
-142,181,20,198,137,49,39,202,33,179,209,214,162,151,4,24,147,226,27,61,61,
-42,41,142,18,98,79,148,67,103,167,165,69,46,138,49,39,194,173,192,158,158,
-149,20,188,40,196,159,10,183,2,122,218,148,82,248,121,18,124,67,103,177,77,
-177,130,36,73,242,136,108,246,41,181,177,18,36,248,134,207,71,90,155,99,68,
-200,147,229,16,217,232,235,83,107,130,36,73,241,13,158,158,149,54,199,9,
-145,39,202,33,179,211,210,166,215,69,72,147,225,86,224,79,79,74,155,94,21,
-34,79,133,91,129,61,109,74,109,126,14,56,7,6,20,28,76,156,89,26,105,158,63,
-240,5,7,19,39,28,82,200,147,143,253,0,193,161,74,72,199,253,130,235,191,
-232,8,149,2,8,196,24,164,137,141,200,8,71,161,196,201,45,167,146,59,68,89,
-24,70,206,0,0,7,129,248,0,0,0,1,142,49,232,71,161,196,201,45,167,146,59,68,
-89,24,70,206,0,0,7,129,248,0,0,0,1,141,201,8,71,161,196,201,45,167,146,59,
-68,89,24,70,206,0,0,7,129,248,0,0,0,2,138,2,214,225,113,235,2,27,128,0,10,
-66,3,189,96,67,120,226,224,0,2,148,140,113,145,66,61,14,38,73,109,60,145,
-218,34,200,194,54,112,0,0,60,15,192,0,0,0,12,110,80,66,61,14,38,73,109,60,
-145,218,34,200,194,54,112,0,0,60,15,192,0,0,0,12,113,147,66,61,14,38,73,
-109,60,145,218,34,200,194,54,112,0,0,60,15,192,0,0,0,12,110,88,66,61,14,38,
-73,109,60,145,218,34,200,194,54,112,0,0,0,16,0,0,0,0,12,113,149,66,61,14,
-38,73,109,60,145,218,34,200,194,54,112,0,0,0,16,0,0,0,0,12,110,96,66,61,14,
-38,73,109,60,145,218,34,200,194,54,112,0,0,0,16,0,0,0,0,12,113,151,66,61,
-14,38,73,109,60,145,218,34,200,194,54,112,0,0,0,16,0,0,0,0,12,110,104,66,
-61,14,38,73,109,60,145,218,34,200,194,54,112,0,0,4,16,0,0,0,0,12,113,153,
-66,61,14,38,73,109,60,145,218,34,200,194,54,112,0,0,4,16,0,0,0,0,12,110,
-112,66,61,14,38,73,109,60,145,218,34,200,194,54,112,0,0,4,16,0,0,0,0,12,
-113,155,66,61,14,38,73,109,60,145,218,34,200,194,54,112,0,0,4,16,0,0,0,0,
-12,110,120,66,61,14,38,73,109,60,145,218,34,200,194,54,112,0,0,4,16,0,0,0,
-0,12,113,157,66,61,14,38,73,109,60,145,218,34,200,194,54,112,0,0,4,16,0,0,
-0,0,12,110,128,66,61,14,38,73,109,60,145,218,34,200,194,54,112,0,0,8,16,0,
-0,0,0,12,113,159,66,61,14,38,73,109,60,145,218,34,200,194,54,112,0,0,8,16,
-0,0,0,0,8,58,32,128,24,78,104,129,61,82,2,145,46,17,162,112,208,211,107,
-200,16,137,112,52,41,73,29,113,2,131,137,147,139,35,77,51,234,80,14,39,49,
-224,137,40,35,100,141,9,136,19,18,0,125,162,58,217,236,81,64,68,72,1,241,
-13,158,197,20,150,50,36,0,251,68,117,179,209,214,234,201,69,16,100,72,1,
-246,136,235,103,163,173,208,146,138,68,23,18,0,124,67,103,163,173,213,146,
-138,76,23,18,0,124,67,103,163,173,208,146,138,84,25,18,0,125,162,58,217,
-233,233,117,100,162,138,50,36,0,251,68,117,179,211,210,232,73,69,34,139,
-137,0,62,33,179,211,210,234,201,69,38,139,137,0,62,33,179,211,210,232,73,
-69,42,139,137,0,62,21,110,4,250,178,81,70,23,18,0,124,42,220,9,244,36,162,
-145,134,68,128,31,6,234,5,100,234,201,69,28,100,72,1,240,110,160,86,78,132,
-148,82,56,168,144,3,237,17,214,207,171,37,22,128,42,36,0,251,68,117,179,
-232,73,69,164,9,137,0,62,33,179,234,201,69,168,9,137,0,62,33,179,232,73,69,
-172,10,180,81,50,118,136,235,103,177,77,129,54,138,38,78,33,179,216,166,
-210,198,218,40,153,59,68,117,179,209,214,234,201,77,144,109,162,137,147,
-180,71,91,61,29,110,132,148,218,32,203,69,19,39,16,217,232,235,117,100,166,
-211,6,90,40,153,56,134,207,71,91,161,37,54,168,54,209,68,201,218,35,173,
-158,158,151,86,74,108,163,109,20,76,157,162,58,217,233,233,116,36,166,209,
-70,90,40,153,56,134,207,79,75,171,37,54,154,50,209,68,201,196,54,122,122,
-93,9,41,181,81,150,138,38,78,21,110,4,250,178,83,102,25,104,162,100,225,86,
-224,79,161,37,54,140,54,209,68,201,193,186,129,89,58,178,83,103,27,104,162,
-100,224,221,64,172,157,9,41,180,113,118,138,38,78,209,29,108,250,178,83,
-136,2,237,20,76,157,162,58,217,244,36,167,18,5,90,40,153,56,134,207,171,37,
-56,160,42,209,68,201,196,54,125,9,41,197,141,78,197,141,86,192,0,133,66,
-215,173,96,49,33,64,46,84,8,14,39,49,224,137,40,18,4,19,159,141,100,1,100,
-180,8,148,146,0,91,69,19,38,202,8,58,64,28,209,160,130,52,78,26,26,110,255,
-80,64,196,104,156,50,125,4,144,116,192,57,165,97,4,104,156,52,52,221,254,
-64,20,160,152,23,223,228,32,148,25,174,137,58,23,51,191,200,84,12,50,9,195,
-39,196,80,
+DUK_INTERNAL const duk_uint8_t duk_builtins_data[3972] = {
+144,148,105,223,160,68,52,228,62,12,104,200,165,132,52,167,194,138,105,242,
+252,57,28,211,57,18,64,52,238,62,44,138,111,171,241,164,19,87,125,30,33,
+167,16,145,159,8,211,136,9,225,42,5,240,145,139,163,163,8,211,136,10,228,
+64,211,19,132,140,93,29,56,70,156,64,119,34,66,146,36,104,137,194,70,46,
+142,172,35,78,32,47,146,195,102,11,240,145,139,163,175,8,211,136,9,228,240,
+242,112,145,139,163,179,8,211,136,8,237,34,130,118,49,116,118,225,26,48,0,
+1,80,29,201,158,46,183,39,135,147,132,140,93,16,132,76,66,33,8,66,16,132,
+33,8,66,34,33,154,112,0,1,73,247,35,79,91,237,198,174,192,47,31,23,95,17,
+13,51,19,35,93,68,216,209,128,0,10,192,174,79,15,32,248,8,196,24,8,107,192,
+0,5,98,118,27,94,0,0,43,19,227,94,0,0,43,20,46,215,128,0,10,197,28,198,188,
+0,0,86,41,100,53,224,0,2,177,79,85,175,0,0,21,138,154,45,120,0,0,172,85,
+217,107,192,0,5,98,182,243,86,193,106,52,127,66,249,50,94,124,35,68,225,
+146,49,13,31,170,23,201,146,243,224,200,39,12,145,136,67,134,11,49,0,0,3,
+225,252,0,0,0,3,51,0,0,3,193,252,0,0,0,3,47,18,1,172,19,120,71,10,25,196,
+136,113,162,156,136,199,42,57,204,144,115,132,240,149,2,248,72,197,209,58,
+2,185,16,52,196,225,35,23,68,233,14,228,72,82,68,141,17,56,72,197,209,58,
+130,249,44,54,96,191,9,24,186,39,88,79,39,135,147,132,140,93,19,176,35,180,
+138,9,216,197,209,59,82,79,31,40,242,1,248,58,42,96,121,14,232,94,62,46,
+190,15,38,31,145,33,86,65,76,242,150,143,69,48,242,179,79,45,56,243,51,207,
+53,64,243,116,79,57,72,243,180,207,61,80,243,245,79,65,88,244,34,249,50,94,
+124,35,68,225,146,39,163,23,201,146,243,224,200,39,12,145,61,40,183,146,37,
+116,88,6,136,158,244,241,174,230,202,80,135,130,50,39,16,217,231,208,20,
+240,70,68,225,86,224,79,60,64,84,75,141,7,27,157,32,66,37,194,161,168,153,
+51,132,9,25,4,225,147,180,138,50,196,18,25,4,225,147,180,138,5,215,49,238,
+105,27,60,185,2,72,209,56,100,237,34,140,193,4,136,209,56,100,237,34,129,
+117,204,123,154,70,207,50,64,98,72,64,121,51,68,8,163,73,33,1,228,208,16,0,
+65,112,152,56,196,159,31,23,77,211,195,201,199,23,150,73,169,234,34,24,49,
+39,199,89,188,124,92,242,70,120,224,201,33,69,15,155,163,196,64,153,137,62,
+58,205,227,226,231,146,51,199,26,6,18,92,130,64,192,148,144,102,240,23,129,
+133,18,2,100,224,160,56,100,42,26,78,62,46,121,35,60,112,216,32,50,21,13,
+39,31,23,60,145,154,9,46,18,1,36,64,47,148,64,98,196,132,201,57,68,132,95,
+18,84,141,159,9,121,145,178,67,155,46,73,2,17,46,72,128,89,7,199,32,66,37,
+194,197,217,35,120,228,131,17,46,18,243,35,100,128,172,156,98,2,40,152,151,
+32,130,166,36,248,235,55,143,139,158,72,207,28,150,24,23,46,92,130,80,72,
+151,21,0,100,213,103,229,245,8,186,190,144,24,78,136,24,94,152,3,142,9,113,
+214,111,31,23,60,145,158,57,164,13,68,184,248,186,110,158,30,78,56,188,226,
+10,62,46,121,35,60,113,18,225,27,70,18,32,10,201,208,32,134,214,208,200,84,
+52,156,49,39,50,71,107,107,152,129,13,173,161,144,168,105,57,34,78,100,142,
+214,215,49,16,134,214,210,220,229,81,252,49,39,50,71,107,107,158,65,13,173,
+165,185,202,163,249,34,78,100,142,214,215,60,146,12,16,28,128,62,175,42,6,
+143,36,136,16,64,90,242,135,192,129,67,71,147,62,65,5,215,231,214,6,215,62,
+180,8,49,1,3,162,92,4,98,12,41,14,67,40,106,229,1,132,130,8,24,78,104,129,
+54,62,96,224,144,13,238,124,32,2,62,146,60,51,224,120,146,164,140,137,20,0,
+178,58,11,56,192,5,146,208,34,71,64,36,157,25,200,32,52,158,180,8,146,87,
+129,232,217,29,5,156,179,224,116,52,100,191,28,87,62,130,214,9,79,136,104,
+201,126,56,174,127,0,31,255,225,73,82,71,16,13,1,36,230,18,1,164,14,87,71,
+132,0,143,0,210,131,96,31,0,211,6,42,23,50,70,1,167,13,18,14,130,36,67,232,
+46,36,29,4,78,69,6,60,226,31,192,7,255,252,24,192,163,11,23,51,130,56,35,
+193,56,100,243,31,6,150,46,103,4,225,147,143,114,27,63,57,241,200,169,194,
+133,42,166,175,240,6,23,240,0,97,28,17,224,39,233,32,80,142,8,240,78,25,56,
+9,250,136,22,39,12,156,123,144,217,240,19,245,18,6,19,154,32,79,214,124,14,
+134,140,151,227,139,237,52,11,88,37,62,33,163,37,248,226,251,77,32,213,184,
+64,89,56,39,49,224,137,61,196,5,96,38,35,251,200,15,18,61,96,17,62,40,6,
+145,1,17,31,228,64,89,45,2,39,205,0,178,122,209,63,162,2,101,64,202,113,67,
+77,247,64,92,221,197,186,196,143,4,9,19,208,1,25,187,139,112,128,178,113,
+110,177,35,193,2,68,244,0,46,110,229,30,242,71,130,4,137,232,4,35,55,113,
+110,16,22,78,81,239,36,120,32,72,158,128,64,147,138,25,249,0,52,72,242,2,
+127,2,5,74,96,140,229,203,34,103,250,154,4,17,163,151,44,137,159,234,105,4,
+33,162,93,6,73,123,13,1,165,64,202,113,251,33,6,64,14,71,78,20,101,213,207,
+4,194,207,2,12,162,0,158,176,23,218,168,23,66,64,255,255,239,127,255,255,
+255,255,19,214,33,187,85,2,232,72,0,0,0,0,0,32,0,0,25,136,0,0,31,15,224,0,
+0,0,4,122,247,73,19,69,73,180,134,149,13,68,241,0,0,3,193,252,0,0,0,0,143,
+90,67,2,104,169,54,144,210,161,168,158,32,0,0,120,127,128,0,0,0,14,73,78,
+20,0,0,0,0,0,0,0,0,8,58,189,233,24,77,217,24,93,240,1,230,238,21,23,32,247,
+68,13,155,184,75,189,205,35,102,128,47,114,64,185,187,143,137,4,137,33,205,
+222,17,6,96,48,87,130,50,37,114,1,246,147,21,143,224,54,186,213,128,114,90,
+112,164,0,0,124,63,128,0,0,0,98,117,119,128,25,55,112,96,153,57,41,197,13,
+53,224,65,147,119,38,134,19,146,156,80,211,94,5,194,94,6,37,55,113,110,16,
+22,78,12,19,39,37,56,161,166,188,14,74,110,226,220,32,44,156,154,24,78,74,
+113,67,77,120,32,97,175,4,28,61,224,133,172,186,70,22,248,1,204,73,242,104,
+97,47,128,44,196,159,11,69,175,152,32,35,100,33,142,49,39,218,76,69,237,22,
+190,96,128,141,144,136,32,196,159,24,230,204,246,66,40,179,18,125,164,196,
+206,185,179,61,144,140,28,196,159,6,9,146,200,71,20,98,79,180,152,135,208,
+76,150,66,64,99,18,124,24,49,100,36,137,49,39,218,76,67,232,49,100,37,8,49,
+39,195,186,145,149,144,150,44,196,159,105,49,31,174,164,101,100,38,10,49,
+39,198,33,180,153,37,100,38,141,49,39,218,76,76,234,27,73,146,86,66,112,
+163,18,124,145,4,230,142,86,66,120,211,18,125,164,197,46,144,78,104,229,
+100,40,15,49,39,198,33,107,68,136,39,52,114,178,20,73,24,147,237,38,38,117,
+11,90,36,65,57,163,149,144,164,68,196,159,38,134,19,46,105,56,226,150,68,
+157,160,3,200,147,228,208,194,92,32,124,137,62,49,11,90,36,65,57,163,149,
+178,166,74,68,159,105,49,51,168,90,209,34,9,205,28,173,149,65,82,36,249,34,
+9,205,28,173,175,170,54,68,159,105,49,75,164,19,154,57,91,95,88,84,137,62,
+49,13,164,201,43,111,235,141,145,39,218,76,76,234,27,73,146,86,223,216,17,
+34,79,135,117,35,43,115,236,139,145,39,218,76,71,235,169,25,91,159,104,60,
+137,62,12,19,37,178,182,42,68,159,105,49,15,160,153,45,149,193,18,36,248,
+199,54,103,182,190,232,185,18,125,164,196,206,185,179,61,181,247,133,200,
+147,225,104,181,243,4,4,109,191,190,58,68,159,105,49,23,180,90,249,130,2,
+54,223,224,67,152,147,230,8,8,217,12,16,121,18,124,193,1,27,101,131,131,56,
+7,38,193,198,72,0,0,0,0,0,0,0,0,198,231,240,134,39,63,136,151,95,63,136,49,
+89,252,66,98,243,248,133,96,132,185,5,224,32,36,201,41,248,200,213,249,0,
+131,64,7,39,192,218,148,124,137,74,216,231,198,227,141,182,124,78,40,217,
+231,197,227,4,213,227,192,159,72,10,5,21,218,138,120,74,129,124,36,98,232,
+228,74,81,62,160,20,10,107,181,21,114,32,105,137,194,70,46,142,68,165,19,
+235,1,64,170,187,81,119,34,66,146,36,104,137,194,70,46,142,68,165,19,236,1,
+64,174,187,81,95,37,134,204,23,225,35,23,71,34,82,137,246,128,160,89,93,
+168,167,147,195,201,194,70,46,142,68,165,19,238,1,64,182,187,81,71,105,20,
+19,177,139,163,145,41,68,16,7,6,15,82,70,72,115,96,0,93,105,160,0,0,0,0,91,
+60,149,195,200,194,8,134,149,216,114,1,128,83,192,144,8,194,195,16,12,168,
+110,20,120,12,141,22,16,120,12,100,22,12,120,28,78,99,192,41,224,136,115,
+36,14,100,197,213,245,193,48,189,112,40,2,237,96,175,131,117,2,178,112,145,
+139,163,145,131,114,70,46,142,218,27,182,72,197,209,219,56,26,53,161,166,
+28,1,204,178,10,14,38,78,44,141,52,207,31,0,0,21,64,129,100,180,8,148,145,
+92,203,176,160,226,100,226,200,211,76,241,240,0,1,84,2,131,137,147,142,41,
+100,73,199,192,0,5,88,6,13,10,82,70,62,0,0,42,66,88,115,18,124,67,103,177,
+69,49,130,12,73,242,136,108,246,40,165,177,6,36,248,134,207,71,90,138,99,
+68,152,147,229,16,217,232,235,81,75,130,12,73,241,13,158,158,149,20,199,9,
+49,39,202,33,179,211,210,162,151,69,24,147,225,86,224,79,79,74,138,94,20,
+98,79,133,91,129,61,109,74,41,124,60,137,62,33,179,216,166,216,193,18,36,
+249,68,54,123,20,218,216,137,18,124,67,103,163,173,77,177,162,100,73,242,
+136,108,244,117,169,181,193,18,36,248,134,207,79,74,155,99,132,200,147,229,
+16,217,233,233,83,107,162,164,73,240,171,112,39,167,165,77,175,10,145,39,
+194,173,192,158,182,165,54,191,153,51,72,71,161,196,201,45,167,146,59,68,
+89,24,70,206,0,0,7,129,248,0,0,0,1,153,51,104,71,161,196,201,45,167,146,59,
+68,89,24,70,206,0,0,7,129,248,0,0,0,1,153,51,136,71,161,196,201,45,167,146,
+59,68,89,24,70,206,0,0,7,129,248,0,0,0,1,153,51,168,71,161,196,201,45,167,
+146,59,68,89,24,70,206,0,0,0,2,0,0,0,0,1,153,51,200,71,161,196,201,45,167,
+146,59,68,89,24,70,206,0,0,0,2,0,0,0,0,1,153,51,232,71,161,196,201,45,167,
+146,59,68,89,24,70,206,0,0,0,130,0,0,0,0,1,153,52,8,71,161,196,201,45,167,
+146,59,68,89,24,70,206,0,0,0,130,0,0,0,0,1,153,52,40,71,161,196,201,45,167,
+146,59,68,89,24,70,206,0,0,0,130,0,0,0,0,1,153,52,72,71,161,196,201,45,167,
+146,59,68,89,24,70,206,0,0,1,2,0,0,0,0,1,135,52,102,32,76,72,1,246,136,235,
+103,177,69,1,17,32,7,196,54,123,20,82,88,200,144,3,237,17,214,207,71,91,
+171,37,20,65,145,32,7,218,35,173,158,142,183,66,74,41,16,92,72,1,241,13,
+158,142,183,86,74,41,48,92,72,1,241,13,158,142,183,66,74,41,80,100,72,1,
+246,136,235,103,167,165,213,146,138,40,200,144,3,237,17,214,207,79,75,161,
+37,20,138,46,36,0,248,134,207,79,75,171,37,20,154,46,36,0,248,134,207,79,
+75,161,37,20,170,46,36,0,248,85,184,19,234,201,69,24,92,72,1,240,171,112,
+39,208,146,138,70,25,18,0,124,27,168,21,147,171,37,20,113,145,32,7,193,186,
+129,89,58,18,81,72,226,162,64,15,180,71,91,62,172,148,90,0,168,144,3,237,
+17,214,207,161,37,22,144,38,36,0,248,134,207,171,37,22,160,38,36,0,248,134,
+207,161,37,22,176,42,209,68,201,218,35,173,158,197,54,4,218,40,153,56,134,
+207,98,155,75,27,104,162,100,237,17,214,207,71,91,171,37,54,65,182,138,38,
+78,209,29,108,244,117,186,18,83,104,131,45,20,76,156,67,103,163,173,213,
+146,155,76,25,104,162,100,226,27,61,29,110,132,148,218,160,219,69,19,39,
+104,142,182,122,122,93,89,41,178,141,180,81,50,118,136,235,103,167,165,208,
+146,155,69,25,104,162,100,226,27,61,61,46,172,148,218,104,203,69,19,39,16,
+217,233,233,116,36,166,213,70,90,40,153,56,85,184,19,234,201,77,152,101,
+162,137,147,133,91,129,62,132,148,218,48,219,69,19,39,6,234,5,100,234,201,
+77,156,109,162,137,147,131,117,2,178,116,36,166,209,197,218,40,153,59,68,
+117,179,234,201,78,32,11,180,81,50,118,136,235,103,208,146,156,72,21,104,
+162,100,226,27,62,172,148,226,128,171,69,19,39,16,217,244,36,167,22,53,123,
+102,53,155,80,2,21,11,94,201,128,196,133,0,185,80,32,56,156,199,130,36,160,
+72,16,78,126,54,48,5,146,208,34,82,72,1,109,20,76,155,120,28,34,1,225,32,5,
+95,130,160,52,171,138,69,132,234,219,163,161,2,197,172,9,0,89,86,214,236,
+31,86,221,40,8,69,220,199,253,231,63,95,193,122,183,27,72,144,17,197,125,
+207,255,160,138,217,67,117,110,54,142,129,32,61,229,237,159,135,114,147,10,
+130,235,209,3,236,132,37,0,96,181,17,80,63,101,8,207,71,107,74,4,245,7,49,
+254,105,219,251,48,94,202,17,158,148,9,234,15,99,252,211,183,246,98,159,
+129,228,176,192,185,127,46,155,185,41,197,13,55,38,3,127,255,20,138,160,
+192,25,106,8,8,1,58,90,130,64,128,146,27,168,37,8,9,129,186,130,96,160,152,
+27,165,171,64,32,131,25,234,10,64,65,17,11,212,19,133,18,243,167,165,163,
+32,24,157,45,65,64,6,75,191,80,80,66,149,110,116,117,5,8,41,240,247,79,72,
+188,8,134,81,122,84,1,173,198,212,20,48,139,113,180,181,5,36,42,220,109,29,
+13,65,74,6,192,95,76,188,6,196,55,78,188,6,247,91,86,136,26,32,104,220,205,
+72,1,98,234,52,122,130,136,18,72,51,117,68,3,146,27,168,40,161,37,8,207,80,
+81,129,204,13,212,20,112,179,141,26,45,65,75,112,20,43,193,25,19,66,128,
+153,78,40,105,144,92,104,152,131,124,27,253,128,0,10,116,3,68,146,163,9,
+128,0,10,102,3,138,145,137,27,60,0,0,82,129,7,2,4,16,7,2,70,143,178,203,
+164,237,35,14,25,10,134,147,143,139,158,72,207,28,54,77,47,109,13,55,113,
+120,96,196,159,29,102,241,241,115,201,25,227,131,36,133,20,62,110,143,17,
+16,113,137,62,62,46,155,167,135,147,142,47,44,151,79,221,64,98,37,194,94,
+100,108,144,21,147,140,73,168,228,19,17,124,73,82,54,124,37,230,70,201,14,
+108,185,36,155,14,243,243,83,212,69,131,132,4,12,137,114,168,37,166,145,7,
+10,4,28,200,14,12,40,56,153,56,178,52,211,60,124,0,0,85,0,160,226,100,227,
+138,89,18,113,240,0,1,86,1,131,66,148,145,143,128,0,10,144,93,134,0,0,43,
+80,17,42,4,17,136,49,73,19,49,134,16,143,67,137,146,91,79,36,118,136,178,
+48,141,156,0,0,15,3,240,0,0,0,3,49,135,16,143,67,137,146,91,79,36,118,136,
+178,48,141,156,0,0,15,3,240,0,0,0,5,20,5,173,194,227,214,4,55,0,0,21,196,7,
+122,192,134,241,197,192,0,5,121,25,140,64,132,122,28,76,146,218,121,35,180,
+69,145,132,108,224,0,0,120,31,128,0,0,0,25,140,72,132,122,28,76,146,218,
+121,35,180,69,145,132,108,224,0,0,0,32,0,0,0,0,25,140,80,132,122,28,76,146,
+218,121,35,180,69,145,132,108,224,0,0,0,32,0,0,0,0,25,140,88,132,122,28,76,
+146,218,121,35,180,69,145,132,108,224,0,0,8,32,0,0,0,0,25,140,96,132,122,
+28,76,146,218,121,35,180,69,145,132,108,224,0,0,8,32,0,0,0,0,25,140,104,
+132,122,28,76,146,218,121,35,180,69,145,132,108,224,0,0,8,32,0,0,0,0,25,
+140,112,132,122,28,76,146,218,121,35,180,69,145,132,108,224,0,0,16,32,0,0,
+0,0,16,113,225,0,48,156,209,2,122,244,5,34,92,35,68,225,161,166,218,16,33,
+18,224,104,82,146,59,50,5,7,19,39,22,70,154,103,215,32,28,78,99,193,18,80,
+70,131,165,1,205,34,8,35,68,225,161,166,239,255,4,12,70,137,195,39,248,73,
+7,78,3,154,102,16,70,137,195,67,77,223,248,1,74,9,129,125,255,130,9,65,154,
+232,147,161,115,59,255,5,64,195,32,156,50,126,197,14,2,3,107,173,213,0,
};
#else
#error invalid endianness defines
@@ -11004,12 +11407,12 @@ DUK_INTERNAL DUK_COLD void duk_err_handle_error(duk_hthread *thr, duk_errcode_t
#if defined(DUK_USE_PARANOID_ERRORS)
DUK_INTERNAL DUK_COLD void duk_err_require_type_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx, const char *expect_name) {
DUK_ERROR_RAW_FMT3(thr, filename, linenumber, DUK_ERR_TYPE_ERROR, "%s required, found %s (stack index %ld)",
- expect_name, duk_get_type_name((duk_context *) thr, idx), (long) idx);
+ expect_name, duk_get_type_name(thr, idx), (long) idx);
}
#else
DUK_INTERNAL DUK_COLD void duk_err_require_type_index(duk_hthread *thr, const char *filename, duk_int_t linenumber, duk_idx_t idx, const char *expect_name) {
DUK_ERROR_RAW_FMT3(thr, filename, linenumber, DUK_ERR_TYPE_ERROR, "%s required, found %s (stack index %ld)",
- expect_name, duk_push_string_readable((duk_context *) thr, idx), (long) idx);
+ expect_name, duk_push_string_readable(thr, idx), (long) idx);
}
#endif
DUK_INTERNAL DUK_COLD void duk_err_error_internal(duk_hthread *thr, const char *filename, duk_int_t linenumber) {
@@ -11044,8 +11447,8 @@ DUK_INTERNAL DUK_COLD void duk_err_type_invalid_trap_result(duk_hthread *thr, co
* when non-verbose errors are used.
*/
-DUK_NORETURN(DUK_LOCAL_DECL void duk__err_shared(duk_hthread *thr, duk_uint_t code));
-DUK_LOCAL void duk__err_shared(duk_hthread *thr, duk_uint_t code) {
+DUK_NORETURN(DUK_LOCAL_DECL void duk__err_shared(duk_hthread *thr, duk_errcode_t code));
+DUK_LOCAL void duk__err_shared(duk_hthread *thr, duk_errcode_t code) {
DUK_ERROR_RAW(thr, NULL, 0, code, NULL);
}
DUK_INTERNAL DUK_COLD void duk_err_error(duk_hthread *thr) {
@@ -11087,6 +11490,17 @@ DUK_INTERNAL DUK_COLD void duk_default_fatal_handler(void *udata, const char *ms
/* Default behavior is to abort() on error. There's no printout
* which makes this awkward, so it's always recommended to use an
* explicit fatal error handler.
+ *
+ * ====================================================================
+ * NOTE: If you are seeing this, you are most likely dealing with an
+ * uncaught error. You should provide a fatal error handler in Duktape
+ * heap creation, and should consider using a protected call as your
+ * first call into an empty Duktape context to properly handle errors.
+ * See:
+ * - http://duktape.org/guide.html#error-handling
+ * - http://wiki.duktape.org/HowtoFatalErrors.html
+ * - http://duktape.org/api.html#taglist-protected
+ * ====================================================================
*/
DUK_D(DUK_DPRINT("built-in default fatal error handler called: %s", msg ? msg : "NULL"));
DUK_ABORT();
@@ -11928,8 +12342,8 @@ duk_codepoint_t duk__slow_case_conversion(duk_hthread *thr,
duk_codepoint_t start_i;
duk_codepoint_t start_o;
- DUK_UNREF(thr);
DUK_ASSERT(bd_ctx != NULL);
+ DUK_UNREF(thr);
DUK_DDD(DUK_DDDPRINT("slow case conversion for codepoint: %ld", (long) cp));
@@ -12111,15 +12525,14 @@ duk_codepoint_t duk__case_transform_helper(duk_hthread *thr,
* Replace valstack top with case converted version.
*/
-DUK_INTERNAL void duk_unicode_case_convert_string(duk_hthread *thr, duk_small_int_t uppercase) {
- duk_context *ctx = (duk_context *) thr;
+DUK_INTERNAL void duk_unicode_case_convert_string(duk_hthread *thr, duk_bool_t uppercase) {
duk_hstring *h_input;
duk_bufwriter_ctx bw_alloc;
duk_bufwriter_ctx *bw;
const duk_uint8_t *p, *p_start, *p_end;
duk_codepoint_t prev, curr, next;
- h_input = duk_require_hstring(ctx, -1); /* Accept symbols. */
+ h_input = duk_require_hstring(thr, -1); /* Accept symbols. */
DUK_ASSERT(h_input != NULL);
bw = &bw_alloc;
@@ -12166,9 +12579,9 @@ DUK_INTERNAL void duk_unicode_case_convert_string(duk_hthread *thr, duk_small_in
}
DUK_BW_COMPACT(thr, bw);
- (void) duk_buffer_to_string(ctx, -1); /* Safe, output is encoded. */
+ (void) duk_buffer_to_string(thr, -1); /* Safe, output is encoded. */
/* invalidates h_buf pointer */
- duk_remove_m2(ctx);
+ duk_remove_m2(thr);
}
#if defined(DUK_USE_REGEXP_SUPPORT)
@@ -12597,9 +13010,9 @@ DUK_INTERNAL duk_bool_t duk_double_is_nan_or_inf(duk_double_t x) {
*/
#if defined(DUK_USE_64BIT_OPS)
#if defined(DUK_USE_DOUBLE_ME)
- return (du.ull[DUK_DBL_IDX_ULL0] & 0x000000007ff00000ULL) == 0x000000007ff00000ULL;
+ return (du.ull[DUK_DBL_IDX_ULL0] & DUK_U64_CONSTANT(0x000000007ff00000)) == DUK_U64_CONSTANT(0x000000007ff00000);
#else
- return (du.ull[DUK_DBL_IDX_ULL0] & 0x7ff0000000000000ULL) == 0x7ff0000000000000ULL;
+ return (du.ull[DUK_DBL_IDX_ULL0] & DUK_U64_CONSTANT(0x7ff0000000000000)) == DUK_U64_CONSTANT(0x7ff0000000000000);
#endif
#else
return (du.ui[DUK_DBL_IDX_UI0] & 0x7ff00000UL) == 0x7ff00000UL;
@@ -12616,21 +13029,21 @@ DUK_INTERNAL duk_bool_t duk_double_is_nan_zero_inf(duk_double_t x) {
du.d = x;
#if defined(DUK_USE_64BIT_OPS)
#if defined(DUK_USE_DOUBLE_ME)
- t = du.ull[DUK_DBL_IDX_ULL0] & 0x000000007ff00000ULL;
- if (t == 0x0000000000000000ULL) {
- t = du.ull[DUK_DBL_IDX_ULL0] & 0x0000000080000000ULL;
+ t = du.ull[DUK_DBL_IDX_ULL0] & DUK_U64_CONSTANT(0x000000007ff00000);
+ if (t == DUK_U64_CONSTANT(0x0000000000000000)) {
+ t = du.ull[DUK_DBL_IDX_ULL0] & DUK_U64_CONSTANT(0x0000000080000000);
return t == 0;
}
- if (t == 0x000000007ff00000UL) {
+ if (t == DUK_U64_CONSTANT(0x000000007ff00000)) {
return 1;
}
#else
- t = du.ull[DUK_DBL_IDX_ULL0] & 0x7ff0000000000000ULL;
- if (t == 0x0000000000000000ULL) {
- t = du.ull[DUK_DBL_IDX_ULL0] & 0x8000000000000000ULL;
+ t = du.ull[DUK_DBL_IDX_ULL0] & DUK_U64_CONSTANT(0x7ff0000000000000);
+ if (t == DUK_U64_CONSTANT(0x0000000000000000)) {
+ t = du.ull[DUK_DBL_IDX_ULL0] & DUK_U64_CONSTANT(0x8000000000000000);
return t == 0;
}
- if (t == 0x7ff0000000000000ULL) {
+ if (t == DUK_U64_CONSTANT(0x7ff0000000000000)) {
return 1;
}
#endif
@@ -12654,7 +13067,7 @@ DUK_INTERNAL duk_small_uint_t duk_double_signbit(duk_double_t x) {
DUK_INTERNAL duk_double_t duk_double_trunc_towards_zero(duk_double_t x) {
/* XXX: optimize */
- duk_small_int_t s = duk_double_signbit(x);
+ duk_small_uint_t s = duk_double_signbit(x);
x = DUK_FLOOR(DUK_FABS(x)); /* truncate towards zero */
if (s) {
x = -x;
@@ -12857,13 +13270,12 @@ DUK_INTERNAL void duk_default_free_function(void *udata, void *ptr) {
/* #include duk_internal.h -> already included */
-DUK_EXTERNAL void *duk_resize_buffer(duk_context *ctx, duk_idx_t idx, duk_size_t new_size) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void *duk_resize_buffer(duk_hthread *thr, duk_idx_t idx, duk_size_t new_size) {
duk_hbuffer_dynamic *h;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- h = (duk_hbuffer_dynamic *) duk_require_hbuffer(ctx, idx);
+ h = (duk_hbuffer_dynamic *) duk_require_hbuffer(thr, idx);
DUK_ASSERT(h != NULL);
if (!(DUK_HBUFFER_HAS_DYNAMIC(h) && !DUK_HBUFFER_HAS_EXTERNAL(h))) {
@@ -12876,15 +13288,14 @@ DUK_EXTERNAL void *duk_resize_buffer(duk_context *ctx, duk_idx_t idx, duk_size_t
return DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(thr->heap, h);
}
-DUK_EXTERNAL void *duk_steal_buffer(duk_context *ctx, duk_idx_t idx, duk_size_t *out_size) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void *duk_steal_buffer(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size) {
duk_hbuffer_dynamic *h;
void *ptr;
duk_size_t sz;
- DUK_ASSERT(ctx != NULL);
+ DUK_ASSERT_API_ENTRY(thr);
- h = (duk_hbuffer_dynamic *) duk_require_hbuffer(ctx, idx);
+ h = (duk_hbuffer_dynamic *) duk_require_hbuffer(thr, idx);
DUK_ASSERT(h != NULL);
if (!(DUK_HBUFFER_HAS_DYNAMIC(h) && !DUK_HBUFFER_HAS_EXTERNAL(h))) {
@@ -12907,13 +13318,12 @@ DUK_EXTERNAL void *duk_steal_buffer(duk_context *ctx, duk_idx_t idx, duk_size_t
return ptr;
}
-DUK_EXTERNAL void duk_config_buffer(duk_context *ctx, duk_idx_t idx, void *ptr, duk_size_t len) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_config_buffer(duk_hthread *thr, duk_idx_t idx, void *ptr, duk_size_t len) {
duk_hbuffer_external *h;
- DUK_ASSERT(ctx != NULL);
+ DUK_ASSERT_API_ENTRY(thr);
- h = (duk_hbuffer_external *) duk_require_hbuffer(ctx, idx);
+ h = (duk_hbuffer_external *) duk_require_hbuffer(thr, idx);
DUK_ASSERT(h != NULL);
if (!DUK_HBUFFER_HAS_EXTERNAL(h)) {
@@ -12940,31 +13350,31 @@ DUK_EXTERNAL void duk_config_buffer(duk_context *ctx, duk_idx_t idx, void *ptr,
#if defined(DUK_USE_BYTECODE_DUMP_SUPPORT)
-#define DUK__SER_MARKER 0xff
-#define DUK__SER_VERSION 0x00
+#define DUK__SER_MARKER 0xbf
#define DUK__SER_STRING 0x00
#define DUK__SER_NUMBER 0x01
#define DUK__BYTECODE_INITIAL_ALLOC 256
+#define DUK__NO_FORMALS 0xffffffffUL
/*
* Dump/load helpers, xxx_raw() helpers do no buffer checks
*/
-DUK_LOCAL duk_uint8_t *duk__load_string_raw(duk_context *ctx, duk_uint8_t *p) {
+DUK_LOCAL duk_uint8_t *duk__load_string_raw(duk_hthread *thr, duk_uint8_t *p) {
duk_uint32_t len;
len = DUK_RAW_READ_U32_BE(p);
- duk_push_lstring(ctx, (const char *) p, len);
+ duk_push_lstring(thr, (const char *) p, len);
p += len;
return p;
}
-DUK_LOCAL duk_uint8_t *duk__load_buffer_raw(duk_context *ctx, duk_uint8_t *p) {
+DUK_LOCAL duk_uint8_t *duk__load_buffer_raw(duk_hthread *thr, duk_uint8_t *p) {
duk_uint32_t len;
duk_uint8_t *buf;
len = DUK_RAW_READ_U32_BE(p);
- buf = (duk_uint8_t *) duk_push_fixed_buffer_nozero(ctx, (duk_size_t) len);
+ buf = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, (duk_size_t) len);
DUK_ASSERT(buf != NULL);
DUK_MEMCPY((void *) buf, (const void *) p, (size_t) len);
p += len;
@@ -13020,7 +13430,7 @@ DUK_LOCAL duk_uint8_t *duk__dump_string_prop(duk_hthread *thr, duk_uint8_t *p, d
DUK_ASSERT(h_str != NULL);
}
DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */
- p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4 + DUK_HSTRING_GET_BYTELEN(h_str), p);
+ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U + DUK_HSTRING_GET_BYTELEN(h_str), p);
p = duk__dump_hstring_raw(p, h_str);
return p;
}
@@ -13034,10 +13444,10 @@ DUK_LOCAL duk_uint8_t *duk__dump_buffer_prop(duk_hthread *thr, duk_uint8_t *p, d
h_buf = DUK_TVAL_GET_BUFFER(tv);
DUK_ASSERT(h_buf != NULL);
DUK_ASSERT(DUK_HBUFFER_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */
- p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4 + DUK_HBUFFER_GET_SIZE(h_buf), p);
+ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U + DUK_HBUFFER_GET_SIZE(h_buf), p);
p = duk__dump_hbuffer_raw(thr, p, h_buf);
} else {
- p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4, p);
+ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U, p);
DUK_RAW_WRITE_U32_BE(p, 0);
}
return p;
@@ -13053,7 +13463,7 @@ DUK_LOCAL duk_uint8_t *duk__dump_uint32_prop(duk_hthread *thr, duk_uint8_t *p, d
} else {
val = def_value;
}
- p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4, p);
+ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U, p);
DUK_RAW_WRITE_U32_BE(p, val);
return p;
}
@@ -13094,12 +13504,12 @@ DUK_LOCAL duk_uint8_t *duk__dump_varmap(duk_hthread *thr, duk_uint8_t *p, duk_bu
#endif
DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */
- p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4 + DUK_HSTRING_GET_BYTELEN(key) + 4, p);
+ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U + DUK_HSTRING_GET_BYTELEN(key) + 4U, p);
p = duk__dump_hstring_raw(p, key);
DUK_RAW_WRITE_U32_BE(p, val);
}
}
- p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4, p);
+ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U, p);
DUK_RAW_WRITE_U32_BE(p, 0); /* end of _Varmap */
return p;
}
@@ -13109,45 +13519,48 @@ DUK_LOCAL duk_uint8_t *duk__dump_formals(duk_hthread *thr, duk_uint8_t *p, duk_b
tv = duk_hobject_find_existing_entry_tval_ptr(thr->heap, (duk_hobject *) func, DUK_HTHREAD_STRING_INT_FORMALS(thr));
if (tv != NULL && DUK_TVAL_IS_OBJECT(tv)) {
- duk_hobject *h;
- duk_uint_fast32_t i;
+ duk_harray *h;
+ duk_uint32_t i;
- h = DUK_TVAL_GET_OBJECT(tv);
+ /* Here we rely on _Formals being a dense array containing
+ * strings. This should be the case unless _Formals has been
+ * tweaked by the application (which we don't support right
+ * now).
+ */
+ h = (duk_harray *) DUK_TVAL_GET_OBJECT(tv);
DUK_ASSERT(h != NULL);
+ DUK_ASSERT(DUK_HOBJECT_IS_ARRAY((duk_hobject *) h));
+ DUK_ASSERT(h->length <= DUK_HOBJECT_GET_ASIZE((duk_hobject *) h));
- /* We know _Formals is dense and all entries will be in the
- * array part. GC and finalizers shouldn't affect _Formals
- * so side effects should be fine.
- */
- for (i = 0; i < (duk_uint_fast32_t) DUK_HOBJECT_GET_ASIZE(h); i++) {
+ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U, p);
+ DUK_ASSERT(h->length != DUK__NO_FORMALS); /* limits */
+ DUK_RAW_WRITE_U32_BE(p, h->length);
+
+ for (i = 0; i < h->length; i++) {
duk_tval *tv_val;
duk_hstring *varname;
- tv_val = DUK_HOBJECT_A_GET_VALUE_PTR(thr->heap, h, i);
+ tv_val = DUK_HOBJECT_A_GET_VALUE_PTR(thr->heap, (duk_hobject *) h, i);
DUK_ASSERT(tv_val != NULL);
- if (DUK_TVAL_IS_STRING(tv_val)) {
- /* Array is dense and contains only strings, but ASIZE may
- * be larger than used part and there are UNUSED entries.
- */
- varname = DUK_TVAL_GET_STRING(tv_val);
- DUK_ASSERT(varname != NULL);
- DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(varname) >= 1); /* won't be confused with terminator */
+ DUK_ASSERT(DUK_TVAL_IS_STRING(tv_val));
- DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */
- p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4 + DUK_HSTRING_GET_BYTELEN(varname), p);
- p = duk__dump_hstring_raw(p, varname);
- }
+ varname = DUK_TVAL_GET_STRING(tv_val);
+ DUK_ASSERT(varname != NULL);
+ DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(varname) >= 1);
+
+ DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */
+ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U + DUK_HSTRING_GET_BYTELEN(varname), p);
+ p = duk__dump_hstring_raw(p, varname);
}
} else {
- DUK_DD(DUK_DDPRINT("dumping function without _Formals, emit empty list"));
+ DUK_DD(DUK_DDPRINT("dumping function without _Formals, emit marker to indicate missing _Formals"));
+ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4U, p);
+ DUK_RAW_WRITE_U32_BE(p, DUK__NO_FORMALS); /* marker: no formals */
}
- p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 4, p);
- DUK_RAW_WRITE_U32_BE(p, 0); /* end of _Formals */
return p;
}
-static duk_uint8_t *duk__dump_func(duk_context *ctx, duk_hcompfunc *func, duk_bufwriter_ctx *bw_ctx, duk_uint8_t *p) {
- duk_hthread *thr;
+static duk_uint8_t *duk__dump_func(duk_hthread *thr, duk_hcompfunc *func, duk_bufwriter_ctx *bw_ctx, duk_uint8_t *p) {
duk_tval *tv, *tv_end;
duk_instr_t *ins, *ins_end;
duk_hobject **fn, **fn_end;
@@ -13157,10 +13570,6 @@ static duk_uint8_t *duk__dump_func(duk_context *ctx, duk_hcompfunc *func, duk_bu
duk_uint16_t tmp16;
duk_double_t d;
- thr = (duk_hthread *) ctx;
- DUK_UNREF(ctx);
- DUK_UNREF(thr);
-
DUK_DD(DUK_DDPRINT("dumping function %p to %p: "
"consts=[%p,%p[ (%ld bytes, %ld items), "
"funcs=[%p,%p[ (%ld bytes, %ld items), "
@@ -13182,7 +13591,7 @@ static duk_uint8_t *duk__dump_func(duk_context *ctx, duk_hcompfunc *func, duk_bu
DUK_ASSERT(DUK_USE_ESBC_MAX_BYTES <= 0x7fffffffUL); /* ensures no overflow */
count_instr = (duk_uint32_t) DUK_HCOMPFUNC_GET_CODE_COUNT(thr->heap, func);
- p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 3 * 4 + 2 * 2 + 3 * 4 + count_instr * 4, p);
+ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 3U * 4U + 2U * 2U + 3U * 4U + count_instr * 4U, p);
/* Fixed header info. */
tmp32 = count_instr;
@@ -13237,12 +13646,12 @@ static duk_uint8_t *duk__dump_func(duk_context *ctx, duk_hcompfunc *func, duk_bu
h_str = DUK_TVAL_GET_STRING(tv);
DUK_ASSERT(h_str != NULL);
DUK_ASSERT(DUK_HSTRING_MAX_BYTELEN <= 0x7fffffffUL); /* ensures no overflow */
- p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 1 + 4 + DUK_HSTRING_GET_BYTELEN(h_str), p),
+ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 1U + 4U + DUK_HSTRING_GET_BYTELEN(h_str), p),
*p++ = DUK__SER_STRING;
p = duk__dump_hstring_raw(p, h_str);
} else {
DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv));
- p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 1 + 8, p);
+ p = DUK_BW_ENSURE_RAW(thr, bw_ctx, 1U + 8U, p);
*p++ = DUK__SER_NUMBER;
d = DUK_TVAL_GET_NUMBER(tv);
DUK_RAW_WRITE_DOUBLE_BE(p, d);
@@ -13261,7 +13670,7 @@ static duk_uint8_t *duk__dump_func(duk_context *ctx, duk_hcompfunc *func, duk_bu
* to serialize deep functions.
*/
DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(*fn));
- p = duk__dump_func(ctx, (duk_hcompfunc *) *fn, bw_ctx, p);
+ p = duk__dump_func(thr, (duk_hcompfunc *) *fn, bw_ctx, p);
fn++;
}
@@ -13306,8 +13715,7 @@ static duk_uint8_t *duk__dump_func(duk_context *ctx, duk_hcompfunc *func, duk_bu
DUK_ASSERT((duk_size_t) (p_end - p) >= (duk_size_t) (n)); \
} while (0)
-static duk_uint8_t *duk__load_func(duk_context *ctx, duk_uint8_t *p, duk_uint8_t *p_end) {
- duk_hthread *thr;
+static duk_uint8_t *duk__load_func(duk_hthread *thr, duk_uint8_t *p, duk_uint8_t *p_end) {
duk_hcompfunc *h_fun;
duk_hbuffer *h_data;
duk_size_t data_size;
@@ -13320,6 +13728,7 @@ static duk_uint8_t *duk__load_func(duk_context *ctx, duk_uint8_t *p, duk_uint8_t
duk_idx_t idx_base;
duk_tval *tv1;
duk_uarridx_t arr_idx;
+ duk_uarridx_t arr_limit;
duk_hobject *func_env;
duk_bool_t need_pop;
@@ -13328,8 +13737,7 @@ static duk_uint8_t *duk__load_func(duk_context *ctx, duk_uint8_t *p, duk_uint8_t
* looks the same as created by duk_js_closure().
*/
- DUK_ASSERT(ctx != NULL);
- thr = (duk_hthread *) ctx;
+ DUK_ASSERT(thr != NULL);
DUK_DD(DUK_DDPRINT("loading function, p=%p, p_end=%p", (void *) p, (void *) p_end));
@@ -13350,13 +13758,13 @@ static duk_uint8_t *duk__load_func(duk_context *ctx, duk_uint8_t *p, duk_uint8_t
* inner functions being loaded. Require enough space to handle
* large functions correctly.
*/
- duk_require_stack(ctx, 2 + count_const + count_funcs);
- idx_base = duk_get_top(ctx);
+ duk_require_stack(thr, (duk_idx_t) (2 + count_const + count_funcs));
+ idx_base = duk_get_top(thr);
/* Push function object, init flags etc. This must match
* duk_js_push_closure() quite carefully.
*/
- h_fun = duk_push_hcompfunc(ctx);
+ h_fun = duk_push_hcompfunc(thr);
DUK_ASSERT(h_fun != NULL);
DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC((duk_hobject *) h_fun));
DUK_ASSERT(DUK_HCOMPFUNC_GET_DATA(thr->heap, h_fun) == NULL);
@@ -13377,8 +13785,11 @@ static duk_uint8_t *duk__load_func(duk_context *ctx, duk_uint8_t *p, duk_uint8_t
tmp32 = DUK_RAW_READ_U32_BE(p);
DUK_HEAPHDR_SET_FLAGS((duk_heaphdr *) h_fun, tmp32); /* masks flags to only change duk_hobject flags */
- /* standard prototype */
+ /* standard prototype (no need to set here, already set) */
+ DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) h_fun) == thr->builtins[DUK_BIDX_FUNCTION_PROTOTYPE]);
+#if 0
DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, &h_fun->obj, thr->builtins[DUK_BIDX_FUNCTION_PROTOTYPE]);
+#endif
/* assert just a few critical flags */
DUK_ASSERT(DUK_HEAPHDR_GET_TYPE((duk_heaphdr *) h_fun) == DUK_HTYPE_OBJECT);
@@ -13391,7 +13802,7 @@ static duk_uint8_t *duk__load_func(duk_context *ctx, duk_uint8_t *p, duk_uint8_t
DUK_ASSERT(!DUK_HOBJECT_HAS_EXOTIC_ARGUMENTS(&h_fun->obj));
/* Create function 'data' buffer but don't attach it yet. */
- fun_data = (duk_uint8_t *) duk_push_fixed_buffer_nozero(ctx, data_size);
+ fun_data = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, data_size);
DUK_ASSERT(fun_data != NULL);
/* Load bytecode instructions. */
@@ -13417,7 +13828,7 @@ static duk_uint8_t *duk__load_func(duk_context *ctx, duk_uint8_t *p, duk_uint8_t
const_type = DUK_RAW_READ_U8(p);
switch (const_type) {
case DUK__SER_STRING: {
- p = duk__load_string_raw(ctx, p);
+ p = duk__load_string_raw(thr, p);
break;
}
case DUK__SER_NUMBER: {
@@ -13429,7 +13840,7 @@ static duk_uint8_t *duk__load_func(duk_context *ctx, duk_uint8_t *p, duk_uint8_t
DUK__ASSERT_LEFT(8);
val = DUK_RAW_READ_DOUBLE_BE(p);
DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(&tv_tmp, val);
- duk_push_tval(ctx, &tv_tmp);
+ duk_push_tval(thr, &tv_tmp);
break;
}
default: {
@@ -13440,7 +13851,7 @@ static duk_uint8_t *duk__load_func(duk_context *ctx, duk_uint8_t *p, duk_uint8_t
/* Load inner functions to value stack, but don't yet copy to buffer. */
for (n = count_funcs; n > 0; n--) {
- p = duk__load_func(ctx, p, p_end);
+ p = duk__load_func(thr, p, p_end);
if (p == NULL) {
goto format_error;
}
@@ -13455,12 +13866,12 @@ static duk_uint8_t *duk__load_func(duk_context *ctx, duk_uint8_t *p, duk_uint8_t
* them afterwards.
*/
- h_data = (duk_hbuffer *) duk_known_hbuffer(ctx, idx_base + 1);
+ h_data = (duk_hbuffer *) duk_known_hbuffer(thr, idx_base + 1);
DUK_ASSERT(!DUK_HBUFFER_HAS_DYNAMIC(h_data));
DUK_HCOMPFUNC_SET_DATA(thr->heap, h_fun, h_data);
DUK_HBUFFER_INCREF(thr, h_data);
- tv1 = duk_get_tval(ctx, idx_base + 2); /* may be NULL if no constants or inner funcs */
+ tv1 = duk_get_tval(thr, idx_base + 2); /* may be NULL if no constants or inner funcs */
DUK_ASSERT((count_const == 0 && count_funcs == 0) || tv1 != NULL);
q = fun_data;
@@ -13493,16 +13904,16 @@ static duk_uint8_t *duk__load_func(duk_context *ctx, duk_uint8_t *p, duk_uint8_t
/* The function object is now reachable and refcounts are fine,
* so we can pop off all the temporaries.
*/
- DUK_DDD(DUK_DDDPRINT("function is reachable, reset top; func: %!iT", duk_get_tval(ctx, idx_base)));
- duk_set_top(ctx, idx_base + 1);
+ DUK_DDD(DUK_DDDPRINT("function is reachable, reset top; func: %!iT", duk_get_tval(thr, idx_base)));
+ duk_set_top(thr, idx_base + 1);
/* Setup function properties. */
tmp32 = DUK_RAW_READ_U32_BE(p);
- duk_push_u32(ctx, tmp32);
- duk_xdef_prop_stridx_short(ctx, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_C);
+ duk_push_u32(thr, tmp32);
+ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_C);
#if defined(DUK_USE_FUNC_NAME_PROPERTY)
- p = duk__load_string_raw(ctx, p); /* -> [ func funcname ] */
+ p = duk__load_string_raw(thr, p); /* -> [ func funcname ] */
func_env = thr->builtins[DUK_BIDX_GLOBAL_ENV];
DUK_ASSERT(func_env != NULL);
need_pop = 0;
@@ -13519,7 +13930,7 @@ static duk_uint8_t *duk__load_func(duk_context *ctx, duk_uint8_t *p, duk_uint8_t
DUK_ASSERT(new_env != NULL);
DUK_ASSERT(new_env->thread == NULL); /* Closed. */
DUK_ASSERT(new_env->varmap == NULL);
- DUK_ASSERT(new_env->regbase == 0);
+ DUK_ASSERT(new_env->regbase_byteoff == 0);
DUK_ASSERT_HDECENV_VALID(new_env);
DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) new_env) == NULL);
DUK_HOBJECT_SET_PROTOTYPE(thr->heap, (duk_hobject *) new_env, func_env);
@@ -13527,11 +13938,11 @@ static duk_uint8_t *duk__load_func(duk_context *ctx, duk_uint8_t *p, duk_uint8_t
func_env = (duk_hobject *) new_env;
- duk_push_hobject(ctx, (duk_hobject *) new_env);
+ duk_push_hobject(thr, (duk_hobject *) new_env);
- duk_dup_m2(ctx); /* -> [ func funcname env funcname ] */
- duk_dup(ctx, idx_base); /* -> [ func funcname env funcname func ] */
- duk_xdef_prop(ctx, -3, DUK_PROPDESC_FLAGS_NONE); /* -> [ func funcname env ] */
+ duk_dup_m2(thr); /* -> [ func funcname env funcname ] */
+ duk_dup(thr, idx_base); /* -> [ func funcname env funcname func ] */
+ duk_xdef_prop(thr, -3, DUK_PROPDESC_FLAGS_NONE); /* -> [ func funcname env ] */
need_pop = 1; /* Need to pop env, but -after- updating h_fun and increfs. */
}
@@ -13541,93 +13952,85 @@ static duk_uint8_t *duk__load_func(duk_context *ctx, duk_uint8_t *p, duk_uint8_t
DUK_HOBJECT_INCREF(thr, func_env);
DUK_HOBJECT_INCREF(thr, func_env);
if (need_pop) {
- duk_pop(ctx);
+ duk_pop(thr);
}
- duk_xdef_prop_stridx_short(ctx, -2, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_C);
+ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_C);
#endif /* DUK_USE_FUNC_NAME_PROPERTY */
#if defined(DUK_USE_FUNC_FILENAME_PROPERTY)
- p = duk__load_string_raw(ctx, p);
- duk_xdef_prop_stridx_short(ctx, -2, DUK_STRIDX_FILE_NAME, DUK_PROPDESC_FLAGS_C);
+ p = duk__load_string_raw(thr, p);
+ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_FILE_NAME, DUK_PROPDESC_FLAGS_C);
#endif /* DUK_USE_FUNC_FILENAME_PROPERTY */
if (DUK_HOBJECT_HAS_CONSTRUCTABLE((duk_hobject *) h_fun)) {
/* Restore empty external .prototype only for constructable
* functions.
*/
- duk_push_object(ctx);
- duk_dup_m2(ctx);
- duk_xdef_prop_stridx_short(ctx, -2, DUK_STRIDX_CONSTRUCTOR, DUK_PROPDESC_FLAGS_WC); /* func.prototype.constructor = func */
- duk_compact_m1(ctx);
- duk_xdef_prop_stridx_short(ctx, -2, DUK_STRIDX_PROTOTYPE, DUK_PROPDESC_FLAGS_W);
+ duk_push_object(thr);
+ duk_dup_m2(thr);
+ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_CONSTRUCTOR, DUK_PROPDESC_FLAGS_WC); /* func.prototype.constructor = func */
+ duk_compact_m1(thr);
+ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_PROTOTYPE, DUK_PROPDESC_FLAGS_W);
}
#if defined(DUK_USE_PC2LINE)
- p = duk__load_buffer_raw(ctx, p);
- duk_xdef_prop_stridx_short(ctx, -2, DUK_STRIDX_INT_PC2LINE, DUK_PROPDESC_FLAGS_WC);
+ p = duk__load_buffer_raw(thr, p);
+ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_PC2LINE, DUK_PROPDESC_FLAGS_WC);
#endif /* DUK_USE_PC2LINE */
- duk_push_object(ctx); /* _Varmap */
+ duk_push_object(thr); /* _Varmap */
for (;;) {
/* XXX: awkward */
- p = duk__load_string_raw(ctx, p);
- if (duk_get_length(ctx, -1) == 0) {
- duk_pop(ctx);
+ p = duk__load_string_raw(thr, p);
+ if (duk_get_length(thr, -1) == 0) {
+ duk_pop(thr);
break;
}
tmp32 = DUK_RAW_READ_U32_BE(p);
- duk_push_u32(ctx, tmp32);
- duk_put_prop(ctx, -3);
+ duk_push_u32(thr, tmp32);
+ duk_put_prop(thr, -3);
}
- duk_compact_m1(ctx);
- duk_xdef_prop_stridx_short(ctx, -2, DUK_STRIDX_INT_VARMAP, DUK_PROPDESC_FLAGS_NONE);
+ duk_compact_m1(thr);
+ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VARMAP, DUK_PROPDESC_FLAGS_NONE);
- /* If _Formals wasn't present in the original function, the list
- * here will be empty. Same happens if _Formals was present but
- * had zero length. We can omit _Formals from the result if its
- * length is zero and matches nargs.
+ /* _Formals may have been missing in the original function, which is
+ * handled using a marker length.
*/
- duk_push_array(ctx); /* _Formals */
- for (arr_idx = 0; ; arr_idx++) {
- /* XXX: awkward */
- p = duk__load_string_raw(ctx, p);
- if (duk_get_length(ctx, -1) == 0) {
- duk_pop(ctx);
- break;
+ arr_limit = DUK_RAW_READ_U32_BE(p);
+ if (arr_limit != DUK__NO_FORMALS) {
+ duk_push_array(thr); /* _Formals */
+ for (arr_idx = 0; arr_idx < arr_limit; arr_idx++) {
+ p = duk__load_string_raw(thr, p);
+ duk_put_prop_index(thr, -2, arr_idx);
}
- duk_put_prop_index(ctx, -2, arr_idx);
- }
- if (arr_idx == 0 && h_fun->nargs == 0) {
- duk_pop(ctx);
+ duk_compact_m1(thr);
+ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_FORMALS, DUK_PROPDESC_FLAGS_NONE);
} else {
- duk_compact_m1(ctx);
- duk_xdef_prop_stridx_short(ctx, -2, DUK_STRIDX_INT_FORMALS, DUK_PROPDESC_FLAGS_NONE);
+ DUK_DD(DUK_DDPRINT("no _Formals in dumped function"));
}
/* Return with final function pushed on stack top. */
- DUK_DD(DUK_DDPRINT("final loaded function: %!iT", duk_get_tval(ctx, -1)));
- DUK_ASSERT_TOP(ctx, idx_base + 1);
+ DUK_DD(DUK_DDPRINT("final loaded function: %!iT", duk_get_tval(thr, -1)));
+ DUK_ASSERT_TOP(thr, idx_base + 1);
return p;
format_error:
return NULL;
}
-DUK_EXTERNAL void duk_dump_function(duk_context *ctx) {
- duk_hthread *thr;
+DUK_EXTERNAL void duk_dump_function(duk_hthread *thr) {
duk_hcompfunc *func;
duk_bufwriter_ctx bw_ctx_alloc;
duk_bufwriter_ctx *bw_ctx = &bw_ctx_alloc;
duk_uint8_t *p;
- DUK_ASSERT(ctx != NULL);
- thr = (duk_hthread *) ctx;
+ DUK_ASSERT_API_ENTRY(thr);
/* Bound functions don't have all properties so we'd either need to
* lookup the non-bound target function or reject bound functions.
- * For now, bound functions are rejected.
+ * For now, bound functions are rejected with TypeError.
*/
- func = duk_require_hcompfunc(ctx, -1);
+ func = duk_require_hcompfunc(thr, -1);
DUK_ASSERT(func != NULL);
DUK_ASSERT(!DUK_HOBJECT_HAS_BOUNDFUNC(&func->obj));
@@ -13637,26 +14040,22 @@ DUK_EXTERNAL void duk_dump_function(duk_context *ctx) {
DUK_BW_INIT_PUSHBUF(thr, bw_ctx, DUK__BYTECODE_INITIAL_ALLOC);
p = DUK_BW_GET_PTR(thr, bw_ctx);
*p++ = DUK__SER_MARKER;
- *p++ = DUK__SER_VERSION;
- p = duk__dump_func(ctx, func, bw_ctx, p);
+ p = duk__dump_func(thr, func, bw_ctx, p);
DUK_BW_SET_PTR(thr, bw_ctx, p);
DUK_BW_COMPACT(thr, bw_ctx);
- DUK_DD(DUK_DDPRINT("serialized result: %!T", duk_get_tval(ctx, -1)));
+ DUK_DD(DUK_DDPRINT("serialized result: %!T", duk_get_tval(thr, -1)));
- duk_remove_m2(ctx); /* [ ... func buf ] -> [ ... buf ] */
+ duk_remove_m2(thr); /* [ ... func buf ] -> [ ... buf ] */
}
-DUK_EXTERNAL void duk_load_function(duk_context *ctx) {
- duk_hthread *thr;
+DUK_EXTERNAL void duk_load_function(duk_hthread *thr) {
duk_uint8_t *p_buf, *p, *p_end;
duk_size_t sz;
- DUK_ASSERT(ctx != NULL);
- thr = (duk_hthread *) ctx;
- DUK_UNREF(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- p_buf = (duk_uint8_t *) duk_require_buffer(ctx, -1, &sz);
+ p_buf = (duk_uint8_t *) duk_require_buffer(thr, -1, &sz);
DUK_ASSERT(p_buf != NULL);
/* The caller is responsible for being sure that bytecode being loaded
@@ -13665,36 +14064,38 @@ DUK_EXTERNAL void duk_load_function(duk_context *ctx) {
* (instruction validation would be quite complex to implement).
*
* This signature check is the only sanity check for detecting
- * accidental invalid inputs. The initial 0xFF byte ensures no
- * ordinary string will be accepted by accident.
+ * accidental invalid inputs. The initial byte ensures no ordinary
+ * string or Symbol will be accepted by accident.
*/
p = p_buf;
p_end = p_buf + sz;
- if (sz < 2 || p[0] != DUK__SER_MARKER || p[1] != DUK__SER_VERSION) {
+ if (sz < 1 || p[0] != DUK__SER_MARKER) {
goto format_error;
}
- p += 2;
+ p++;
- p = duk__load_func(ctx, p, p_end);
+ p = duk__load_func(thr, p, p_end);
if (p == NULL) {
goto format_error;
}
- duk_remove_m2(ctx); /* [ ... buf func ] -> [ ... func ] */
+ duk_remove_m2(thr); /* [ ... buf func ] -> [ ... func ] */
return;
format_error:
- DUK_ERROR_TYPE(thr, DUK_STR_DECODE_FAILED);
+ DUK_ERROR_TYPE(thr, DUK_STR_INVALID_BYTECODE);
}
#else /* DUK_USE_BYTECODE_DUMP_SUPPORT */
-DUK_EXTERNAL void duk_dump_function(duk_context *ctx) {
- DUK_ERROR_UNSUPPORTED((duk_hthread *) ctx);
+DUK_EXTERNAL void duk_dump_function(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ DUK_ERROR_UNSUPPORTED(thr);
}
-DUK_EXTERNAL void duk_load_function(duk_context *ctx) {
- DUK_ERROR_UNSUPPORTED((duk_hthread *) ctx);
+DUK_EXTERNAL void duk_load_function(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ DUK_ERROR_UNSUPPORTED(thr);
}
#endif /* DUK_USE_BYTECODE_DUMP_SUPPORT */
@@ -13702,228 +14103,324 @@ DUK_EXTERNAL void duk_load_function(duk_context *ctx) {
/* automatic undefs */
#undef DUK__ASSERT_LEFT
#undef DUK__BYTECODE_INITIAL_ALLOC
+#undef DUK__NO_FORMALS
#undef DUK__SER_MARKER
#undef DUK__SER_NUMBER
#undef DUK__SER_STRING
-#undef DUK__SER_VERSION
/*
* Calls.
*
- * Protected variants should avoid ever throwing an error.
+ * Protected variants should avoid ever throwing an error. Must be careful
+ * to catch errors related to value stack manipulation and property lookup,
+ * not just the call itself.
+ *
+ * The only exception is when arguments are insane, e.g. nargs/nrets are out
+ * of bounds; in such cases an error is thrown for two reasons. First, we
+ * can't always respect the value stack input/output guarantees in such cases
+ * so the caller would end up with the value stack in an unexpected state.
+ * Second, an attempt to create an error might itself fail (although this
+ * could be avoided by pushing a preallocated object/string or a primitive
+ * value).
*/
/* #include duk_internal.h -> already included */
+/*
+ * Helpers
+ */
+
+struct duk__pcall_prop_args {
+ duk_idx_t obj_idx;
+ duk_idx_t nargs;
+ duk_small_uint_t call_flags;
+};
+typedef struct duk__pcall_prop_args duk__pcall_prop_args;
+
+struct duk__pcall_method_args {
+ duk_idx_t nargs;
+ duk_small_uint_t call_flags;
+};
+typedef struct duk__pcall_method_args duk__pcall_method_args;
+
+struct duk__pcall_args {
+ duk_idx_t nargs;
+ duk_small_uint_t call_flags;
+};
+typedef struct duk__pcall_args duk__pcall_args;
+
+/* Compute and validate idx_func for a certain 'nargs' and 'other'
+ * parameter count (1 or 2, depending on whether 'this' binding is
+ * present).
+ */
+DUK_LOCAL duk_idx_t duk__call_get_idx_func(duk_hthread *thr, duk_idx_t nargs, duk_idx_t other) {
+ duk_idx_t idx_func;
+
+ /* XXX: byte arithmetic? */
+
+ DUK_ASSERT(other >= 0);
+
+ idx_func = duk_get_top(thr) - nargs - other;
+ if (DUK_UNLIKELY((idx_func | nargs) < 0)) { /* idx_func < 0 || nargs < 0; OR sign bits */
+ DUK_ERROR_TYPE_INVALID_ARGS(thr);
+ /* unreachable */
+ }
+ DUK_ASSERT(duk_is_valid_index(thr, idx_func));
+ return idx_func;
+}
+
+/* Compute idx_func, assume index will be valid. This is a valid assumption
+ * for protected calls: nargs < 0 is checked explicitly and duk_safe_call()
+ * validates the argument count.
+ */
+DUK_LOCAL duk_idx_t duk__call_get_idx_func_unvalidated(duk_hthread *thr, duk_idx_t nargs, duk_idx_t other) {
+ duk_idx_t idx_func;
+
+ /* XXX: byte arithmetic? */
+
+ DUK_ASSERT(nargs >= 0);
+ DUK_ASSERT(other >= 0);
+
+ idx_func = duk_get_top(thr) - nargs - other;
+ DUK_ASSERT(idx_func >= 0);
+ DUK_ASSERT(duk_is_valid_index(thr, idx_func));
+ return idx_func;
+}
+
/* Prepare value stack for a method call through an object property.
* May currently throw an error e.g. when getting the property.
*/
-DUK_LOCAL void duk__call_prop_prep_stack(duk_context *ctx, duk_idx_t normalized_obj_idx, duk_idx_t nargs) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_LOCAL void duk__call_prop_prep_stack(duk_hthread *thr, duk_idx_t normalized_obj_idx, duk_idx_t nargs) {
+ DUK_ASSERT_CTX_VALID(thr);
+ DUK_ASSERT(nargs >= 0);
DUK_DDD(DUK_DDDPRINT("duk__call_prop_prep_stack, normalized_obj_idx=%ld, nargs=%ld, stacktop=%ld",
- (long) normalized_obj_idx, (long) nargs, (long) duk_get_top(ctx)));
+ (long) normalized_obj_idx, (long) nargs, (long) duk_get_top(thr)));
/* [... key arg1 ... argN] */
/* duplicate key */
- duk_dup(ctx, -nargs - 1); /* Note: -nargs alone would fail for nargs == 0, this is OK */
- duk_get_prop(ctx, normalized_obj_idx);
+ duk_dup(thr, -nargs - 1); /* Note: -nargs alone would fail for nargs == 0, this is OK */
+ (void) duk_get_prop(thr, normalized_obj_idx);
+
+ DUK_DDD(DUK_DDDPRINT("func: %!T", (duk_tval *) duk_get_tval(thr, -1)));
+
+#if defined(DUK_USE_VERBOSE_ERRORS)
+ if (DUK_UNLIKELY(!duk_is_callable(thr, -1))) {
+ duk_tval *tv_targ;
+ duk_tval *tv_base;
+ duk_tval *tv_key;
- DUK_DDD(DUK_DDDPRINT("func: %!T", (duk_tval *) duk_get_tval(ctx, -1)));
+ tv_targ = DUK_GET_TVAL_NEGIDX(thr, -1);
+ tv_base = DUK_GET_TVAL_POSIDX(thr, normalized_obj_idx);
+ tv_key = DUK_GET_TVAL_NEGIDX(thr, -nargs - 2);
+ DUK_ASSERT(tv_targ >= thr->valstack_bottom && tv_targ < thr->valstack_top);
+ DUK_ASSERT(tv_base >= thr->valstack_bottom && tv_base < thr->valstack_top);
+ DUK_ASSERT(tv_key >= thr->valstack_bottom && tv_key < thr->valstack_top);
+
+ duk_call_setup_propcall_error(thr, tv_targ, tv_base, tv_key);
+ }
+#endif
/* [... key arg1 ... argN func] */
- duk_replace(ctx, -nargs - 2);
+ duk_replace(thr, -nargs - 2);
/* [... func arg1 ... argN] */
- duk_dup(ctx, normalized_obj_idx);
- duk_insert(ctx, -nargs - 1);
+ duk_dup(thr, normalized_obj_idx);
+ duk_insert(thr, -nargs - 1);
/* [... func this arg1 ... argN] */
}
-DUK_EXTERNAL void duk_call(duk_context *ctx, duk_idx_t nargs) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_call(duk_hthread *thr, duk_idx_t nargs) {
duk_small_uint_t call_flags;
duk_idx_t idx_func;
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_ASSERT(thr != NULL);
+ DUK_ASSERT_API_ENTRY(thr);
- idx_func = duk_get_top(ctx) - nargs - 1;
- if (idx_func < 0 || nargs < 0) {
- /* note that we can't reliably pop anything here */
- DUK_ERROR_TYPE_INVALID_ARGS(thr);
- }
+ idx_func = duk__call_get_idx_func(thr, nargs, 1);
+ DUK_ASSERT(duk_is_valid_index(thr, idx_func));
- /* XXX: awkward; we assume there is space for this, overwrite
- * directly instead?
- */
- duk_push_undefined(ctx);
- duk_insert(ctx, idx_func + 1);
+ duk_insert_undefined(thr, idx_func + 1);
call_flags = 0; /* not protected, respect reclimit, not constructor */
-
- duk_handle_call_unprotected(thr, /* thread */
- nargs, /* num_stack_args */
- call_flags); /* call_flags */
+ duk_handle_call_unprotected(thr, idx_func, call_flags);
}
-DUK_EXTERNAL void duk_call_method(duk_context *ctx, duk_idx_t nargs) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_call_method(duk_hthread *thr, duk_idx_t nargs) {
duk_small_uint_t call_flags;
duk_idx_t idx_func;
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_ASSERT(thr != NULL);
+ DUK_ASSERT_API_ENTRY(thr);
- idx_func = duk_get_top(ctx) - nargs - 2; /* must work for nargs <= 0 */
- if (idx_func < 0 || nargs < 0) {
- /* note that we can't reliably pop anything here */
- DUK_ERROR_TYPE_INVALID_ARGS(thr);
- }
+ idx_func = duk__call_get_idx_func(thr, nargs, 2);
+ DUK_ASSERT(duk_is_valid_index(thr, idx_func));
call_flags = 0; /* not protected, respect reclimit, not constructor */
-
- duk_handle_call_unprotected(thr, /* thread */
- nargs, /* num_stack_args */
- call_flags); /* call_flags */
+ duk_handle_call_unprotected(thr, idx_func, call_flags);
}
-DUK_EXTERNAL void duk_call_prop(duk_context *ctx, duk_idx_t obj_idx, duk_idx_t nargs) {
+DUK_EXTERNAL void duk_call_prop(duk_hthread *thr, duk_idx_t obj_idx, duk_idx_t nargs) {
/*
* XXX: if duk_handle_call() took values through indices, this could be
* made much more sensible. However, duk_handle_call() needs to fudge
- * the 'this' and 'func' values to handle bound function chains, which
- * is now done "in-place", so this is not a trivial change.
+ * the 'this' and 'func' values to handle bound functions, which is now
+ * done "in-place", so this is not a trivial change.
*/
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- obj_idx = duk_require_normalize_index(ctx, obj_idx); /* make absolute */
+ obj_idx = duk_require_normalize_index(thr, obj_idx); /* make absolute */
+ if (DUK_UNLIKELY(nargs < 0)) {
+ DUK_ERROR_TYPE_INVALID_ARGS(thr);
+ }
- duk__call_prop_prep_stack(ctx, obj_idx, nargs);
+ duk__call_prop_prep_stack(thr, obj_idx, nargs);
- duk_call_method(ctx, nargs);
+ duk_call_method(thr, nargs);
}
-DUK_EXTERNAL duk_int_t duk_pcall(duk_context *ctx, duk_idx_t nargs) {
- duk_hthread *thr = (duk_hthread *) ctx;
- duk_small_uint_t call_flags;
+DUK_LOCAL duk_ret_t duk__pcall_raw(duk_hthread *thr, void *udata) {
+ duk__pcall_args *args;
duk_idx_t idx_func;
- duk_int_t rc;
+ duk_int_t ret;
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_ASSERT(thr != NULL);
+ DUK_ASSERT_CTX_VALID(thr);
+ DUK_ASSERT(udata != NULL);
- idx_func = duk_get_top(ctx) - nargs - 1; /* must work for nargs <= 0 */
- if (idx_func < 0 || nargs < 0) {
- /* We can't reliably pop anything here because the stack input
- * shape is incorrect. So we throw an error; if the caller has
- * no catch point for this, a fatal error will occur. Another
- * alternative would be to just return an error. But then the
- * stack would be in an unknown state which might cause some
- * very hard to diagnose problems later on. Also note that even
- * if we did not throw an error here, the underlying call handler
- * might STILL throw an out-of-memory error or some other internal
- * fatal error.
- */
+ args = (duk__pcall_args *) udata;
+ idx_func = duk__call_get_idx_func_unvalidated(thr, args->nargs, 1);
+ DUK_ASSERT(duk_is_valid_index(thr, idx_func));
+
+ duk_insert_undefined(thr, idx_func + 1);
+
+ ret = duk_handle_call_unprotected(thr, idx_func, args->call_flags);
+ DUK_ASSERT(ret == 0);
+ DUK_UNREF(ret);
+
+ return 1;
+}
+
+DUK_EXTERNAL duk_int_t duk_pcall(duk_hthread *thr, duk_idx_t nargs) {
+ duk__pcall_args args;
+
+ DUK_ASSERT_API_ENTRY(thr);
+
+ args.nargs = nargs;
+ if (DUK_UNLIKELY(nargs < 0)) {
DUK_ERROR_TYPE_INVALID_ARGS(thr);
return DUK_EXEC_ERROR; /* unreachable */
}
+ args.call_flags = 0;
- /* awkward; we assume there is space for this */
- duk_push_undefined(ctx);
- duk_insert(ctx, idx_func + 1);
+ return duk_safe_call(thr, duk__pcall_raw, (void *) &args /*udata*/, nargs + 1 /*nargs*/, 1 /*nrets*/);
+}
- call_flags = 0; /* respect reclimit, not constructor */
+DUK_LOCAL duk_ret_t duk__pcall_method_raw(duk_hthread *thr, void *udata) {
+ duk__pcall_method_args *args;
+ duk_idx_t idx_func;
+ duk_int_t ret;
- rc = duk_handle_call_protected(thr, /* thread */
- nargs, /* num_stack_args */
- call_flags); /* call_flags */
+ DUK_ASSERT_CTX_VALID(thr);
+ DUK_ASSERT(udata != NULL);
- return rc;
+ args = (duk__pcall_method_args *) udata;
+
+ idx_func = duk__call_get_idx_func_unvalidated(thr, args->nargs, 2);
+ DUK_ASSERT(duk_is_valid_index(thr, idx_func));
+
+ ret = duk_handle_call_unprotected(thr, idx_func, args->call_flags);
+ DUK_ASSERT(ret == 0);
+ DUK_UNREF(ret);
+
+ return 1;
}
-DUK_EXTERNAL duk_int_t duk_pcall_method(duk_context *ctx, duk_idx_t nargs) {
- duk_hthread *thr = (duk_hthread *) ctx;
- duk_small_uint_t call_flags;
- duk_idx_t idx_func;
- duk_int_t rc;
+DUK_INTERNAL duk_int_t duk_pcall_method_flags(duk_hthread *thr, duk_idx_t nargs, duk_small_uint_t call_flags) {
+ duk__pcall_method_args args;
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_ASSERT(thr != NULL);
+ DUK_ASSERT_API_ENTRY(thr);
- idx_func = duk_get_top(ctx) - nargs - 2; /* must work for nargs <= 0 */
- if (idx_func < 0 || nargs < 0) {
- /* See comments in duk_pcall(). */
+ args.nargs = nargs;
+ if (DUK_UNLIKELY(nargs < 0)) {
DUK_ERROR_TYPE_INVALID_ARGS(thr);
return DUK_EXEC_ERROR; /* unreachable */
}
+ args.call_flags = call_flags;
- call_flags = 0; /* respect reclimit, not constructor */
+ return duk_safe_call(thr, duk__pcall_method_raw, (void *) &args /*udata*/, nargs + 2 /*nargs*/, 1 /*nrets*/);
+}
- rc = duk_handle_call_protected(thr, /* thread */
- nargs, /* num_stack_args */
- call_flags); /* call_flags */
+DUK_EXTERNAL duk_int_t duk_pcall_method(duk_hthread *thr, duk_idx_t nargs) {
+ DUK_ASSERT_API_ENTRY(thr);
- return rc;
+ return duk_pcall_method_flags(thr, nargs, 0);
}
-struct duk__pcall_prop_args {
- duk_idx_t obj_idx;
- duk_idx_t nargs;
-};
-typedef struct duk__pcall_prop_args duk__pcall_prop_args;
-
-DUK_LOCAL duk_ret_t duk__pcall_prop_raw(duk_context *ctx, void *udata) {
- duk_idx_t obj_idx;
- duk_idx_t nargs;
+DUK_LOCAL duk_ret_t duk__pcall_prop_raw(duk_hthread *thr, void *udata) {
duk__pcall_prop_args *args;
+ duk_idx_t obj_idx;
+ duk_int_t ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_CTX_VALID(thr);
DUK_ASSERT(udata != NULL);
args = (duk__pcall_prop_args *) udata;
- obj_idx = args->obj_idx;
- nargs = args->nargs;
- obj_idx = duk_require_normalize_index(ctx, obj_idx); /* make absolute */
- duk__call_prop_prep_stack(ctx, obj_idx, nargs);
- duk_call_method(ctx, nargs);
+ obj_idx = duk_require_normalize_index(thr, args->obj_idx); /* make absolute */
+ duk__call_prop_prep_stack(thr, obj_idx, args->nargs);
+
+ ret = duk_handle_call_unprotected_nargs(thr, args->nargs, args->call_flags);
+ DUK_ASSERT(ret == 0);
+ DUK_UNREF(ret);
return 1;
}
-DUK_EXTERNAL duk_int_t duk_pcall_prop(duk_context *ctx, duk_idx_t obj_idx, duk_idx_t nargs) {
+DUK_EXTERNAL duk_int_t duk_pcall_prop(duk_hthread *thr, duk_idx_t obj_idx, duk_idx_t nargs) {
duk__pcall_prop_args args;
- /*
- * Must be careful to catch errors related to value stack manipulation
- * and property lookup, not just the call itself.
- */
-
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
args.obj_idx = obj_idx;
args.nargs = nargs;
+ if (DUK_UNLIKELY(nargs < 0)) {
+ DUK_ERROR_TYPE_INVALID_ARGS(thr);
+ return DUK_EXEC_ERROR; /* unreachable */
+ }
+ args.call_flags = 0;
- /* Inputs: explicit arguments (nargs), +1 for key. If the value stack
- * does not contain enough args, an error is thrown; this matches
- * behavior of the other protected call API functions.
- */
- return duk_safe_call(ctx, duk__pcall_prop_raw, (void *) &args /*udata*/, nargs + 1 /*nargs*/, 1 /*nrets*/);
+ return duk_safe_call(thr, duk__pcall_prop_raw, (void *) &args /*udata*/, nargs + 1 /*nargs*/, 1 /*nrets*/);
}
-DUK_EXTERNAL duk_int_t duk_safe_call(duk_context *ctx, duk_safe_call_function func, void *udata, duk_idx_t nargs, duk_idx_t nrets) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_int_t duk_safe_call(duk_hthread *thr, duk_safe_call_function func, void *udata, duk_idx_t nargs, duk_idx_t nrets) {
duk_int_t rc;
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_ASSERT(thr != NULL);
-
- if (duk_get_top(ctx) < nargs || nrets < 0) {
- /* See comments in duk_pcall(). */
+ DUK_ASSERT_API_ENTRY(thr);
+
+ /* nargs condition; fail if: top - bottom < nargs
+ * <=> top < bottom + nargs
+ * nrets condition; fail if: end - (top - nargs) < nrets
+ * <=> end - top + nargs < nrets
+ * <=> end + nargs < top + nrets
+ */
+ /* XXX: check for any reserve? */
+
+ if (DUK_UNLIKELY((nargs | nrets) < 0 || /* nargs < 0 || nrets < 0; OR sign bits */
+ thr->valstack_top < thr->valstack_bottom + nargs || /* nargs too large compared to top */
+ thr->valstack_end + nargs < thr->valstack_top + nrets)) { /* nrets too large compared to reserve */
+ DUK_D(DUK_DPRINT("not enough stack reserve for safe call or invalid arguments: "
+ "nargs=%ld < 0 (?), nrets=%ld < 0 (?), top=%ld < bottom=%ld + nargs=%ld (?), "
+ "end=%ld + nargs=%ld < top=%ld + nrets=%ld (?)",
+ (long) nargs,
+ (long) nrets,
+ (long) (thr->valstack_top - thr->valstack),
+ (long) (thr->valstack_bottom - thr->valstack),
+ (long) nargs,
+ (long) (thr->valstack_end - thr->valstack),
+ (long) nargs,
+ (long) (thr->valstack_top - thr->valstack),
+ (long) nrets));
DUK_ERROR_TYPE_INVALID_ARGS(thr);
return DUK_EXEC_ERROR; /* unreachable */
}
@@ -13937,248 +14434,53 @@ DUK_EXTERNAL duk_int_t duk_safe_call(duk_context *ctx, duk_safe_call_function fu
return rc;
}
-DUK_EXTERNAL void duk_new(duk_context *ctx, duk_idx_t nargs) {
- /*
- * There are two [[Construct]] operations in the specification:
- *
- * - E5 Section 13.2.2: for Function objects
- * - E5 Section 15.3.4.5.2: for "bound" Function objects
- *
- * The chain of bound functions is resolved in Section 15.3.4.5.2,
- * with arguments "piling up" until the [[Construct]] internal
- * method is called on the final, actual Function object. Note
- * that the "prototype" property is looked up *only* from the
- * final object, *before* calling the constructor.
- *
- * Currently we follow the bound function chain here to get the
- * "prototype" property value from the final, non-bound function.
- * However, we let duk_handle_call() handle the argument "piling"
- * when the constructor is called. The bound function chain is
- * thus now processed twice.
- *
- * When constructing new Array instances, an unnecessary object is
- * created and discarded now: the standard [[Construct]] creates an
- * object, and calls the Array constructor. The Array constructor
- * returns an Array instance, which is used as the result value for
- * the "new" operation; the object created before the Array constructor
- * call is discarded.
- *
- * This would be easy to fix, e.g. by knowing that the Array constructor
- * will always create a replacement object and skip creating the fallback
- * object in that case.
- *
- * Note: functions called via "new" need to know they are called as a
- * constructor. For instance, built-in constructors behave differently
- * depending on how they are called.
- */
-
- /* XXX: merge this with duk_js_call.c, as this function implements
- * core semantics (or perhaps merge the two files altogether).
- */
-
- duk_hthread *thr = (duk_hthread *) ctx;
- duk_hobject *proto;
- duk_hobject *cons;
- duk_hobject *fallback;
- duk_idx_t idx_cons;
- duk_small_uint_t call_flags;
-
- DUK_ASSERT_CTX_VALID(ctx);
-
- /* [... constructor arg1 ... argN] */
-
- idx_cons = duk_require_normalize_index(ctx, -nargs - 1);
-
- DUK_DDD(DUK_DDDPRINT("top=%ld, nargs=%ld, idx_cons=%ld",
- (long) duk_get_top(ctx), (long) nargs, (long) idx_cons));
-
- /* XXX: code duplication */
-
- /*
- * Figure out the final, non-bound constructor, to get "prototype"
- * property.
- */
-
- duk_dup(ctx, idx_cons);
- for (;;) {
- duk_tval *tv;
- tv = DUK_GET_TVAL_NEGIDX(ctx, -1);
- DUK_ASSERT(tv != NULL);
-
- if (DUK_TVAL_IS_OBJECT(tv)) {
- cons = DUK_TVAL_GET_OBJECT(tv);
- DUK_ASSERT(cons != NULL);
- if (!DUK_HOBJECT_IS_CALLABLE(cons) || !DUK_HOBJECT_HAS_CONSTRUCTABLE(cons)) {
- /* Checking callability of the immediate target
- * is important, same for constructability.
- * Checking it for functions down the bound
- * function chain is not strictly necessary
- * because .bind() should normally reject them.
- * But it's good to check anyway because it's
- * technically possible to edit the bound function
- * chain via internal keys.
- */
- goto not_constructable;
- }
- if (!DUK_HOBJECT_HAS_BOUNDFUNC(cons)) {
- break;
- }
- } else if (DUK_TVAL_IS_LIGHTFUNC(tv)) {
- /* Lightfuncs cannot be bound. */
- break;
- } else {
- /* Anything else is not constructable. */
- goto not_constructable;
- }
- duk_get_prop_stridx_short(ctx, -1, DUK_STRIDX_INT_TARGET); /* -> [... cons target] */
- duk_remove_m2(ctx); /* -> [... target] */
- }
- DUK_ASSERT(duk_is_callable(ctx, -1));
- DUK_ASSERT(duk_is_lightfunc(ctx, -1) ||
- (duk_get_hobject(ctx, -1) != NULL && !DUK_HOBJECT_HAS_BOUNDFUNC(duk_get_hobject(ctx, -1))));
-
- /* [... constructor arg1 ... argN final_cons] */
-
- /*
- * Create "fallback" object to be used as the object instance,
- * unless the constructor returns a replacement value.
- * Its internal prototype needs to be set based on "prototype"
- * property of the constructor.
- */
-
- duk_push_object(ctx); /* class Object, extensible */
-
- /* [... constructor arg1 ... argN final_cons fallback] */
-
- duk_get_prop_stridx_short(ctx, -2, DUK_STRIDX_PROTOTYPE);
- proto = duk_get_hobject(ctx, -1);
- if (!proto) {
- DUK_DDD(DUK_DDDPRINT("constructor has no 'prototype' property, or value not an object "
- "-> leave standard Object prototype as fallback prototype"));
- } else {
- DUK_DDD(DUK_DDDPRINT("constructor has 'prototype' property with object value "
- "-> set fallback prototype to that value: %!iO", (duk_heaphdr *) proto));
- fallback = duk_get_hobject(ctx, -2);
- DUK_ASSERT(fallback != NULL);
- DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, fallback, proto);
- }
- duk_pop(ctx);
-
- /* [... constructor arg1 ... argN final_cons fallback] */
-
- /*
- * Manipulate callstack for the call.
- */
-
- duk_dup_top(ctx);
- duk_insert(ctx, idx_cons + 1); /* use fallback as 'this' value */
- duk_insert(ctx, idx_cons); /* also stash it before constructor,
- * in case we need it (as the fallback value)
- */
- duk_pop(ctx); /* pop final_cons */
-
-
- /* [... fallback constructor fallback(this) arg1 ... argN];
- * Note: idx_cons points to first 'fallback', not 'constructor'.
- */
-
- DUK_DDD(DUK_DDDPRINT("before call, idx_cons+1 (constructor) -> %!T, idx_cons+2 (fallback/this) -> %!T, "
- "nargs=%ld, top=%ld",
- (duk_tval *) duk_get_tval(ctx, idx_cons + 1),
- (duk_tval *) duk_get_tval(ctx, idx_cons + 2),
- (long) nargs,
- (long) duk_get_top(ctx)));
-
- /*
- * Call the constructor function (called in "constructor mode").
- */
-
- call_flags = DUK_CALL_FLAG_CONSTRUCTOR_CALL; /* not protected, respect reclimit, is a constructor call */
-
- duk_handle_call_unprotected(thr, /* thread */
- nargs, /* num_stack_args */
- call_flags); /* call_flags */
-
- /* [... fallback retval] */
-
- DUK_DDD(DUK_DDDPRINT("constructor call finished, fallback=%!iT, retval=%!iT",
- (duk_tval *) duk_get_tval(ctx, -2),
- (duk_tval *) duk_get_tval(ctx, -1)));
-
- /*
- * Determine whether to use the constructor return value as the created
- * object instance or not.
- */
-
- if (duk_check_type_mask(ctx, -1, DUK_TYPE_MASK_OBJECT |
- DUK_TYPE_MASK_BUFFER |
- DUK_TYPE_MASK_LIGHTFUNC)) {
- duk_remove_m2(ctx);
- } else {
- duk_pop(ctx);
- }
+DUK_EXTERNAL void duk_new(duk_hthread *thr, duk_idx_t nargs) {
+ duk_idx_t idx_func;
- /*
- * Augment created errors upon creation (not when they are thrown or
- * rethrown). __FILE__ and __LINE__ are not desirable here; the call
- * stack reflects the caller which is correct.
- */
+ DUK_ASSERT_API_ENTRY(thr);
-#if defined(DUK_USE_AUGMENT_ERROR_CREATE)
- duk_hthread_sync_currpc(thr);
- duk_err_augment_error_create(thr, thr, NULL, 0, 1 /*noblame_fileline*/);
-#endif
+ idx_func = duk__call_get_idx_func(thr, nargs, 1);
+ DUK_ASSERT(duk_is_valid_index(thr, idx_func));
- /* [... retval] */
+ duk_push_object(thr); /* default instance; internal proto updated by call handling */
+ duk_insert(thr, idx_func + 1);
- return;
-
- not_constructable:
-#if defined(DUK_USE_VERBOSE_ERRORS)
-#if defined(DUK_USE_PARANOID_ERRORS)
- DUK_ERROR_FMT1(thr, DUK_ERR_TYPE_ERROR, "%s not constructable", duk_get_type_name(ctx, -1));
-#else
- DUK_ERROR_FMT1(thr, DUK_ERR_TYPE_ERROR, "%s not constructable", duk_push_string_readable(ctx, -1));
-#endif
-#else
- DUK_ERROR_TYPE(thr, "not constructable");
-#endif
+ duk_handle_call_unprotected(thr, idx_func, DUK_CALL_FLAG_CONSTRUCT);
}
-DUK_LOCAL duk_ret_t duk__pnew_helper(duk_context *ctx, void *udata) {
+DUK_LOCAL duk_ret_t duk__pnew_helper(duk_hthread *thr, void *udata) {
duk_idx_t nargs;
DUK_ASSERT(udata != NULL);
nargs = *((duk_idx_t *) udata);
- duk_new(ctx, nargs);
+ duk_new(thr, nargs);
return 1;
}
-DUK_EXTERNAL duk_int_t duk_pnew(duk_context *ctx, duk_idx_t nargs) {
+DUK_EXTERNAL duk_int_t duk_pnew(duk_hthread *thr, duk_idx_t nargs) {
duk_int_t rc;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
/* For now, just use duk_safe_call() to wrap duk_new(). We can't
- * simply use a protected duk_handle_call() because there's post
- * processing which might throw. It should be possible to ensure
- * the post processing never throws (except in internal errors and
- * out of memory etc which are always allowed) and then remove this
- * wrapper.
+ * simply use a protected duk_handle_call() because pushing the
+ * default instance might throw.
*/
- rc = duk_safe_call(ctx, duk__pnew_helper, (void *) &nargs /*udata*/, nargs + 1 /*nargs*/, 1 /*nrets*/);
+ if (DUK_UNLIKELY(nargs < 0)) {
+ DUK_ERROR_TYPE_INVALID_ARGS(thr);
+ return DUK_EXEC_ERROR; /* unreachable */
+ }
+
+ rc = duk_safe_call(thr, duk__pnew_helper, (void *) &nargs /*udata*/, nargs + 1 /*nargs*/, 1 /*nrets*/);
return rc;
}
-DUK_EXTERNAL duk_bool_t duk_is_constructor_call(duk_context *ctx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_bool_t duk_is_constructor_call(duk_hthread *thr) {
duk_activation *act;
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_ASSERT(thr != NULL);
- DUK_ASSERT_DISABLE(thr->callstack_top >= 0);
+ DUK_ASSERT_API_ENTRY(thr);
act = thr->callstack_curr;
if (act != NULL) {
@@ -14190,14 +14492,15 @@ DUK_EXTERNAL duk_bool_t duk_is_constructor_call(duk_context *ctx) {
/* XXX: Make this obsolete by adding a function flag for rejecting a
* non-constructor call automatically?
*/
-DUK_INTERNAL void duk_require_constructor_call(duk_context *ctx) {
- if (!duk_is_constructor_call(ctx)) {
- DUK_ERROR_TYPE((duk_hthread *) ctx, DUK_STR_CONSTRUCT_ONLY);
+DUK_INTERNAL void duk_require_constructor_call(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+
+ if (!duk_is_constructor_call(thr)) {
+ DUK_ERROR_TYPE(thr, DUK_STR_CONSTRUCT_ONLY);
}
}
-DUK_EXTERNAL duk_bool_t duk_is_strict_call(duk_context *ctx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_bool_t duk_is_strict_call(duk_hthread *thr) {
duk_activation *act;
/* For user code this could just return 1 (strict) always
@@ -14209,9 +14512,7 @@ DUK_EXTERNAL duk_bool_t duk_is_strict_call(duk_context *ctx) {
* the internal call sites.
*/
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_ASSERT(thr != NULL);
- DUK_ASSERT_DISABLE(thr->callstack_top >= 0);
+ DUK_ASSERT_API_ENTRY(thr);
act = thr->callstack_curr;
if (act != NULL) {
@@ -14226,14 +14527,11 @@ DUK_EXTERNAL duk_bool_t duk_is_strict_call(duk_context *ctx) {
* Duktape/C function magic
*/
-DUK_EXTERNAL duk_int_t duk_get_current_magic(duk_context *ctx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_int_t duk_get_current_magic(duk_hthread *thr) {
duk_activation *act;
duk_hobject *func;
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_ASSERT(thr != NULL);
- DUK_ASSERT_DISABLE(thr->callstack_top >= 0);
+ DUK_ASSERT_API_ENTRY(thr);
act = thr->callstack_curr;
if (act) {
@@ -14254,14 +14552,13 @@ DUK_EXTERNAL duk_int_t duk_get_current_magic(duk_context *ctx) {
return 0;
}
-DUK_EXTERNAL duk_int_t duk_get_magic(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_int_t duk_get_magic(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
duk_hobject *h;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- tv = duk_require_tval(ctx, idx);
+ tv = duk_require_tval(thr, idx);
if (DUK_TVAL_IS_OBJECT(tv)) {
h = DUK_TVAL_GET_OBJECT(tv);
DUK_ASSERT(h != NULL);
@@ -14280,12 +14577,12 @@ DUK_EXTERNAL duk_int_t duk_get_magic(duk_context *ctx, duk_idx_t idx) {
return 0;
}
-DUK_EXTERNAL void duk_set_magic(duk_context *ctx, duk_idx_t idx, duk_int_t magic) {
+DUK_EXTERNAL void duk_set_magic(duk_hthread *thr, duk_idx_t idx, duk_int_t magic) {
duk_hnatfunc *nf;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- nf = duk_require_hnatfunc(ctx, idx);
+ nf = duk_require_hnatfunc(thr, idx);
DUK_ASSERT(nf != NULL);
nf->magic = (duk_int16_t) magic;
}
@@ -14294,30 +14591,40 @@ DUK_EXTERNAL void duk_set_magic(duk_context *ctx, duk_idx_t idx, duk_int_t magic
* Misc helpers
*/
-DUK_INTERNAL void duk_resolve_nonbound_function(duk_context *ctx) {
- duk_uint_t sanity;
+/* Resolve a bound function on value stack top to a non-bound target
+ * (leave other values as is).
+ */
+DUK_INTERNAL void duk_resolve_nonbound_function(duk_hthread *thr) {
duk_tval *tv;
- sanity = DUK_HOBJECT_BOUND_CHAIN_SANITY;
- do {
- tv = DUK_GET_TVAL_NEGIDX(ctx, -1);
- if (DUK_TVAL_IS_LIGHTFUNC(tv)) {
- /* Lightweight function: never bound, so terminate. */
- break;
- } else if (DUK_TVAL_IS_OBJECT(tv)) {
- duk_hobject *func;
+ DUK_ASSERT_HTHREAD_VALID(thr);
- func = DUK_TVAL_GET_OBJECT(tv);
- DUK_ASSERT(func != NULL);
- if (!DUK_HOBJECT_IS_CALLABLE(func) || !DUK_HOBJECT_HAS_BOUNDFUNC(func)) {
- break;
- }
- duk_get_prop_stridx_short(ctx, -1, DUK_STRIDX_INT_TARGET);
- duk_replace(ctx, -2);
- } else {
- break;
+ tv = DUK_GET_TVAL_NEGIDX(thr, -1);
+ if (DUK_TVAL_IS_OBJECT(tv)) {
+ duk_hobject *h;
+
+ h = DUK_TVAL_GET_OBJECT(tv);
+ DUK_ASSERT(h != NULL);
+ if (DUK_HOBJECT_HAS_BOUNDFUNC(h)) {
+ duk_push_tval(thr, &((duk_hboundfunc *) h)->target);
+ duk_replace(thr, -2);
+#if 0
+ DUK_TVAL_SET_TVAL(tv, &((duk_hboundfunc *) h)->target);
+ DUK_TVAL_INCREF(thr, tv);
+ DUK_HOBJECT_DECREF_NORZ(thr, h);
+#endif
+ /* Rely on Function.prototype.bind() on never creating a bound
+ * function whose target is not proper. This is now safe
+ * because the target is not even an internal property but a
+ * struct member.
+ */
+ DUK_ASSERT(duk_is_lightfunc(thr, -1) || duk_is_callable(thr, -1));
}
- } while (--sanity > 0);
+ }
+
+ /* Lightfuncs cannot be bound but are always callable and
+ * constructable.
+ */
}
/*
* Encoding and decoding basic formats: hex, base64.
@@ -14333,21 +14640,21 @@ DUK_INTERNAL void duk_resolve_nonbound_function(duk_context *ctx) {
* buffer and string values because they're the most common. In particular,
* avoid creating a temporary string or buffer when possible.
*/
-DUK_LOCAL const duk_uint8_t *duk__prep_codec_arg(duk_context *ctx, duk_idx_t idx, duk_size_t *out_len) {
+DUK_LOCAL const duk_uint8_t *duk__prep_codec_arg(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_len) {
void *ptr;
duk_bool_t isbuffer;
- DUK_ASSERT(duk_is_valid_index(ctx, idx)); /* checked by caller */
+ DUK_ASSERT(duk_is_valid_index(thr, idx)); /* checked by caller */
/* XXX: with def_ptr set to a stack related pointer, isbuffer could
* be removed from the helper?
*/
- ptr = duk_get_buffer_data_raw(ctx, idx, out_len, NULL /*def_ptr*/, 0 /*def_size*/, 0 /*throw_flag*/, &isbuffer);
+ ptr = duk_get_buffer_data_raw(thr, idx, out_len, NULL /*def_ptr*/, 0 /*def_size*/, 0 /*throw_flag*/, &isbuffer);
if (isbuffer) {
DUK_ASSERT(*out_len == 0 || ptr != NULL);
return (const duk_uint8_t *) ptr;
}
- return (const duk_uint8_t *) duk_to_lstring(ctx, idx, out_len);
+ return (const duk_uint8_t *) duk_to_lstring(thr, idx, out_len);
}
#if defined(DUK_USE_BASE64_FASTPATH)
@@ -14696,22 +15003,21 @@ DUK_LOCAL duk_bool_t duk__base64_decode_helper(const duk_uint8_t *src, duk_size_
}
#endif /* DUK_USE_BASE64_FASTPATH */
-DUK_EXTERNAL const char *duk_base64_encode(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL const char *duk_base64_encode(duk_hthread *thr, duk_idx_t idx) {
const duk_uint8_t *src;
duk_size_t srclen;
duk_size_t dstlen;
duk_uint8_t *dst;
const char *ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
/* XXX: optimize for string inputs: no need to coerce to a buffer
* which makes a copy of the input.
*/
- idx = duk_require_normalize_index(ctx, idx);
- src = duk__prep_codec_arg(ctx, idx, &srclen);
+ idx = duk_require_normalize_index(thr, idx);
+ src = duk__prep_codec_arg(thr, idx, &srclen);
/* Note: for srclen=0, src may be NULL */
/* Computation must not wrap; this limit works for 32-bit size_t:
@@ -14723,21 +15029,20 @@ DUK_EXTERNAL const char *duk_base64_encode(duk_context *ctx, duk_idx_t idx) {
goto type_error;
}
dstlen = (srclen + 2) / 3 * 4;
- dst = (duk_uint8_t *) duk_push_fixed_buffer_nozero(ctx, dstlen);
+ dst = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, dstlen);
duk__base64_encode_helper((const duk_uint8_t *) src, srclen, dst);
- ret = duk_buffer_to_string(ctx, -1); /* Safe, result is ASCII. */
- duk_replace(ctx, idx);
+ ret = duk_buffer_to_string(thr, -1); /* Safe, result is ASCII. */
+ duk_replace(thr, idx);
return ret;
type_error:
- DUK_ERROR_TYPE(thr, DUK_STR_ENCODE_FAILED);
+ DUK_ERROR_TYPE(thr, DUK_STR_BASE64_ENCODE_FAILED);
return NULL; /* never here */
}
-DUK_EXTERNAL void duk_base64_decode(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_base64_decode(duk_hthread *thr, duk_idx_t idx) {
const duk_uint8_t *src;
duk_size_t srclen;
duk_size_t dstlen;
@@ -14745,14 +15050,14 @@ DUK_EXTERNAL void duk_base64_decode(duk_context *ctx, duk_idx_t idx) {
duk_uint8_t *dst_final;
duk_bool_t retval;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
/* XXX: optimize for buffer inputs: no need to coerce to a string
* which causes an unnecessary interning.
*/
- idx = duk_require_normalize_index(ctx, idx);
- src = duk__prep_codec_arg(ctx, idx, &srclen);
+ idx = duk_require_normalize_index(thr, idx);
+ src = duk__prep_codec_arg(thr, idx, &srclen);
/* Computation must not wrap, only srclen + 3 is at risk of
* wrapping because after that the number gets smaller.
@@ -14763,7 +15068,7 @@ DUK_EXTERNAL void duk_base64_decode(duk_context *ctx, duk_idx_t idx) {
goto type_error;
}
dstlen = (srclen + 3) / 4 * 3; /* upper limit, assuming no whitespace etc */
- dst = (duk_uint8_t *) duk_push_dynamic_buffer(ctx, dstlen);
+ dst = (duk_uint8_t *) duk_push_dynamic_buffer(thr, dstlen);
/* Note: for dstlen=0, dst may be NULL */
retval = duk__base64_decode_helper((const duk_uint8_t *) src, srclen, dst, &dst_final);
@@ -14772,15 +15077,15 @@ DUK_EXTERNAL void duk_base64_decode(duk_context *ctx, duk_idx_t idx) {
}
/* XXX: convert to fixed buffer? */
- (void) duk_resize_buffer(ctx, -1, (duk_size_t) (dst_final - dst));
- duk_replace(ctx, idx);
+ (void) duk_resize_buffer(thr, -1, (duk_size_t) (dst_final - dst));
+ duk_replace(thr, idx);
return;
type_error:
- DUK_ERROR_TYPE(thr, DUK_STR_DECODE_FAILED);
+ DUK_ERROR_TYPE(thr, DUK_STR_BASE64_DECODE_FAILED);
}
-DUK_EXTERNAL const char *duk_hex_encode(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL const char *duk_hex_encode(duk_hthread *thr, duk_idx_t idx) {
const duk_uint8_t *inp;
duk_size_t len;
duk_size_t i;
@@ -14791,14 +15096,14 @@ DUK_EXTERNAL const char *duk_hex_encode(duk_context *ctx, duk_idx_t idx) {
duk_uint16_t *p16;
#endif
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- idx = duk_require_normalize_index(ctx, idx);
- inp = duk__prep_codec_arg(ctx, idx, &len);
+ idx = duk_require_normalize_index(thr, idx);
+ inp = duk__prep_codec_arg(thr, idx, &len);
DUK_ASSERT(inp != NULL || len == 0);
/* Fixed buffer, no zeroing because we'll fill all the data. */
- buf = (duk_uint8_t *) duk_push_fixed_buffer_nozero(ctx, len * 2);
+ buf = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, len * 2);
DUK_ASSERT(buf != NULL);
#if defined(DUK_USE_HEX_FASTPATH)
@@ -14831,13 +15136,12 @@ DUK_EXTERNAL const char *duk_hex_encode(duk_context *ctx, duk_idx_t idx) {
* caller coerce to string if necessary?
*/
- ret = duk_buffer_to_string(ctx, -1); /* Safe, result is ASCII. */
- duk_replace(ctx, idx);
+ ret = duk_buffer_to_string(thr, -1); /* Safe, result is ASCII. */
+ duk_replace(thr, idx);
return ret;
}
-DUK_EXTERNAL void duk_hex_decode(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_hex_decode(duk_hthread *thr, duk_idx_t idx) {
const duk_uint8_t *inp;
duk_size_t len;
duk_size_t i;
@@ -14849,10 +15153,10 @@ DUK_EXTERNAL void duk_hex_decode(duk_context *ctx, duk_idx_t idx) {
duk_size_t len_safe;
#endif
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- idx = duk_require_normalize_index(ctx, idx);
- inp = duk__prep_codec_arg(ctx, idx, &len);
+ idx = duk_require_normalize_index(thr, idx);
+ inp = duk__prep_codec_arg(thr, idx, &len);
DUK_ASSERT(inp != NULL || len == 0);
if (len & 0x01) {
@@ -14860,7 +15164,7 @@ DUK_EXTERNAL void duk_hex_decode(duk_context *ctx, duk_idx_t idx) {
}
/* Fixed buffer, no zeroing because we'll fill all the data. */
- buf = (duk_uint8_t *) duk_push_fixed_buffer_nozero(ctx, len / 2);
+ buf = (duk_uint8_t *) duk_push_fixed_buffer_nozero(thr, len / 2);
DUK_ASSERT(buf != NULL);
#if defined(DUK_USE_HEX_FASTPATH)
@@ -14913,68 +15217,70 @@ DUK_EXTERNAL void duk_hex_decode(duk_context *ctx, duk_idx_t idx) {
}
#endif /* DUK_USE_HEX_FASTPATH */
- duk_replace(ctx, idx);
+ duk_replace(thr, idx);
return;
type_error:
- DUK_ERROR_TYPE(thr, DUK_STR_DECODE_FAILED);
+ DUK_ERROR_TYPE(thr, DUK_STR_HEX_DECODE_FAILED);
}
#if defined(DUK_USE_JSON_SUPPORT)
-DUK_EXTERNAL const char *duk_json_encode(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL const char *duk_json_encode(duk_hthread *thr, duk_idx_t idx) {
#if defined(DUK_USE_ASSERTIONS)
duk_idx_t top_at_entry;
#endif
const char *ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
#if defined(DUK_USE_ASSERTIONS)
- top_at_entry = duk_get_top(ctx);
+ top_at_entry = duk_get_top(thr);
#endif
- idx = duk_require_normalize_index(ctx, idx);
- duk_bi_json_stringify_helper(ctx,
+ idx = duk_require_normalize_index(thr, idx);
+ duk_bi_json_stringify_helper(thr,
idx /*idx_value*/,
DUK_INVALID_INDEX /*idx_replacer*/,
DUK_INVALID_INDEX /*idx_space*/,
0 /*flags*/);
- DUK_ASSERT(duk_is_string(ctx, -1));
- duk_replace(ctx, idx);
- ret = duk_get_string(ctx, idx);
+ DUK_ASSERT(duk_is_string(thr, -1));
+ duk_replace(thr, idx);
+ ret = duk_get_string(thr, idx);
- DUK_ASSERT(duk_get_top(ctx) == top_at_entry);
+ DUK_ASSERT(duk_get_top(thr) == top_at_entry);
return ret;
}
-DUK_EXTERNAL void duk_json_decode(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL void duk_json_decode(duk_hthread *thr, duk_idx_t idx) {
#if defined(DUK_USE_ASSERTIONS)
duk_idx_t top_at_entry;
#endif
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
#if defined(DUK_USE_ASSERTIONS)
- top_at_entry = duk_get_top(ctx);
+ top_at_entry = duk_get_top(thr);
#endif
- idx = duk_require_normalize_index(ctx, idx);
- duk_bi_json_parse_helper(ctx,
+ idx = duk_require_normalize_index(thr, idx);
+ duk_bi_json_parse_helper(thr,
idx /*idx_value*/,
DUK_INVALID_INDEX /*idx_reviver*/,
0 /*flags*/);
- duk_replace(ctx, idx);
+ duk_replace(thr, idx);
- DUK_ASSERT(duk_get_top(ctx) == top_at_entry);
+ DUK_ASSERT(duk_get_top(thr) == top_at_entry);
}
#else /* DUK_USE_JSON_SUPPORT */
-DUK_EXTERNAL const char *duk_json_encode(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL const char *duk_json_encode(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_UNREF(idx);
- DUK_ERROR_UNSUPPORTED((duk_hthread *) ctx);
+ DUK_ERROR_UNSUPPORTED(thr);
}
-DUK_EXTERNAL void duk_json_decode(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL void duk_json_decode(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_UNREF(idx);
- DUK_ERROR_UNSUPPORTED((duk_hthread *) ctx);
+ DUK_ERROR_UNSUPPORTED(thr);
}
#endif /* DUK_USE_JSON_SUPPORT */
/*
@@ -14991,10 +15297,10 @@ struct duk__compile_raw_args {
};
/* Eval is just a wrapper now. */
-DUK_EXTERNAL duk_int_t duk_eval_raw(duk_context *ctx, const char *src_buffer, duk_size_t src_length, duk_uint_t flags) {
+DUK_EXTERNAL duk_int_t duk_eval_raw(duk_hthread *thr, const char *src_buffer, duk_size_t src_length, duk_uint_t flags) {
duk_int_t rc;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
/* Note: strictness is *not* inherited from the current Duktape/C.
* This would be confusing because the current strictness state
@@ -15005,7 +15311,7 @@ DUK_EXTERNAL duk_int_t duk_eval_raw(duk_context *ctx, const char *src_buffer, du
/* [ ... source? filename? ] (depends on flags) */
- rc = duk_compile_raw(ctx, src_buffer, src_length, flags | DUK_COMPILE_EVAL); /* may be safe, or non-safe depending on flags */
+ rc = duk_compile_raw(thr, src_buffer, src_length, flags | DUK_COMPILE_EVAL); /* may be safe, or non-safe depending on flags */
/* [ ... closure/error ] */
@@ -15014,12 +15320,12 @@ DUK_EXTERNAL duk_int_t duk_eval_raw(duk_context *ctx, const char *src_buffer, du
goto got_rc;
}
- duk_push_global_object(ctx); /* explicit 'this' binding, see GH-164 */
+ duk_push_global_object(thr); /* explicit 'this' binding, see GH-164 */
if (flags & DUK_COMPILE_SAFE) {
- rc = duk_pcall_method(ctx, 0);
+ rc = duk_pcall_method(thr, 0);
} else {
- duk_call_method(ctx, 0);
+ duk_call_method(thr, 0);
rc = DUK_EXEC_SUCCESS;
}
@@ -15027,20 +15333,19 @@ DUK_EXTERNAL duk_int_t duk_eval_raw(duk_context *ctx, const char *src_buffer, du
got_rc:
if (flags & DUK_COMPILE_NORESULT) {
- duk_pop(ctx);
+ duk_pop(thr);
}
return rc;
}
/* Helper which can be called both directly and with duk_safe_call(). */
-DUK_LOCAL duk_ret_t duk__do_compile(duk_context *ctx, void *udata) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_LOCAL duk_ret_t duk__do_compile(duk_hthread *thr, void *udata) {
duk__compile_raw_args *comp_args;
duk_uint_t flags;
duk_hcompfunc *h_templ;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_CTX_VALID(thr);
DUK_ASSERT(udata != NULL);
/* Note: strictness is not inherited from the current Duktape/C
@@ -15057,7 +15362,7 @@ DUK_LOCAL duk_ret_t duk__do_compile(duk_context *ctx, void *udata) {
if (flags & DUK_COMPILE_NOFILENAME) {
/* Automatic filename: 'eval' or 'input'. */
- duk_push_hstring_stridx(ctx, (flags & DUK_COMPILE_EVAL) ? DUK_STRIDX_EVAL : DUK_STRIDX_INPUT);
+ duk_push_hstring_stridx(thr, (flags & DUK_COMPILE_EVAL) ? DUK_STRIDX_EVAL : DUK_STRIDX_INPUT);
}
/* [ ... source? filename ] */
@@ -15065,7 +15370,7 @@ DUK_LOCAL duk_ret_t duk__do_compile(duk_context *ctx, void *udata) {
if (!comp_args->src_buffer) {
duk_hstring *h_sourcecode;
- h_sourcecode = duk_get_hstring(ctx, -2);
+ h_sourcecode = duk_get_hstring(thr, -2);
if ((flags & DUK_COMPILE_NOSOURCE) || /* args incorrect */
(h_sourcecode == NULL)) { /* e.g. duk_push_string_file_raw() pushed undefined */
DUK_ERROR_TYPE(thr, DUK_STR_NO_SOURCECODE);
@@ -15089,29 +15394,29 @@ DUK_LOCAL duk_ret_t duk__do_compile(duk_context *ctx, void *udata) {
if (flags & DUK_COMPILE_NOSOURCE) {
;
} else {
- duk_remove_m2(ctx);
+ duk_remove_m2(thr);
}
/* [ ... func_template ] */
- h_templ = (duk_hcompfunc *) duk_known_hobject(ctx, -1);
+ h_templ = (duk_hcompfunc *) duk_known_hobject(thr, -1);
duk_js_push_closure(thr,
h_templ,
thr->builtins[DUK_BIDX_GLOBAL_ENV],
thr->builtins[DUK_BIDX_GLOBAL_ENV],
1 /*add_auto_proto*/);
- duk_remove_m2(ctx); /* -> [ ... closure ] */
+ duk_remove_m2(thr); /* -> [ ... closure ] */
/* [ ... closure ] */
return 1;
}
-DUK_EXTERNAL duk_int_t duk_compile_raw(duk_context *ctx, const char *src_buffer, duk_size_t src_length, duk_uint_t flags) {
+DUK_EXTERNAL duk_int_t duk_compile_raw(duk_hthread *thr, const char *src_buffer, duk_size_t src_length, duk_uint_t flags) {
duk__compile_raw_args comp_args_alloc;
duk__compile_raw_args *comp_args = &comp_args_alloc;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
if ((flags & DUK_COMPILE_STRLEN) && (src_buffer != NULL)) {
/* String length is computed here to avoid multiple evaluation
@@ -15138,13 +15443,13 @@ DUK_EXTERNAL duk_int_t duk_compile_raw(duk_context *ctx, const char *src_buffer,
nargs = flags & 0x07;
DUK_ASSERT(nargs == ((flags & DUK_COMPILE_NOSOURCE) ? 0 : 1) +
((flags & DUK_COMPILE_NOFILENAME) ? 0 : 1));
- rc = duk_safe_call(ctx, duk__do_compile, (void *) comp_args, nargs, nrets);
+ rc = duk_safe_call(thr, duk__do_compile, (void *) comp_args, nargs, nrets);
/* [ ... closure ] */
return rc;
}
- (void) duk__do_compile(ctx, (void *) comp_args);
+ (void) duk__do_compile(thr, (void *) comp_args);
/* [ ... closure ] */
return DUK_EXEC_SUCCESS;
@@ -15156,48 +15461,49 @@ DUK_EXTERNAL duk_int_t duk_compile_raw(duk_context *ctx, const char *src_buffer,
/* #include duk_internal.h -> already included */
#if defined(DUK_USE_JSON_SUPPORT)
-DUK_EXTERNAL void duk_push_context_dump(duk_context *ctx) {
+DUK_EXTERNAL void duk_push_context_dump(duk_hthread *thr) {
duk_idx_t idx;
duk_idx_t top;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
/* We don't duk_require_stack() here now, but rely on the caller having
* enough space.
*/
- top = duk_get_top(ctx);
- duk_push_array(ctx);
+ top = duk_get_top(thr);
+ duk_push_array(thr);
for (idx = 0; idx < top; idx++) {
- duk_dup(ctx, idx);
- duk_put_prop_index(ctx, -2, idx);
+ duk_dup(thr, idx);
+ duk_put_prop_index(thr, -2, (duk_uarridx_t) idx);
}
/* XXX: conversion errors should not propagate outwards.
* Perhaps values need to be coerced individually?
*/
- duk_bi_json_stringify_helper(ctx,
- duk_get_top_index(ctx), /*idx_value*/
+ duk_bi_json_stringify_helper(thr,
+ duk_get_top_index(thr), /*idx_value*/
DUK_INVALID_INDEX, /*idx_replacer*/
DUK_INVALID_INDEX, /*idx_space*/
DUK_JSON_FLAG_EXT_CUSTOM |
DUK_JSON_FLAG_ASCII_ONLY |
DUK_JSON_FLAG_AVOID_KEY_QUOTES /*flags*/);
- duk_push_sprintf(ctx, "ctx: top=%ld, stack=%s", (long) top, (const char *) duk_safe_to_string(ctx, -1));
- duk_replace(ctx, -3); /* [ ... arr jsonx(arr) res ] -> [ ... res jsonx(arr) ] */
- duk_pop(ctx);
- DUK_ASSERT(duk_is_string(ctx, -1));
+ duk_push_sprintf(thr, "ctx: top=%ld, stack=%s", (long) top, (const char *) duk_safe_to_string(thr, -1));
+ duk_replace(thr, -3); /* [ ... arr jsonx(arr) res ] -> [ ... res jsonx(arr) ] */
+ duk_pop(thr);
+ DUK_ASSERT(duk_is_string(thr, -1));
}
#else /* DUK_USE_JSON_SUPPORT */
-DUK_EXTERNAL void duk_push_context_dump(duk_context *ctx) {
- DUK_ERROR_UNSUPPORTED((duk_hthread *) ctx);
+DUK_EXTERNAL void duk_push_context_dump(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ DUK_ERROR_UNSUPPORTED(thr);
}
#endif /* DUK_USE_JSON_SUPPORT */
#if defined(DUK_USE_DEBUGGER_SUPPORT)
-DUK_EXTERNAL void duk_debugger_attach(duk_context *ctx,
+DUK_EXTERNAL void duk_debugger_attach(duk_hthread *thr,
duk_debug_read_function read_cb,
duk_debug_write_function write_cb,
duk_debug_peek_function peek_cb,
@@ -15206,7 +15512,6 @@ DUK_EXTERNAL void duk_debugger_attach(duk_context *ctx,
duk_debug_request_function request_cb,
duk_debug_detached_function detached_cb,
void *udata) {
- duk_hthread *thr = (duk_hthread *) ctx;
duk_heap *heap;
const char *str;
duk_size_t len;
@@ -15217,7 +15522,7 @@ DUK_EXTERNAL void duk_debugger_attach(duk_context *ctx,
DUK_D(DUK_DPRINT("application called duk_debugger_attach()"));
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(read_cb != NULL);
DUK_ASSERT(write_cb != NULL);
/* Other callbacks are optional. */
@@ -15237,10 +15542,9 @@ DUK_EXTERNAL void duk_debugger_attach(duk_context *ctx,
heap->dbg_processing = 0;
heap->dbg_state_dirty = 0;
heap->dbg_force_restart = 0;
- heap->dbg_step_type = DUK_STEP_TYPE_NONE;
- heap->dbg_step_thread = NULL;
- heap->dbg_step_csindex = 0;
- heap->dbg_step_startline = 0;
+ heap->dbg_pause_flags = 0;
+ heap->dbg_pause_act = NULL;
+ heap->dbg_pause_startline = 0;
heap->dbg_exec_counter = 0;
heap->dbg_last_counter = 0;
heap->dbg_last_time = 0.0;
@@ -15249,45 +15553,38 @@ DUK_EXTERNAL void duk_debugger_attach(duk_context *ctx,
/* Send version identification and flush right afterwards. Note that
* we must write raw, unframed bytes here.
*/
- duk_push_sprintf(ctx, "%ld %ld %s %s\n",
+ duk_push_sprintf(thr, "%ld %ld %s %s\n",
(long) DUK_DEBUG_PROTOCOL_VERSION,
(long) DUK_VERSION,
(const char *) DUK_GIT_DESCRIBE,
(const char *) DUK_USE_TARGET_INFO);
- str = duk_get_lstring(ctx, -1, &len);
+ str = duk_get_lstring(thr, -1, &len);
DUK_ASSERT(str != NULL);
duk_debug_write_bytes(thr, (const duk_uint8_t *) str, len);
duk_debug_write_flush(thr);
- duk_pop(ctx);
+ duk_pop(thr);
}
-DUK_EXTERNAL void duk_debugger_detach(duk_context *ctx) {
- duk_hthread *thr;
-
+DUK_EXTERNAL void duk_debugger_detach(duk_hthread *thr) {
DUK_D(DUK_DPRINT("application called duk_debugger_detach()"));
- DUK_ASSERT_CTX_VALID(ctx);
- thr = (duk_hthread *) ctx;
- DUK_ASSERT(thr != NULL);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(thr->heap != NULL);
/* Can be called multiple times with no harm. */
duk_debug_do_detach(thr->heap);
}
-DUK_EXTERNAL void duk_debugger_cooperate(duk_context *ctx) {
- duk_hthread *thr;
+DUK_EXTERNAL void duk_debugger_cooperate(duk_hthread *thr) {
duk_bool_t processed_messages;
- DUK_ASSERT_CTX_VALID(ctx);
- thr = (duk_hthread *) ctx;
- DUK_ASSERT(thr != NULL);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(thr->heap != NULL);
if (!duk_debug_is_attached(thr->heap)) {
return;
}
- if (thr->callstack_top > 0 || thr->heap->dbg_processing) {
+ if (thr->callstack_curr != NULL || thr->heap->dbg_processing) {
/* Calling duk_debugger_cooperate() while Duktape is being
* called into is not supported. This is not a 100% check
* but prevents any damage in most cases.
@@ -15299,20 +15596,17 @@ DUK_EXTERNAL void duk_debugger_cooperate(duk_context *ctx) {
DUK_UNREF(processed_messages);
}
-DUK_EXTERNAL duk_bool_t duk_debugger_notify(duk_context *ctx, duk_idx_t nvalues) {
- duk_hthread *thr;
+DUK_EXTERNAL duk_bool_t duk_debugger_notify(duk_hthread *thr, duk_idx_t nvalues) {
duk_idx_t top;
duk_idx_t idx;
duk_bool_t ret = 0;
- DUK_ASSERT_CTX_VALID(ctx);
- thr = (duk_hthread *) ctx;
- DUK_ASSERT(thr != NULL);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(thr->heap != NULL);
DUK_D(DUK_DPRINT("application called duk_debugger_notify() with nvalues=%ld", (long) nvalues));
- top = duk_get_top(ctx);
+ top = duk_get_top(thr);
if (top < nvalues) {
DUK_ERROR_RANGE(thr, "not enough stack values for notify");
return ret; /* unreachable */
@@ -15320,7 +15614,7 @@ DUK_EXTERNAL duk_bool_t duk_debugger_notify(duk_context *ctx, duk_idx_t nvalues)
if (duk_debug_is_attached(thr->heap)) {
duk_debug_write_notify(thr, DUK_DBG_CMD_APPNOTIFY);
for (idx = top - nvalues; idx < top; idx++) {
- duk_tval *tv = DUK_GET_TVAL_POSIDX(ctx, idx);
+ duk_tval *tv = DUK_GET_TVAL_POSIDX(thr, idx);
duk_debug_write_tval(thr, tv);
}
duk_debug_write_eom(thr);
@@ -15334,16 +15628,12 @@ DUK_EXTERNAL duk_bool_t duk_debugger_notify(duk_context *ctx, duk_idx_t nvalues)
ret = 1;
}
}
- duk_pop_n(ctx, nvalues);
+ duk_pop_n(thr, nvalues);
return ret;
}
-DUK_EXTERNAL void duk_debugger_pause(duk_context *ctx) {
- duk_hthread *thr;
-
- DUK_ASSERT_CTX_VALID(ctx);
- thr = (duk_hthread *) ctx;
- DUK_ASSERT(thr != NULL);
+DUK_EXTERNAL void duk_debugger_pause(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(thr->heap != NULL);
DUK_D(DUK_DPRINT("application called duk_debugger_pause()"));
@@ -15367,7 +15657,7 @@ DUK_EXTERNAL void duk_debugger_pause(duk_context *ctx) {
#else /* DUK_USE_DEBUGGER_SUPPORT */
-DUK_EXTERNAL void duk_debugger_attach(duk_context *ctx,
+DUK_EXTERNAL void duk_debugger_attach(duk_hthread *thr,
duk_debug_read_function read_cb,
duk_debug_write_function write_cb,
duk_debug_peek_function peek_cb,
@@ -15376,7 +15666,7 @@ DUK_EXTERNAL void duk_debugger_attach(duk_context *ctx,
duk_debug_request_function request_cb,
duk_debug_detached_function detached_cb,
void *udata) {
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_UNREF(read_cb);
DUK_UNREF(write_cb);
DUK_UNREF(peek_cb);
@@ -15385,40 +15675,40 @@ DUK_EXTERNAL void duk_debugger_attach(duk_context *ctx,
DUK_UNREF(request_cb);
DUK_UNREF(detached_cb);
DUK_UNREF(udata);
- DUK_ERROR_TYPE((duk_hthread *) ctx, "no debugger support");
+ DUK_ERROR_TYPE(thr, "no debugger support");
}
-DUK_EXTERNAL void duk_debugger_detach(duk_context *ctx) {
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_ERROR_TYPE((duk_hthread *) ctx, "no debugger support");
+DUK_EXTERNAL void duk_debugger_detach(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ DUK_ERROR_TYPE(thr, "no debugger support");
}
-DUK_EXTERNAL void duk_debugger_cooperate(duk_context *ctx) {
+DUK_EXTERNAL void duk_debugger_cooperate(duk_hthread *thr) {
/* nop */
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_UNREF(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
+ DUK_UNREF(thr);
}
-DUK_EXTERNAL duk_bool_t duk_debugger_notify(duk_context *ctx, duk_idx_t nvalues) {
+DUK_EXTERNAL duk_bool_t duk_debugger_notify(duk_hthread *thr, duk_idx_t nvalues) {
duk_idx_t top;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- top = duk_get_top(ctx);
+ top = duk_get_top(thr);
if (top < nvalues) {
- DUK_ERROR_RANGE_INVALID_COUNT((duk_hthread *) ctx);
+ DUK_ERROR_RANGE_INVALID_COUNT(thr);
return 0; /* unreachable */
}
/* No debugger support, just pop values. */
- duk_pop_n(ctx, nvalues);
+ duk_pop_n(thr, nvalues);
return 0;
}
-DUK_EXTERNAL void duk_debugger_pause(duk_context *ctx) {
+DUK_EXTERNAL void duk_debugger_pause(duk_hthread *thr) {
/* Treat like debugger statement: nop */
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_UNREF(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
+ DUK_UNREF(thr);
}
#endif /* DUK_USE_DEBUGGER_SUPPORT */
@@ -15437,14 +15727,13 @@ struct duk_internal_thread_state {
duk_int_t call_recursion_depth;
};
-DUK_EXTERNAL
-duk_context *duk_create_heap(duk_alloc_function alloc_func,
- duk_realloc_function realloc_func,
- duk_free_function free_func,
- void *heap_udata,
- duk_fatal_function fatal_handler) {
+DUK_EXTERNAL duk_hthread *duk_create_heap(duk_alloc_function alloc_func,
+ duk_realloc_function realloc_func,
+ duk_free_function free_func,
+ void *heap_udata,
+ duk_fatal_function fatal_handler) {
duk_heap *heap = NULL;
- duk_context *ctx;
+ duk_hthread *thr;
/* Assume that either all memory funcs are NULL or non-NULL, mixed
* cases will now be unsafe.
@@ -15483,33 +15772,31 @@ duk_context *duk_create_heap(duk_alloc_function alloc_func,
if (!heap) {
return NULL;
}
- ctx = (duk_context *) heap->heap_thread;
- DUK_ASSERT(ctx != NULL);
- DUK_ASSERT(((duk_hthread *) ctx)->heap != NULL);
- return ctx;
+ thr = heap->heap_thread;
+ DUK_ASSERT(thr != NULL);
+ DUK_ASSERT(thr->heap != NULL);
+ return thr;
}
-DUK_EXTERNAL void duk_destroy_heap(duk_context *ctx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_destroy_heap(duk_hthread *thr) {
duk_heap *heap;
- if (!ctx) {
+ if (!thr) {
return;
}
+ DUK_ASSERT_API_ENTRY(thr);
heap = thr->heap;
DUK_ASSERT(heap != NULL);
duk_heap_free(heap);
}
-DUK_EXTERNAL void duk_suspend(duk_context *ctx, duk_thread_state *state) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_suspend(duk_hthread *thr, duk_thread_state *state) {
duk_internal_thread_state *snapshot = (duk_internal_thread_state *) (void *) state;
duk_heap *heap;
duk_ljstate *lj;
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_ASSERT(thr != NULL);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(thr->heap != NULL);
DUK_ASSERT(state != NULL); /* unvalidated */
@@ -15528,8 +15815,8 @@ DUK_EXTERNAL void duk_suspend(duk_context *ctx, duk_thread_state *state) {
heap = thr->heap;
lj = &heap->lj;
- duk_push_tval(ctx, &lj->value1);
- duk_push_tval(ctx, &lj->value2);
+ duk_push_tval(thr, &lj->value1);
+ duk_push_tval(thr, &lj->value2);
/* XXX: creating_error == 0 is asserted above, so no need to store. */
DUK_MEMCPY((void *) &snapshot->lj, (const void *) lj, sizeof(duk_ljstate));
@@ -15546,13 +15833,11 @@ DUK_EXTERNAL void duk_suspend(duk_context *ctx, duk_thread_state *state) {
heap->call_recursion_depth = 0;
}
-DUK_EXTERNAL void duk_resume(duk_context *ctx, const duk_thread_state *state) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_resume(duk_hthread *thr, const duk_thread_state *state) {
const duk_internal_thread_state *snapshot = (const duk_internal_thread_state *) (const void *) state;
duk_heap *heap;
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_ASSERT(thr != NULL);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(thr->heap != NULL);
DUK_ASSERT(state != NULL); /* unvalidated */
@@ -15569,20 +15854,21 @@ DUK_EXTERNAL void duk_resume(duk_context *ctx, const duk_thread_state *state) {
heap->curr_thread = snapshot->curr_thread;
heap->call_recursion_depth = snapshot->call_recursion_depth;
- duk_pop_2(ctx);
+ duk_pop_2(thr);
}
/* XXX: better place for this */
-DUK_EXTERNAL void duk_set_global_object(duk_context *ctx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_set_global_object(duk_hthread *thr) {
duk_hobject *h_glob;
duk_hobject *h_prev_glob;
duk_hobjenv *h_env;
duk_hobject *h_prev_env;
- DUK_D(DUK_DPRINT("replace global object with: %!T", duk_get_tval(ctx, -1)));
+ DUK_ASSERT_API_ENTRY(thr);
+
+ DUK_D(DUK_DPRINT("replace global object with: %!T", duk_get_tval(thr, -1)));
- h_glob = duk_require_hobject(ctx, -1);
+ h_glob = duk_require_hobject(thr, -1);
DUK_ASSERT(h_glob != NULL);
/*
@@ -15627,7 +15913,7 @@ DUK_EXTERNAL void duk_set_global_object(duk_context *ctx) {
/* [ ... new_glob ] */
- duk_pop(ctx);
+ duk_pop(thr);
/* [ ... ] */
}
@@ -15640,7 +15926,7 @@ DUK_EXTERNAL void duk_set_global_object(duk_context *ctx) {
/* For footprint efficient multiple value setting: arrays are much better than
* varargs, format string with parsing is often better than string pointer arrays.
*/
-DUK_LOCAL void duk__inspect_multiple_uint(duk_context *ctx, const char *fmt, duk_int_t *vals) {
+DUK_LOCAL void duk__inspect_multiple_uint(duk_hthread *thr, const char *fmt, duk_int_t *vals) {
duk_int_t val;
const char *p;
const char *p_curr;
@@ -15657,9 +15943,9 @@ DUK_LOCAL void duk__inspect_multiple_uint(duk_context *ctx, const char *fmt, duk
val = *vals++;
if (val >= 0) {
/* Negative values are markers to skip key. */
- duk_push_string(ctx, p_curr);
- duk_push_uint(ctx, val);
- duk_put_prop(ctx, -3);
+ duk_push_string(thr, p_curr);
+ duk_push_int(thr, val);
+ duk_put_prop(thr, -3);
}
}
}
@@ -15687,8 +15973,7 @@ DUK_LOCAL void duk__inspect_multiple_uint(duk_context *ctx, const char *fmt, duk
#define DUK__IDX_TSTATE 12
#define DUK__IDX_VARIANT 13
-DUK_EXTERNAL void duk_inspect_value(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_inspect_value(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
duk_heaphdr *h;
/* The temporary values should be in an array rather than individual
@@ -15697,31 +15982,31 @@ DUK_EXTERNAL void duk_inspect_value(duk_context *ctx, duk_idx_t idx) {
*/
duk_int_t vals[14];
- DUK_UNREF(thr);
+ DUK_ASSERT_API_ENTRY(thr);
/* Assume two's complement and set everything to -1. */
DUK_MEMSET((void *) &vals, (int) 0xff, sizeof(vals));
DUK_ASSERT(vals[DUK__IDX_TYPE] == -1); /* spot check one */
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
h = (DUK_TVAL_IS_HEAP_ALLOCATED(tv) ? DUK_TVAL_GET_HEAPHDR(tv) : NULL);
vals[DUK__IDX_TYPE] = duk_get_type_tval(tv);
- vals[DUK__IDX_ITAG] = (duk_uint_t) DUK_TVAL_GET_TAG(tv);
+ vals[DUK__IDX_ITAG] = (duk_int_t) DUK_TVAL_GET_TAG(tv);
- duk_push_bare_object(ctx); /* Invalidates 'tv'. */
+ duk_push_bare_object(thr); /* Invalidates 'tv'. */
tv = NULL;
if (h == NULL) {
goto finish;
}
- duk_push_pointer(ctx, (void *) h);
- duk_put_prop_string(ctx, -2, "hptr");
+ duk_push_pointer(thr, (void *) h);
+ duk_put_prop_string(thr, -2, "hptr");
#if 0
/* Covers a lot of information, e.g. buffer and string variants. */
- duk_push_uint(ctx, (duk_uint_t) DUK_HEAPHDR_GET_FLAGS(h));
- duk_put_prop_string(ctx, -2, "hflags");
+ duk_push_uint(thr, (duk_uint_t) DUK_HEAPHDR_GET_FLAGS(h));
+ duk_put_prop_string(thr, -2, "hflags");
#endif
#if defined(DUK_USE_REFERENCE_COUNTING)
@@ -15800,62 +16085,61 @@ DUK_EXTERNAL void duk_inspect_value(duk_context *ctx, duk_idx_t idx) {
vals[DUK__IDX_VARIANT] = 1; /* buffer variant 1: dynamic */
vals[DUK__IDX_HBYTES] = (duk_uint_t) (sizeof(duk_hbuffer_dynamic));
}
- vals[DUK__IDX_DBYTES] = (duk_uint_t) (DUK_HBUFFER_GET_SIZE(h_buf));
+ vals[DUK__IDX_DBYTES] = (duk_int_t) (DUK_HBUFFER_GET_SIZE(h_buf));
} else {
DUK_ASSERT(vals[DUK__IDX_VARIANT] == 0); /* buffer variant 0: fixed */
- vals[DUK__IDX_HBYTES] = (duk_uint_t) (sizeof(duk_hbuffer_fixed) + DUK_HBUFFER_GET_SIZE(h_buf));
+ vals[DUK__IDX_HBYTES] = (duk_int_t) (sizeof(duk_hbuffer_fixed) + DUK_HBUFFER_GET_SIZE(h_buf));
}
break;
}
}
finish:
- duk__inspect_multiple_uint(ctx,
+ duk__inspect_multiple_uint(thr,
"type" "\x00" "itag" "\x00" "refc" "\x00" "hbytes" "\x00" "class" "\x00"
"pbytes" "\x00" "esize" "\x00" "enext" "\x00" "asize" "\x00" "hsize" "\x00"
"bcbytes" "\x00" "dbytes" "\x00" "tstate" "\x00" "variant" "\x00" "\x00",
(duk_int_t *) &vals);
}
-DUK_EXTERNAL void duk_inspect_callstack_entry(duk_context *ctx, duk_int_t level) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_inspect_callstack_entry(duk_hthread *thr, duk_int_t level) {
duk_activation *act;
duk_uint_fast32_t pc;
duk_uint_fast32_t line;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- /* -1 = top callstack entry, callstack[callstack_top - 1]
- * -callstack_top = bottom callstack entry, callstack[0]
+ /* -1 = top callstack entry
+ * -2 = caller of level -1
+ * etc
*/
- if (level >= 0 || -level > (duk_int_t) thr->callstack_top) {
- duk_push_undefined(ctx);
+ act = duk_hthread_get_activation_for_level(thr, level);
+ if (act == NULL) {
+ duk_push_undefined(thr);
return;
}
- duk_push_bare_object(ctx);
- DUK_ASSERT(level >= -((duk_int_t) thr->callstack_top) && level <= -1);
+ duk_push_bare_object(thr);
- act = thr->callstack + thr->callstack_top + level;
/* Relevant PC is just before current one because PC is
* post-incremented. This should match what error augment
* code does.
*/
pc = duk_hthread_get_act_prev_pc(thr, act);
- duk_push_tval(ctx, &act->tv_func);
+ duk_push_tval(thr, &act->tv_func);
- duk_push_uint(ctx, (duk_uint_t) pc);
- duk_put_prop_stridx_short(ctx, -3, DUK_STRIDX_PC);
+ duk_push_uint(thr, (duk_uint_t) pc);
+ duk_put_prop_stridx_short(thr, -3, DUK_STRIDX_PC);
#if defined(DUK_USE_PC2LINE)
- line = duk_hobject_pc2line_query(ctx, -1, pc);
+ line = duk_hobject_pc2line_query(thr, -1, pc);
#else
line = 0;
#endif
- duk_push_uint(ctx, (duk_uint_t) line);
- duk_put_prop_stridx_short(ctx, -3, DUK_STRIDX_LINE_NUMBER);
+ duk_push_uint(thr, (duk_uint_t) line);
+ duk_put_prop_stridx_short(thr, -3, DUK_STRIDX_LINE_NUMBER);
- duk_put_prop_stridx_short(ctx, -2, DUK_STRIDX_LC_FUNCTION);
+ duk_put_prop_stridx_short(thr, -2, DUK_STRIDX_LC_FUNCTION);
/* Providing access to e.g. act->lex_env would be dangerous: these
* internal structures must never be accessible to the application.
* Duktape relies on them having consistent data, and this consistency
@@ -15884,50 +16168,38 @@ DUK_EXTERNAL void duk_inspect_callstack_entry(duk_context *ctx, duk_int_t level)
/* #include duk_internal.h -> already included */
-DUK_EXTERNAL void *duk_alloc_raw(duk_context *ctx, duk_size_t size) {
- duk_hthread *thr = (duk_hthread *) ctx;
-
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL void *duk_alloc_raw(duk_hthread *thr, duk_size_t size) {
+ DUK_ASSERT_API_ENTRY(thr);
return DUK_ALLOC_RAW(thr->heap, size);
}
-DUK_EXTERNAL void duk_free_raw(duk_context *ctx, void *ptr) {
- duk_hthread *thr = (duk_hthread *) ctx;
-
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL void duk_free_raw(duk_hthread *thr, void *ptr) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_FREE_RAW(thr->heap, ptr);
}
-DUK_EXTERNAL void *duk_realloc_raw(duk_context *ctx, void *ptr, duk_size_t size) {
- duk_hthread *thr = (duk_hthread *) ctx;
-
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL void *duk_realloc_raw(duk_hthread *thr, void *ptr, duk_size_t size) {
+ DUK_ASSERT_API_ENTRY(thr);
return DUK_REALLOC_RAW(thr->heap, ptr, size);
}
-DUK_EXTERNAL void *duk_alloc(duk_context *ctx, duk_size_t size) {
- duk_hthread *thr = (duk_hthread *) ctx;
-
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL void *duk_alloc(duk_hthread *thr, duk_size_t size) {
+ DUK_ASSERT_API_ENTRY(thr);
return DUK_ALLOC(thr->heap, size);
}
-DUK_EXTERNAL void duk_free(duk_context *ctx, void *ptr) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_free(duk_hthread *thr, void *ptr) {
+ DUK_ASSERT_API_ENTRY(thr);
- DUK_ASSERT_CTX_VALID(ctx);
-
- DUK_FREE(thr->heap, ptr);
+ DUK_FREE_CHECKED(thr, ptr);
}
-DUK_EXTERNAL void *duk_realloc(duk_context *ctx, void *ptr, duk_size_t size) {
- duk_hthread *thr = (duk_hthread *) ctx;
-
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL void *duk_realloc(duk_hthread *thr, void *ptr, duk_size_t size) {
+ DUK_ASSERT_API_ENTRY(thr);
/*
* Note: since this is an exposed API call, there should be
@@ -15942,11 +16214,10 @@ DUK_EXTERNAL void *duk_realloc(duk_context *ctx, void *ptr, duk_size_t size) {
return DUK_REALLOC(thr->heap, ptr, size);
}
-DUK_EXTERNAL void duk_get_memory_functions(duk_context *ctx, duk_memory_functions *out_funcs) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_get_memory_functions(duk_hthread *thr, duk_memory_functions *out_funcs) {
duk_heap *heap;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(out_funcs != NULL);
DUK_ASSERT(thr != NULL);
DUK_ASSERT(thr->heap != NULL);
@@ -15958,12 +16229,11 @@ DUK_EXTERNAL void duk_get_memory_functions(duk_context *ctx, duk_memory_function
out_funcs->udata = heap->heap_udata;
}
-DUK_EXTERNAL void duk_gc(duk_context *ctx, duk_uint_t flags) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_gc(duk_hthread *thr, duk_uint_t flags) {
duk_heap *heap;
duk_small_uint_t ms_flags;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
heap = thr->heap;
DUK_ASSERT(heap != NULL);
@@ -15986,94 +16256,98 @@ DUK_EXTERNAL void duk_gc(duk_context *ctx, duk_uint_t flags) {
* defineProperty, getOwnPropertyDescriptor).
*/
-DUK_EXTERNAL duk_bool_t duk_get_prop(duk_context *ctx, duk_idx_t obj_idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_bool_t duk_get_prop(duk_hthread *thr, duk_idx_t obj_idx) {
duk_tval *tv_obj;
duk_tval *tv_key;
duk_bool_t rc;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
/* Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property get right now.
*/
- tv_obj = duk_require_tval(ctx, obj_idx);
- tv_key = duk_require_tval(ctx, -1);
+ tv_obj = duk_require_tval(thr, obj_idx);
+ tv_key = duk_require_tval(thr, -1);
rc = duk_hobject_getprop(thr, tv_obj, tv_key);
DUK_ASSERT(rc == 0 || rc == 1);
/* a value is left on stack regardless of rc */
- duk_remove_m2(ctx); /* remove key */
+ duk_remove_m2(thr); /* remove key */
+ DUK_ASSERT(duk_is_undefined(thr, -1) || rc == 1);
return rc; /* 1 if property found, 0 otherwise */
}
-DUK_EXTERNAL duk_bool_t duk_get_prop_string(duk_context *ctx, duk_idx_t obj_idx, const char *key) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_bool_t duk_get_prop_string(duk_hthread *thr, duk_idx_t obj_idx, const char *key) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(key != NULL);
- obj_idx = duk_require_normalize_index(ctx, obj_idx);
- duk_push_string(ctx, key);
- return duk_get_prop(ctx, obj_idx);
+ obj_idx = duk_require_normalize_index(thr, obj_idx);
+ duk_push_string(thr, key);
+ return duk_get_prop(thr, obj_idx);
}
-DUK_EXTERNAL duk_bool_t duk_get_prop_lstring(duk_context *ctx, duk_idx_t obj_idx, const char *key, duk_size_t key_len) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_bool_t duk_get_prop_lstring(duk_hthread *thr, duk_idx_t obj_idx, const char *key, duk_size_t key_len) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(key != NULL);
- obj_idx = duk_require_normalize_index(ctx, obj_idx);
- duk_push_lstring(ctx, key, key_len);
- return duk_get_prop(ctx, obj_idx);
+ obj_idx = duk_require_normalize_index(thr, obj_idx);
+ duk_push_lstring(thr, key, key_len);
+ return duk_get_prop(thr, obj_idx);
}
-DUK_EXTERNAL duk_bool_t duk_get_prop_index(duk_context *ctx, duk_idx_t obj_idx, duk_uarridx_t arr_idx) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_bool_t duk_get_prop_index(duk_hthread *thr, duk_idx_t obj_idx, duk_uarridx_t arr_idx) {
+ DUK_ASSERT_API_ENTRY(thr);
- obj_idx = duk_require_normalize_index(ctx, obj_idx);
- duk_push_uarridx(ctx, arr_idx);
- return duk_get_prop(ctx, obj_idx);
+ obj_idx = duk_require_normalize_index(thr, obj_idx);
+ duk_push_uarridx(thr, arr_idx);
+ return duk_get_prop(thr, obj_idx);
}
-DUK_INTERNAL duk_bool_t duk_get_prop_stridx(duk_context *ctx, duk_idx_t obj_idx, duk_small_uint_t stridx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_bool_t duk_get_prop_heapptr(duk_hthread *thr, duk_idx_t obj_idx, void *ptr) {
+ DUK_ASSERT_API_ENTRY(thr);
- DUK_ASSERT_CTX_VALID(ctx);
+ obj_idx = duk_require_normalize_index(thr, obj_idx);
+ duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */
+ return duk_get_prop(thr, obj_idx);
+}
+
+DUK_INTERNAL duk_bool_t duk_get_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT_STRIDX_VALID(stridx);
- DUK_UNREF(thr);
- obj_idx = duk_require_normalize_index(ctx, obj_idx);
- duk_push_hstring(ctx, DUK_HTHREAD_GET_STRING(thr, stridx));
- return duk_get_prop(ctx, obj_idx);
+ obj_idx = duk_require_normalize_index(thr, obj_idx);
+ duk_push_hstring(thr, DUK_HTHREAD_GET_STRING(thr, stridx));
+ return duk_get_prop(thr, obj_idx);
}
-DUK_INTERNAL duk_bool_t duk_get_prop_stridx_short_raw(duk_context *ctx, duk_uint_t packed_args) {
- return duk_get_prop_stridx(ctx, (duk_idx_t) (duk_int16_t) (packed_args >> 16),
+DUK_INTERNAL duk_bool_t duk_get_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args) {
+ return duk_get_prop_stridx(thr, (duk_idx_t) (duk_int16_t) (packed_args >> 16),
(duk_small_uint_t) (packed_args & 0xffffUL));
}
-DUK_INTERNAL duk_bool_t duk_get_prop_stridx_boolean(duk_context *ctx, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_bool_t *out_has_prop) {
+DUK_INTERNAL duk_bool_t duk_get_prop_stridx_boolean(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_bool_t *out_has_prop) {
duk_bool_t rc;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT_STRIDX_VALID(stridx);
- rc = duk_get_prop_stridx(ctx, obj_idx, stridx);
+ rc = duk_get_prop_stridx(thr, obj_idx, stridx);
if (out_has_prop) {
*out_has_prop = rc;
}
- rc = duk_to_boolean(ctx, -1);
+ rc = duk_to_boolean(thr, -1);
DUK_ASSERT(rc == 0 || rc == 1);
- duk_pop(ctx);
+ duk_pop(thr);
return rc;
}
-DUK_LOCAL duk_bool_t duk__put_prop_shared(duk_context *ctx, duk_idx_t obj_idx, duk_idx_t idx_key) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_LOCAL duk_bool_t duk__put_prop_shared(duk_hthread *thr, duk_idx_t obj_idx, duk_idx_t idx_key) {
duk_tval *tv_obj;
duk_tval *tv_key;
duk_tval *tv_val;
- duk_small_int_t throw_flag;
+ duk_bool_t throw_flag;
duk_bool_t rc;
/* Note: copying tv_obj and tv_key to locals to shield against a valstack
@@ -16087,202 +16361,216 @@ DUK_LOCAL duk_bool_t duk__put_prop_shared(duk_context *ctx, duk_idx_t obj_idx, d
DUK_ASSERT((idx_key == -2 && (idx_key ^ 1) == -1) ||
(idx_key == -1 && (idx_key ^ 1) == -2));
/* XXX: Direct access; faster validation. */
- tv_obj = duk_require_tval(ctx, obj_idx);
- tv_key = duk_require_tval(ctx, idx_key);
- tv_val = duk_require_tval(ctx, idx_key ^ 1);
- throw_flag = duk_is_strict_call(ctx);
+ tv_obj = duk_require_tval(thr, obj_idx);
+ tv_key = duk_require_tval(thr, idx_key);
+ tv_val = duk_require_tval(thr, idx_key ^ 1);
+ throw_flag = duk_is_strict_call(thr);
rc = duk_hobject_putprop(thr, tv_obj, tv_key, tv_val, throw_flag);
DUK_ASSERT(rc == 0 || rc == 1);
- duk_pop_2(ctx); /* remove key and value */
+ duk_pop_2(thr); /* remove key and value */
return rc; /* 1 if property found, 0 otherwise */
}
-DUK_EXTERNAL duk_bool_t duk_put_prop(duk_context *ctx, duk_idx_t obj_idx) {
- DUK_ASSERT_CTX_VALID(ctx);
- return duk__put_prop_shared(ctx, obj_idx, -2);
+DUK_EXTERNAL duk_bool_t duk_put_prop(duk_hthread *thr, duk_idx_t obj_idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk__put_prop_shared(thr, obj_idx, -2);
}
-DUK_EXTERNAL duk_bool_t duk_put_prop_string(duk_context *ctx, duk_idx_t obj_idx, const char *key) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_bool_t duk_put_prop_string(duk_hthread *thr, duk_idx_t obj_idx, const char *key) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(key != NULL);
/* Careful here and with other duk_put_prop_xxx() helpers: the
* target object and the property value may be in the same value
* stack slot (unusual, but still conceptually clear).
*/
- obj_idx = duk_normalize_index(ctx, obj_idx);
- (void) duk_push_string(ctx, key);
- return duk__put_prop_shared(ctx, obj_idx, -1);
+ obj_idx = duk_normalize_index(thr, obj_idx);
+ (void) duk_push_string(thr, key);
+ return duk__put_prop_shared(thr, obj_idx, -1);
}
-DUK_EXTERNAL duk_bool_t duk_put_prop_lstring(duk_context *ctx, duk_idx_t obj_idx, const char *key, duk_size_t key_len) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_bool_t duk_put_prop_lstring(duk_hthread *thr, duk_idx_t obj_idx, const char *key, duk_size_t key_len) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(key != NULL);
- obj_idx = duk_normalize_index(ctx, obj_idx);
- (void) duk_push_lstring(ctx, key, key_len);
- return duk__put_prop_shared(ctx, obj_idx, -1);
+ obj_idx = duk_normalize_index(thr, obj_idx);
+ (void) duk_push_lstring(thr, key, key_len);
+ return duk__put_prop_shared(thr, obj_idx, -1);
}
-DUK_EXTERNAL duk_bool_t duk_put_prop_index(duk_context *ctx, duk_idx_t obj_idx, duk_uarridx_t arr_idx) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_bool_t duk_put_prop_index(duk_hthread *thr, duk_idx_t obj_idx, duk_uarridx_t arr_idx) {
+ DUK_ASSERT_API_ENTRY(thr);
- obj_idx = duk_require_normalize_index(ctx, obj_idx);
- duk_push_uarridx(ctx, arr_idx);
- return duk__put_prop_shared(ctx, obj_idx, -1);
+ obj_idx = duk_require_normalize_index(thr, obj_idx);
+ duk_push_uarridx(thr, arr_idx);
+ return duk__put_prop_shared(thr, obj_idx, -1);
}
-DUK_INTERNAL duk_bool_t duk_put_prop_stridx(duk_context *ctx, duk_idx_t obj_idx, duk_small_uint_t stridx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_bool_t duk_put_prop_heapptr(duk_hthread *thr, duk_idx_t obj_idx, void *ptr) {
+ DUK_ASSERT_API_ENTRY(thr);
+
+ obj_idx = duk_require_normalize_index(thr, obj_idx);
+ duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */
+ return duk__put_prop_shared(thr, obj_idx, -1);
+}
- DUK_ASSERT_CTX_VALID(ctx);
+
+DUK_INTERNAL duk_bool_t duk_put_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT_STRIDX_VALID(stridx);
- DUK_UNREF(thr);
- obj_idx = duk_require_normalize_index(ctx, obj_idx);
- duk_push_hstring(ctx, DUK_HTHREAD_GET_STRING(thr, stridx));
- return duk__put_prop_shared(ctx, obj_idx, -1);
+ obj_idx = duk_require_normalize_index(thr, obj_idx);
+ duk_push_hstring(thr, DUK_HTHREAD_GET_STRING(thr, stridx));
+ return duk__put_prop_shared(thr, obj_idx, -1);
}
-DUK_INTERNAL duk_bool_t duk_put_prop_stridx_short_raw(duk_context *ctx, duk_uint_t packed_args) {
- return duk_put_prop_stridx(ctx, (duk_idx_t) (duk_int16_t) (packed_args >> 16),
+DUK_INTERNAL duk_bool_t duk_put_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args) {
+ return duk_put_prop_stridx(thr, (duk_idx_t) (duk_int16_t) (packed_args >> 16),
(duk_small_uint_t) (packed_args & 0xffffUL));
}
-DUK_EXTERNAL duk_bool_t duk_del_prop(duk_context *ctx, duk_idx_t obj_idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_bool_t duk_del_prop(duk_hthread *thr, duk_idx_t obj_idx) {
duk_tval *tv_obj;
duk_tval *tv_key;
- duk_small_int_t throw_flag;
+ duk_bool_t throw_flag;
duk_bool_t rc;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
/* Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property delete right now.
*/
- tv_obj = duk_require_tval(ctx, obj_idx);
- tv_key = duk_require_tval(ctx, -1);
- throw_flag = duk_is_strict_call(ctx);
+ tv_obj = duk_require_tval(thr, obj_idx);
+ tv_key = duk_require_tval(thr, -1);
+ throw_flag = duk_is_strict_call(thr);
rc = duk_hobject_delprop(thr, tv_obj, tv_key, throw_flag);
DUK_ASSERT(rc == 0 || rc == 1);
- duk_pop(ctx); /* remove key */
+ duk_pop(thr); /* remove key */
return rc;
}
-DUK_EXTERNAL duk_bool_t duk_del_prop_string(duk_context *ctx, duk_idx_t obj_idx, const char *key) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_bool_t duk_del_prop_string(duk_hthread *thr, duk_idx_t obj_idx, const char *key) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(key != NULL);
- obj_idx = duk_require_normalize_index(ctx, obj_idx);
- duk_push_string(ctx, key);
- return duk_del_prop(ctx, obj_idx);
+ obj_idx = duk_require_normalize_index(thr, obj_idx);
+ duk_push_string(thr, key);
+ return duk_del_prop(thr, obj_idx);
}
-DUK_EXTERNAL duk_bool_t duk_del_prop_lstring(duk_context *ctx, duk_idx_t obj_idx, const char *key, duk_size_t key_len) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_bool_t duk_del_prop_lstring(duk_hthread *thr, duk_idx_t obj_idx, const char *key, duk_size_t key_len) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(key != NULL);
- obj_idx = duk_require_normalize_index(ctx, obj_idx);
- duk_push_lstring(ctx, key, key_len);
- return duk_del_prop(ctx, obj_idx);
+ obj_idx = duk_require_normalize_index(thr, obj_idx);
+ duk_push_lstring(thr, key, key_len);
+ return duk_del_prop(thr, obj_idx);
}
-DUK_EXTERNAL duk_bool_t duk_del_prop_index(duk_context *ctx, duk_idx_t obj_idx, duk_uarridx_t arr_idx) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_bool_t duk_del_prop_index(duk_hthread *thr, duk_idx_t obj_idx, duk_uarridx_t arr_idx) {
+ DUK_ASSERT_API_ENTRY(thr);
- obj_idx = duk_require_normalize_index(ctx, obj_idx);
- duk_push_uarridx(ctx, arr_idx);
- return duk_del_prop(ctx, obj_idx);
+ obj_idx = duk_require_normalize_index(thr, obj_idx);
+ duk_push_uarridx(thr, arr_idx);
+ return duk_del_prop(thr, obj_idx);
}
-DUK_INTERNAL duk_bool_t duk_del_prop_stridx(duk_context *ctx, duk_idx_t obj_idx, duk_small_uint_t stridx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_bool_t duk_del_prop_heapptr(duk_hthread *thr, duk_idx_t obj_idx, void *ptr) {
+ DUK_ASSERT_API_ENTRY(thr);
- DUK_ASSERT_CTX_VALID(ctx);
+ obj_idx = duk_require_normalize_index(thr, obj_idx);
+ duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */
+ return duk_del_prop(thr, obj_idx);
+}
+
+DUK_INTERNAL duk_bool_t duk_del_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT_STRIDX_VALID(stridx);
- DUK_UNREF(thr);
- obj_idx = duk_require_normalize_index(ctx, obj_idx);
- duk_push_hstring(ctx, DUK_HTHREAD_GET_STRING(thr, stridx));
- return duk_del_prop(ctx, obj_idx);
+ obj_idx = duk_require_normalize_index(thr, obj_idx);
+ duk_push_hstring(thr, DUK_HTHREAD_GET_STRING(thr, stridx));
+ return duk_del_prop(thr, obj_idx);
}
#if 0
-DUK_INTERNAL duk_bool_t duk_del_prop_stridx_short_raw(duk_context *ctx, duk_uint_t packed_args) {
- return duk_del_prop_stridx(ctx, (duk_idx_t) (duk_int16_t) (packed_args >> 16),
+DUK_INTERNAL duk_bool_t duk_del_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args) {
+ return duk_del_prop_stridx(thr, (duk_idx_t) (duk_int16_t) (packed_args >> 16),
(duk_small_uint_t) (packed_args & 0xffffUL));
}
#endif
-DUK_EXTERNAL duk_bool_t duk_has_prop(duk_context *ctx, duk_idx_t obj_idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_bool_t duk_has_prop(duk_hthread *thr, duk_idx_t obj_idx) {
duk_tval *tv_obj;
duk_tval *tv_key;
duk_bool_t rc;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
/* Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property existence check right now.
*/
- tv_obj = duk_require_tval(ctx, obj_idx);
- tv_key = duk_require_tval(ctx, -1);
+ tv_obj = duk_require_tval(thr, obj_idx);
+ tv_key = duk_require_tval(thr, -1);
rc = duk_hobject_hasprop(thr, tv_obj, tv_key);
DUK_ASSERT(rc == 0 || rc == 1);
- duk_pop(ctx); /* remove key */
+ duk_pop(thr); /* remove key */
return rc; /* 1 if property found, 0 otherwise */
}
-DUK_EXTERNAL duk_bool_t duk_has_prop_string(duk_context *ctx, duk_idx_t obj_idx, const char *key) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_bool_t duk_has_prop_string(duk_hthread *thr, duk_idx_t obj_idx, const char *key) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(key != NULL);
- obj_idx = duk_require_normalize_index(ctx, obj_idx);
- duk_push_string(ctx, key);
- return duk_has_prop(ctx, obj_idx);
+ obj_idx = duk_require_normalize_index(thr, obj_idx);
+ duk_push_string(thr, key);
+ return duk_has_prop(thr, obj_idx);
}
-DUK_EXTERNAL duk_bool_t duk_has_prop_lstring(duk_context *ctx, duk_idx_t obj_idx, const char *key, duk_size_t key_len) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_bool_t duk_has_prop_lstring(duk_hthread *thr, duk_idx_t obj_idx, const char *key, duk_size_t key_len) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(key != NULL);
- obj_idx = duk_require_normalize_index(ctx, obj_idx);
- duk_push_lstring(ctx, key, key_len);
- return duk_has_prop(ctx, obj_idx);
+ obj_idx = duk_require_normalize_index(thr, obj_idx);
+ duk_push_lstring(thr, key, key_len);
+ return duk_has_prop(thr, obj_idx);
}
-DUK_EXTERNAL duk_bool_t duk_has_prop_index(duk_context *ctx, duk_idx_t obj_idx, duk_uarridx_t arr_idx) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_bool_t duk_has_prop_index(duk_hthread *thr, duk_idx_t obj_idx, duk_uarridx_t arr_idx) {
+ DUK_ASSERT_API_ENTRY(thr);
- obj_idx = duk_require_normalize_index(ctx, obj_idx);
- duk_push_uarridx(ctx, arr_idx);
- return duk_has_prop(ctx, obj_idx);
+ obj_idx = duk_require_normalize_index(thr, obj_idx);
+ duk_push_uarridx(thr, arr_idx);
+ return duk_has_prop(thr, obj_idx);
}
-DUK_INTERNAL duk_bool_t duk_has_prop_stridx(duk_context *ctx, duk_idx_t obj_idx, duk_small_uint_t stridx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_bool_t duk_has_prop_heapptr(duk_hthread *thr, duk_idx_t obj_idx, void *ptr) {
+ DUK_ASSERT_API_ENTRY(thr);
- DUK_ASSERT_CTX_VALID(ctx);
+ obj_idx = duk_require_normalize_index(thr, obj_idx);
+ duk_push_heapptr(thr, ptr); /* NULL -> 'undefined' */
+ return duk_has_prop(thr, obj_idx);
+}
+
+DUK_INTERNAL duk_bool_t duk_has_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT_STRIDX_VALID(stridx);
- DUK_UNREF(thr);
- obj_idx = duk_require_normalize_index(ctx, obj_idx);
- duk_push_hstring(ctx, DUK_HTHREAD_GET_STRING(thr, stridx));
- return duk_has_prop(ctx, obj_idx);
+ obj_idx = duk_require_normalize_index(thr, obj_idx);
+ duk_push_hstring(thr, DUK_HTHREAD_GET_STRING(thr, stridx));
+ return duk_has_prop(thr, obj_idx);
}
#if 0
-DUK_INTERNAL duk_bool_t duk_has_prop_stridx_short_raw(duk_context *ctx, duk_uint_t packed_args) {
- return duk_has_prop_stridx(ctx, (duk_idx_t) (duk_int16_t) (packed_args >> 16),
+DUK_INTERNAL duk_bool_t duk_has_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args) {
+ return duk_has_prop_stridx(thr, (duk_idx_t) (duk_int16_t) (packed_args >> 16),
(duk_small_uint_t) (packed_args & 0xffffUL));
}
#endif
@@ -16292,103 +16580,103 @@ DUK_INTERNAL duk_bool_t duk_has_prop_stridx_short_raw(duk_context *ctx, duk_uint
* not invoked by this method. The caller must be careful to invoke any such
* behaviors if necessary.
*/
-DUK_INTERNAL void duk_xdef_prop(duk_context *ctx, duk_idx_t obj_idx, duk_small_uint_t desc_flags) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_INTERNAL void duk_xdef_prop(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t desc_flags) {
duk_hobject *obj;
duk_hstring *key;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- obj = duk_require_hobject(ctx, obj_idx);
+ obj = duk_require_hobject(thr, obj_idx);
DUK_ASSERT(obj != NULL);
- key = duk_to_property_key_hstring(ctx, -2);
+ key = duk_to_property_key_hstring(thr, -2);
DUK_ASSERT(key != NULL);
- DUK_ASSERT(duk_require_tval(ctx, -1) != NULL);
+ DUK_ASSERT(duk_require_tval(thr, -1) != NULL);
duk_hobject_define_property_internal(thr, obj, key, desc_flags);
- duk_pop(ctx); /* pop key */
+ duk_pop(thr); /* pop key */
}
-DUK_INTERNAL void duk_xdef_prop_index(duk_context *ctx, duk_idx_t obj_idx, duk_uarridx_t arr_idx, duk_small_uint_t desc_flags) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_INTERNAL void duk_xdef_prop_index(duk_hthread *thr, duk_idx_t obj_idx, duk_uarridx_t arr_idx, duk_small_uint_t desc_flags) {
duk_hobject *obj;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- obj = duk_require_hobject(ctx, obj_idx);
+ obj = duk_require_hobject(thr, obj_idx);
DUK_ASSERT(obj != NULL);
duk_hobject_define_property_internal_arridx(thr, obj, arr_idx, desc_flags);
/* value popped by call */
}
-DUK_INTERNAL void duk_xdef_prop_stridx(duk_context *ctx, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_small_uint_t desc_flags) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_INTERNAL void duk_xdef_prop_stridx(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_small_uint_t desc_flags) {
duk_hobject *obj;
duk_hstring *key;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT_STRIDX_VALID(stridx);
- obj = duk_require_hobject(ctx, obj_idx);
+ obj = duk_require_hobject(thr, obj_idx);
DUK_ASSERT(obj != NULL);
key = DUK_HTHREAD_GET_STRING(thr, stridx);
DUK_ASSERT(key != NULL);
- DUK_ASSERT(duk_require_tval(ctx, -1) != NULL);
+ DUK_ASSERT(duk_require_tval(thr, -1) != NULL);
duk_hobject_define_property_internal(thr, obj, key, desc_flags);
/* value popped by call */
}
-DUK_INTERNAL void duk_xdef_prop_stridx_short_raw(duk_context *ctx, duk_uint_t packed_args) {
- duk_xdef_prop_stridx(ctx, (duk_idx_t) (duk_int8_t) (packed_args >> 24),
+DUK_INTERNAL void duk_xdef_prop_stridx_short_raw(duk_hthread *thr, duk_uint_t packed_args) {
+ duk_xdef_prop_stridx(thr, (duk_idx_t) (duk_int8_t) (packed_args >> 24),
(duk_small_uint_t) (packed_args >> 8) & 0xffffUL,
(duk_small_uint_t) (packed_args & 0xffL));
}
-DUK_INTERNAL void duk_xdef_prop_stridx_builtin(duk_context *ctx, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_small_int_t builtin_idx, duk_small_uint_t desc_flags) {
- duk_hthread *thr = (duk_hthread *) ctx;
+#if 0 /*unused*/
+DUK_INTERNAL void duk_xdef_prop_stridx_builtin(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx, duk_small_int_t builtin_idx, duk_small_uint_t desc_flags) {
duk_hobject *obj;
duk_hstring *key;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT_STRIDX_VALID(stridx);
DUK_ASSERT_BIDX_VALID(builtin_idx);
- obj = duk_require_hobject(ctx, obj_idx);
+ obj = duk_require_hobject(thr, obj_idx);
DUK_ASSERT(obj != NULL);
key = DUK_HTHREAD_GET_STRING(thr, stridx);
DUK_ASSERT(key != NULL);
- duk_push_hobject(ctx, thr->builtins[builtin_idx]);
+ duk_push_hobject(thr, thr->builtins[builtin_idx]);
duk_hobject_define_property_internal(thr, obj, key, desc_flags);
/* value popped by call */
}
+#endif
/* This is a rare property helper; it sets the global thrower (E5 Section 13.2.3)
* setter/getter into an object property. This is needed by the 'arguments'
* object creation code, function instance creation code, and Function.prototype.bind().
*/
-DUK_INTERNAL void duk_xdef_prop_stridx_thrower(duk_context *ctx, duk_idx_t obj_idx, duk_small_uint_t stridx) {
- obj_idx = duk_require_normalize_index(ctx, obj_idx);
- duk_push_hstring_stridx(ctx, stridx);
- duk_push_hobject_bidx(ctx, DUK_BIDX_TYPE_ERROR_THROWER);
- duk_dup_top(ctx);
- duk_def_prop(ctx, obj_idx, DUK_DEFPROP_HAVE_SETTER | DUK_DEFPROP_HAVE_GETTER | DUK_DEFPROP_FORCE); /* attributes always 0 */
+DUK_INTERNAL void duk_xdef_prop_stridx_thrower(duk_hthread *thr, duk_idx_t obj_idx, duk_small_uint_t stridx) {
+ DUK_ASSERT_API_ENTRY(thr);
+
+ obj_idx = duk_require_normalize_index(thr, obj_idx);
+ duk_push_hstring_stridx(thr, stridx);
+ duk_push_hobject_bidx(thr, DUK_BIDX_TYPE_ERROR_THROWER);
+ duk_dup_top(thr);
+ duk_def_prop(thr, obj_idx, DUK_DEFPROP_HAVE_SETTER | DUK_DEFPROP_HAVE_GETTER | DUK_DEFPROP_FORCE); /* attributes always 0 */
}
/* Object.getOwnPropertyDescriptor() equivalent C binding. */
-DUK_EXTERNAL void duk_get_prop_desc(duk_context *ctx, duk_idx_t obj_idx, duk_uint_t flags) {
+DUK_EXTERNAL void duk_get_prop_desc(duk_hthread *thr, duk_idx_t obj_idx, duk_uint_t flags) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_UNREF(flags); /* no flags defined yet */
- duk_hobject_object_get_own_property_descriptor(ctx, obj_idx); /* [ ... key ] -> [ ... desc ] */
+ duk_hobject_object_get_own_property_descriptor(thr, obj_idx); /* [ ... key ] -> [ ... desc ] */
}
/* Object.defineProperty() equivalent C binding. */
-DUK_EXTERNAL void duk_def_prop(duk_context *ctx, duk_idx_t obj_idx, duk_uint_t flags) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_def_prop(duk_hthread *thr, duk_idx_t obj_idx, duk_uint_t flags) {
duk_idx_t idx_base;
duk_hobject *obj;
duk_hstring *key;
@@ -16398,9 +16686,9 @@ DUK_EXTERNAL void duk_def_prop(duk_context *ctx, duk_idx_t obj_idx, duk_uint_t f
duk_uint_t is_data_desc;
duk_uint_t is_acc_desc;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- obj = duk_require_hobject(ctx, obj_idx);
+ obj = duk_require_hobject(thr, obj_idx);
is_data_desc = flags & (DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE);
is_acc_desc = flags & (DUK_DEFPROP_HAVE_GETTER | DUK_DEFPROP_HAVE_SETTER);
@@ -16412,12 +16700,12 @@ DUK_EXTERNAL void duk_def_prop(duk_context *ctx, duk_idx_t obj_idx, duk_uint_t f
goto fail_invalid_desc;
}
- idx_base = duk_get_top_index(ctx);
+ idx_base = duk_get_top_index(thr);
if (flags & DUK_DEFPROP_HAVE_SETTER) {
- duk_require_type_mask(ctx, idx_base, DUK_TYPE_MASK_UNDEFINED |
+ duk_require_type_mask(thr, idx_base, DUK_TYPE_MASK_UNDEFINED |
DUK_TYPE_MASK_OBJECT |
DUK_TYPE_MASK_LIGHTFUNC);
- set = duk_get_hobject_promote_lfunc(ctx, idx_base);
+ set = duk_get_hobject_promote_lfunc(thr, idx_base);
if (set != NULL && !DUK_HOBJECT_IS_CALLABLE(set)) {
goto fail_not_callable;
}
@@ -16426,10 +16714,10 @@ DUK_EXTERNAL void duk_def_prop(duk_context *ctx, duk_idx_t obj_idx, duk_uint_t f
set = NULL;
}
if (flags & DUK_DEFPROP_HAVE_GETTER) {
- duk_require_type_mask(ctx, idx_base, DUK_TYPE_MASK_UNDEFINED |
+ duk_require_type_mask(thr, idx_base, DUK_TYPE_MASK_UNDEFINED |
DUK_TYPE_MASK_OBJECT |
DUK_TYPE_MASK_LIGHTFUNC);
- get = duk_get_hobject_promote_lfunc(ctx, idx_base);
+ get = duk_get_hobject_promote_lfunc(thr, idx_base);
if (get != NULL && !DUK_HOBJECT_IS_CALLABLE(get)) {
goto fail_not_callable;
}
@@ -16443,12 +16731,12 @@ DUK_EXTERNAL void duk_def_prop(duk_context *ctx, duk_idx_t obj_idx, duk_uint_t f
} else {
idx_value = (duk_idx_t) -1;
}
- key = duk_to_property_key_hstring(ctx, idx_base);
+ key = duk_to_property_key_hstring(thr, idx_base);
DUK_ASSERT(key != NULL);
- duk_require_valid_index(ctx, idx_base);
+ duk_require_valid_index(thr, idx_base);
- duk_hobject_define_property_helper(ctx,
+ duk_hobject_define_property_helper(thr,
flags /*defprop_flags*/,
obj,
key,
@@ -16459,7 +16747,7 @@ DUK_EXTERNAL void duk_def_prop(duk_context *ctx, duk_idx_t obj_idx, duk_uint_t f
/* Clean up stack */
- duk_set_top(ctx, idx_base);
+ duk_set_top(thr, idx_base);
/* [ ... obj ... ] */
@@ -16481,73 +16769,140 @@ DUK_EXTERNAL void duk_def_prop(duk_context *ctx, duk_idx_t obj_idx, duk_uint_t f
* and are not exposed through the API.
*/
-DUK_EXTERNAL void duk_compact(duk_context *ctx, duk_idx_t obj_idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_compact(duk_hthread *thr, duk_idx_t obj_idx) {
duk_hobject *obj;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- obj = duk_get_hobject(ctx, obj_idx);
+ obj = duk_get_hobject(thr, obj_idx);
if (obj) {
/* Note: this may fail, caller should protect the call if necessary */
duk_hobject_compact_props(thr, obj);
}
}
-DUK_INTERNAL void duk_compact_m1(duk_context *ctx) {
- duk_compact(ctx, -1);
+DUK_INTERNAL void duk_compact_m1(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+
+ duk_compact(thr, -1);
}
/* XXX: the duk_hobject_enum.c stack APIs should be reworked */
-DUK_EXTERNAL void duk_enum(duk_context *ctx, duk_idx_t obj_idx, duk_uint_t enum_flags) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL void duk_enum(duk_hthread *thr, duk_idx_t obj_idx, duk_uint_t enum_flags) {
+ DUK_ASSERT_API_ENTRY(thr);
- duk_dup(ctx, obj_idx);
- duk_require_hobject_promote_mask(ctx, -1, DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER);
- duk_hobject_enumerator_create(ctx, enum_flags); /* [target] -> [enum] */
+ duk_dup(thr, obj_idx);
+ duk_require_hobject_promote_mask(thr, -1, DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER);
+ duk_hobject_enumerator_create(thr, enum_flags); /* [target] -> [enum] */
}
-DUK_EXTERNAL duk_bool_t duk_next(duk_context *ctx, duk_idx_t enum_index, duk_bool_t get_value) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_bool_t duk_next(duk_hthread *thr, duk_idx_t enum_index, duk_bool_t get_value) {
+ DUK_ASSERT_API_ENTRY(thr);
- duk_require_hobject(ctx, enum_index);
- duk_dup(ctx, enum_index);
- return duk_hobject_enumerator_next(ctx, get_value);
+ duk_require_hobject(thr, enum_index);
+ duk_dup(thr, enum_index);
+ return duk_hobject_enumerator_next(thr, get_value);
+}
+
+DUK_INTERNAL void duk_seal_freeze_raw(duk_hthread *thr, duk_idx_t obj_idx, duk_bool_t is_freeze) {
+ duk_tval *tv;
+ duk_hobject *h;
+
+ DUK_ASSERT_API_ENTRY(thr);
+
+ tv = duk_require_tval(thr, obj_idx);
+ DUK_ASSERT(tv != NULL);
+
+ /* Seal/freeze are quite rare in practice so it'd be nice to get the
+ * correct behavior simply via automatic promotion (at the cost of some
+ * memory churn). However, the promoted objects don't behave the same,
+ * e.g. promoted lightfuncs are extensible.
+ */
+
+ switch (DUK_TVAL_GET_TAG(tv)) {
+ case DUK_TAG_BUFFER:
+ /* Plain buffer: already sealed, but not frozen (and can't be frozen
+ * because index properties can't be made non-writable.
+ */
+ if (is_freeze) {
+ goto fail_cannot_freeze;
+ }
+ break;
+ case DUK_TAG_LIGHTFUNC:
+ /* Lightfunc: already sealed and frozen, success. */
+ break;
+ case DUK_TAG_OBJECT:
+ h = DUK_TVAL_GET_OBJECT(tv);
+ DUK_ASSERT(h != NULL);
+ if (is_freeze && DUK_HOBJECT_IS_BUFOBJ(h)) {
+ /* Buffer objects cannot be frozen because there's no internal
+ * support for making virtual array indices non-writable.
+ */
+ DUK_DD(DUK_DDPRINT("cannot freeze a buffer object"));
+ goto fail_cannot_freeze;
+ }
+ duk_hobject_object_seal_freeze_helper(thr, h, is_freeze);
+
+ /* Sealed and frozen objects cannot gain any more properties,
+ * so this is a good time to compact them.
+ */
+ duk_hobject_compact_props(thr, h);
+ break;
+ default:
+ /* ES2015 Sections 19.1.2.5, 19.1.2.17 */
+ break;
+ }
+ return;
+
+ fail_cannot_freeze:
+ DUK_ERROR_TYPE_INVALID_ARGS(thr); /* XXX: proper error message */
+}
+
+DUK_EXTERNAL void duk_seal(duk_hthread *thr, duk_idx_t obj_idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+
+ duk_seal_freeze_raw(thr, obj_idx, 0 /*is_freeze*/);
+}
+
+DUK_EXTERNAL void duk_freeze(duk_hthread *thr, duk_idx_t obj_idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+
+ duk_seal_freeze_raw(thr, obj_idx, 1 /*is_freeze*/);
}
/*
* Helpers for writing multiple properties
*/
-DUK_EXTERNAL void duk_put_function_list(duk_context *ctx, duk_idx_t obj_idx, const duk_function_list_entry *funcs) {
+DUK_EXTERNAL void duk_put_function_list(duk_hthread *thr, duk_idx_t obj_idx, const duk_function_list_entry *funcs) {
const duk_function_list_entry *ent = funcs;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- obj_idx = duk_require_normalize_index(ctx, obj_idx);
+ obj_idx = duk_require_normalize_index(thr, obj_idx);
if (ent != NULL) {
while (ent->key != NULL) {
- duk_push_c_function(ctx, ent->value, ent->nargs);
- duk_put_prop_string(ctx, obj_idx, ent->key);
+ duk_push_c_function(thr, ent->value, ent->nargs);
+ duk_put_prop_string(thr, obj_idx, ent->key);
ent++;
}
}
}
-DUK_EXTERNAL void duk_put_number_list(duk_context *ctx, duk_idx_t obj_idx, const duk_number_list_entry *numbers) {
+DUK_EXTERNAL void duk_put_number_list(duk_hthread *thr, duk_idx_t obj_idx, const duk_number_list_entry *numbers) {
const duk_number_list_entry *ent = numbers;
duk_tval *tv;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- obj_idx = duk_require_normalize_index(ctx, obj_idx);
+ obj_idx = duk_require_normalize_index(thr, obj_idx);
if (ent != NULL) {
while (ent->key != NULL) {
- tv = ((duk_hthread *) ctx)->valstack_top++;
+ tv = thr->valstack_top++;
DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(tv)); /* value stack init policy */
DUK_TVAL_SET_NUMBER_CHKFAST_SLOW(tv, ent->value); /* no need for decref/incref */
- duk_put_prop_string(ctx, obj_idx, ent->key);
+ duk_put_prop_string(thr, obj_idx, ent->key);
ent++;
}
}
@@ -16557,65 +16912,61 @@ DUK_EXTERNAL void duk_put_number_list(duk_context *ctx, duk_idx_t obj_idx, const
* Shortcut for accessing global object properties
*/
-DUK_EXTERNAL duk_bool_t duk_get_global_string(duk_context *ctx, const char *key) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_bool_t duk_get_global_string(duk_hthread *thr, const char *key) {
duk_bool_t ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(thr->builtins[DUK_BIDX_GLOBAL] != NULL);
/* XXX: direct implementation */
- duk_push_hobject(ctx, thr->builtins[DUK_BIDX_GLOBAL]);
- ret = duk_get_prop_string(ctx, -1, key);
- duk_remove_m2(ctx);
+ duk_push_hobject(thr, thr->builtins[DUK_BIDX_GLOBAL]);
+ ret = duk_get_prop_string(thr, -1, key);
+ duk_remove_m2(thr);
return ret;
}
-DUK_EXTERNAL duk_bool_t duk_get_global_lstring(duk_context *ctx, const char *key, duk_size_t key_len) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_bool_t duk_get_global_lstring(duk_hthread *thr, const char *key, duk_size_t key_len) {
duk_bool_t ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(thr->builtins[DUK_BIDX_GLOBAL] != NULL);
/* XXX: direct implementation */
- duk_push_hobject(ctx, thr->builtins[DUK_BIDX_GLOBAL]);
- ret = duk_get_prop_lstring(ctx, -1, key, key_len);
- duk_remove_m2(ctx);
+ duk_push_hobject(thr, thr->builtins[DUK_BIDX_GLOBAL]);
+ ret = duk_get_prop_lstring(thr, -1, key, key_len);
+ duk_remove_m2(thr);
return ret;
}
-DUK_EXTERNAL duk_bool_t duk_put_global_string(duk_context *ctx, const char *key) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_bool_t duk_put_global_string(duk_hthread *thr, const char *key) {
duk_bool_t ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(thr->builtins[DUK_BIDX_GLOBAL] != NULL);
/* XXX: direct implementation */
- duk_push_hobject(ctx, thr->builtins[DUK_BIDX_GLOBAL]);
- duk_insert(ctx, -2);
- ret = duk_put_prop_string(ctx, -2, key); /* [ ... global val ] -> [ ... global ] */
- duk_pop(ctx);
+ duk_push_hobject(thr, thr->builtins[DUK_BIDX_GLOBAL]);
+ duk_insert(thr, -2);
+ ret = duk_put_prop_string(thr, -2, key); /* [ ... global val ] -> [ ... global ] */
+ duk_pop(thr);
return ret;
}
-DUK_EXTERNAL duk_bool_t duk_put_global_lstring(duk_context *ctx, const char *key, duk_size_t key_len) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_bool_t duk_put_global_lstring(duk_hthread *thr, const char *key, duk_size_t key_len) {
duk_bool_t ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(thr->builtins[DUK_BIDX_GLOBAL] != NULL);
/* XXX: direct implementation */
- duk_push_hobject(ctx, thr->builtins[DUK_BIDX_GLOBAL]);
- duk_insert(ctx, -2);
- ret = duk_put_prop_lstring(ctx, -2, key, key_len); /* [ ... global val ] -> [ ... global ] */
- duk_pop(ctx);
+ duk_push_hobject(thr, thr->builtins[DUK_BIDX_GLOBAL]);
+ duk_insert(thr, -2);
+ ret = duk_put_prop_lstring(thr, -2, key, key_len); /* [ ... global val ] -> [ ... global ] */
+ duk_pop(thr);
return ret;
}
@@ -16623,38 +16974,35 @@ DUK_EXTERNAL duk_bool_t duk_put_global_lstring(duk_context *ctx, const char *key
* Object prototype
*/
-DUK_EXTERNAL void duk_get_prototype(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_get_prototype(duk_hthread *thr, duk_idx_t idx) {
duk_hobject *obj;
duk_hobject *proto;
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_UNREF(thr);
+ DUK_ASSERT_API_ENTRY(thr);
- obj = duk_require_hobject(ctx, idx);
+ obj = duk_require_hobject(thr, idx);
DUK_ASSERT(obj != NULL);
/* XXX: shared helper for duk_push_hobject_or_undefined()? */
proto = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, obj);
if (proto) {
- duk_push_hobject(ctx, proto);
+ duk_push_hobject(thr, proto);
} else {
- duk_push_undefined(ctx);
+ duk_push_undefined(thr);
}
}
-DUK_EXTERNAL void duk_set_prototype(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_set_prototype(duk_hthread *thr, duk_idx_t idx) {
duk_hobject *obj;
duk_hobject *proto;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- obj = duk_require_hobject(ctx, idx);
+ obj = duk_require_hobject(thr, idx);
DUK_ASSERT(obj != NULL);
- duk_require_type_mask(ctx, -1, DUK_TYPE_MASK_UNDEFINED |
+ duk_require_type_mask(thr, -1, DUK_TYPE_MASK_UNDEFINED |
DUK_TYPE_MASK_OBJECT);
- proto = duk_get_hobject(ctx, -1);
+ proto = duk_get_hobject(thr, -1);
/* proto can also be NULL here (allowed explicitly) */
#if defined(DUK_USE_ROM_OBJECTS)
@@ -16666,7 +17014,7 @@ DUK_EXTERNAL void duk_set_prototype(duk_context *ctx, duk_idx_t idx) {
DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, obj, proto);
- duk_pop(ctx);
+ duk_pop(thr);
}
/*
@@ -16679,21 +17027,21 @@ DUK_EXTERNAL void duk_set_prototype(duk_context *ctx, duk_idx_t idx) {
* XXX: same issue as with Duktape.fin: there's no way to delete the property
* now (just set it to undefined).
*/
-DUK_EXTERNAL void duk_get_finalizer(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL void duk_get_finalizer(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
- duk_get_prop_stridx(ctx, idx, DUK_STRIDX_INT_FINALIZER);
+ duk_get_prop_stridx(thr, idx, DUK_STRIDX_INT_FINALIZER);
}
-DUK_EXTERNAL void duk_set_finalizer(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL void duk_set_finalizer(duk_hthread *thr, duk_idx_t idx) {
duk_hobject *h;
duk_bool_t callable;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- h = duk_require_hobject(ctx, idx); /* Get before 'put' so that 'idx' is correct. */
- callable = duk_is_callable(ctx, -1);
- duk_put_prop_stridx(ctx, idx, DUK_STRIDX_INT_FINALIZER);
+ h = duk_require_hobject(thr, idx); /* Get before 'put' so that 'idx' is correct. */
+ callable = duk_is_callable(thr, -1);
+ duk_put_prop_stridx(thr, idx, DUK_STRIDX_INT_FINALIZER);
/* In addition to setting the finalizer property, keep a "have
* finalizer" flag in duk_hobject in sync so that refzero can do
@@ -16713,16 +17061,16 @@ DUK_EXTERNAL void duk_set_finalizer(duk_context *ctx, duk_idx_t idx) {
}
}
#else /* DUK_USE_FINALIZER_SUPPORT */
-DUK_EXTERNAL void duk_get_finalizer(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL void duk_get_finalizer(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_UNREF(idx);
- DUK_ERROR_UNSUPPORTED((duk_hthread *) ctx);
+ DUK_ERROR_UNSUPPORTED(thr);
}
-DUK_EXTERNAL void duk_set_finalizer(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL void duk_set_finalizer(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_UNREF(idx);
- DUK_ERROR_UNSUPPORTED((duk_hthread *) ctx);
+ DUK_ERROR_UNSUPPORTED(thr);
}
#endif /* DUK_USE_FINALIZER_SUPPORT */
/*
@@ -16743,7 +17091,7 @@ DUK_EXTERNAL void duk_set_finalizer(duk_context *ctx, duk_idx_t idx) {
* Forward declarations
*/
-DUK_LOCAL_DECL duk_idx_t duk__push_c_function_raw(duk_context *ctx, duk_c_function func, duk_idx_t nargs, duk_uint_t flags);
+DUK_LOCAL_DECL duk_idx_t duk__push_c_function_raw(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_uint_t flags, duk_small_uint_t proto_bidx);
/*
* Global state for working around missing variadic macros
@@ -16758,6 +17106,10 @@ DUK_EXTERNAL duk_int_t duk_api_global_line = 0;
* Misc helpers
*/
+DUK_LOCAL const char * const duk__symbol_type_strings[4] = {
+ "hidden", "global", "local", "wellknown"
+};
+
#if !defined(DUK_USE_PACKED_TVAL)
DUK_LOCAL const duk_uint_t duk__type_from_tag[] = {
DUK_TYPE_NUMBER,
@@ -16787,12 +17139,15 @@ DUK_LOCAL const duk_uint_t duk__type_mask_from_tag[] = {
};
#endif /* !DUK_USE_PACKED_TVAL */
+/* Assert that there's room for one value. */
+#define DUK__ASSERT_SPACE() do { \
+ DUK_ASSERT(!(thr->valstack_top >= thr->valstack_end)); \
+ } while (0)
+
/* Check that there's room to push one value. */
#if defined(DUK_USE_VALSTACK_UNSAFE)
/* Faster but value stack overruns are memory unsafe. */
-#define DUK__CHECK_SPACE() do { \
- DUK_ASSERT(!(thr->valstack_top >= thr->valstack_end)); \
- } while (0)
+#define DUK__CHECK_SPACE() DUK__ASSERT_SPACE()
#else
#define DUK__CHECK_SPACE() do { \
if (DUK_UNLIKELY(thr->valstack_top >= thr->valstack_end)) { \
@@ -16801,17 +17156,48 @@ DUK_LOCAL const duk_uint_t duk__type_mask_from_tag[] = {
} while (0)
#endif
-DUK_LOCAL_DECL duk_heaphdr *duk__get_tagged_heaphdr_raw(duk_context *ctx, duk_idx_t idx, duk_uint_t tag);
+DUK_LOCAL duk_small_uint_t duk__get_symbol_type(duk_hstring *h) {
+ const duk_uint8_t *data;
+ duk_size_t len;
-DUK_LOCAL duk_int_t duk__api_coerce_d2i(duk_context *ctx, duk_idx_t idx, duk_int_t def_value, duk_bool_t require) {
- duk_hthread *thr;
+ DUK_ASSERT(h != NULL);
+ DUK_ASSERT(DUK_HSTRING_HAS_SYMBOL(h));
+ DUK_ASSERT(DUK_HSTRING_GET_BYTELEN(h) >= 1); /* always true, symbol prefix */
+
+ data = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h);
+ len = DUK_HSTRING_GET_BYTELEN(h);
+ DUK_ASSERT(len >= 1);
+
+ /* XXX: differentiate between 0x82 and 0xff (hidden vs. internal?)? */
+
+ if (data[0] == 0xffU) {
+ return DUK_SYMBOL_TYPE_HIDDEN;
+ } else if (data[0] == 0x82U) {
+ return DUK_SYMBOL_TYPE_HIDDEN;
+ } else if (data[0] == 0x80U) {
+ return DUK_SYMBOL_TYPE_GLOBAL;
+ } else if (data[len - 1] != 0xffU) {
+ return DUK_SYMBOL_TYPE_LOCAL;
+ } else {
+ return DUK_SYMBOL_TYPE_WELLKNOWN;
+ }
+}
+
+DUK_LOCAL const char *duk__get_symbol_type_string(duk_hstring *h) {
+ duk_small_uint_t idx;
+ idx = duk__get_symbol_type(h);
+ DUK_ASSERT(idx < sizeof(duk__symbol_type_strings));
+ return duk__symbol_type_strings[idx];
+}
+
+DUK_LOCAL_DECL duk_heaphdr *duk__get_tagged_heaphdr_raw(duk_hthread *thr, duk_idx_t idx, duk_uint_t tag);
+
+DUK_LOCAL duk_int_t duk__api_coerce_d2i(duk_hthread *thr, duk_idx_t idx, duk_int_t def_value, duk_bool_t require) {
duk_tval *tv;
duk_small_int_t c;
duk_double_t d;
- thr = (duk_hthread *) ctx;
-
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
/*
@@ -16867,17 +17253,14 @@ DUK_LOCAL duk_int_t duk__api_coerce_d2i(duk_context *ctx, duk_idx_t idx, duk_int
return def_value;
}
-DUK_LOCAL duk_uint_t duk__api_coerce_d2ui(duk_context *ctx, duk_idx_t idx, duk_uint_t def_value, duk_bool_t require) {
- duk_hthread *thr;
+DUK_LOCAL duk_uint_t duk__api_coerce_d2ui(duk_hthread *thr, duk_idx_t idx, duk_uint_t def_value, duk_bool_t require) {
duk_tval *tv;
duk_small_int_t c;
duk_double_t d;
/* Same as above but for unsigned int range. */
- thr = (duk_hthread *) ctx;
-
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
#if defined(DUK_USE_FASTINT)
@@ -16930,12 +17313,11 @@ DUK_LOCAL duk_uint_t duk__api_coerce_d2ui(duk_context *ctx, duk_idx_t idx, duk_u
* There's some repetition because of this; keep the functions in sync.
*/
-DUK_EXTERNAL duk_idx_t duk_normalize_index(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_idx_t duk_normalize_index(duk_hthread *thr, duk_idx_t idx) {
duk_uidx_t vs_size;
duk_uidx_t uidx;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(DUK_INVALID_INDEX < 0);
/* Care must be taken to avoid pointer wrapping in the index
@@ -16966,12 +17348,11 @@ DUK_EXTERNAL duk_idx_t duk_normalize_index(duk_context *ctx, duk_idx_t idx) {
return DUK_INVALID_INDEX;
}
-DUK_EXTERNAL duk_idx_t duk_require_normalize_index(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_idx_t duk_require_normalize_index(duk_hthread *thr, duk_idx_t idx) {
duk_uidx_t vs_size;
duk_uidx_t uidx;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(DUK_INVALID_INDEX < 0);
DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
@@ -16995,12 +17376,11 @@ DUK_EXTERNAL duk_idx_t duk_require_normalize_index(duk_context *ctx, duk_idx_t i
return 0; /* unreachable */
}
-DUK_INTERNAL duk_tval *duk_get_tval(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_INTERNAL duk_tval *duk_get_tval(duk_hthread *thr, duk_idx_t idx) {
duk_uidx_t vs_size;
duk_uidx_t uidx;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(DUK_INVALID_INDEX < 0);
DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
@@ -17031,21 +17411,23 @@ DUK_INTERNAL duk_tval *duk_get_tval(duk_context *ctx, duk_idx_t idx) {
*/
DUK_LOCAL const duk_tval_unused duk__const_tval_unused = DUK_TVAL_UNUSED_INITIALIZER();
-DUK_INTERNAL duk_tval *duk_get_tval_or_unused(duk_context *ctx, duk_idx_t idx) {
+DUK_INTERNAL duk_tval *duk_get_tval_or_unused(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
- tv = duk_get_tval(ctx, idx);
+
+ DUK_ASSERT_API_ENTRY(thr);
+
+ tv = duk_get_tval(thr, idx);
if (tv != NULL) {
return tv;
}
return (duk_tval *) DUK_LOSE_CONST(&duk__const_tval_unused);
}
-DUK_INTERNAL duk_tval *duk_require_tval(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_INTERNAL duk_tval *duk_require_tval(duk_hthread *thr, duk_idx_t idx) {
duk_uidx_t vs_size;
duk_uidx_t uidx;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(DUK_INVALID_INDEX < 0);
DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
@@ -17071,21 +17453,19 @@ DUK_INTERNAL duk_tval *duk_require_tval(duk_context *ctx, duk_idx_t idx) {
}
/* Non-critical. */
-DUK_EXTERNAL duk_bool_t duk_is_valid_index(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_bool_t duk_is_valid_index(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(DUK_INVALID_INDEX < 0);
- return (duk_normalize_index(ctx, idx) >= 0);
+ return (duk_normalize_index(thr, idx) >= 0);
}
/* Non-critical. */
-DUK_EXTERNAL void duk_require_valid_index(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
-
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL void duk_require_valid_index(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(DUK_INVALID_INDEX < 0);
- if (DUK_UNLIKELY(duk_normalize_index(ctx, idx) < 0)) {
+ if (DUK_UNLIKELY(duk_normalize_index(thr, idx) < 0)) {
DUK_ERROR_RANGE_INDEX(thr, idx);
return; /* unreachable */
}
@@ -17095,10 +17475,8 @@ DUK_EXTERNAL void duk_require_valid_index(duk_context *ctx, duk_idx_t idx) {
* Value stack top handling
*/
-DUK_EXTERNAL duk_idx_t duk_get_top(duk_context *ctx) {
- duk_hthread *thr = (duk_hthread *) ctx;
-
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_idx_t duk_get_top(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
return (duk_idx_t) (thr->valstack_top - thr->valstack_bottom);
}
@@ -17106,11 +17484,10 @@ DUK_EXTERNAL duk_idx_t duk_get_top(duk_context *ctx) {
/* Internal helper to get current top but to require a minimum top value
* (TypeError if not met).
*/
-DUK_INTERNAL duk_idx_t duk_get_top_require_min(duk_context *ctx, duk_idx_t min_top) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_INTERNAL duk_idx_t duk_get_top_require_min(duk_hthread *thr, duk_idx_t min_top) {
duk_idx_t ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
ret = (duk_idx_t) (thr->valstack_top - thr->valstack_bottom);
if (DUK_UNLIKELY(ret < min_top)) {
@@ -17123,14 +17500,13 @@ DUK_INTERNAL duk_idx_t duk_get_top_require_min(duk_context *ctx, duk_idx_t min_t
* This is performance critical especially for call handling, so whenever
* changing, profile and look at generated code.
*/
-DUK_EXTERNAL void duk_set_top(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_set_top(duk_hthread *thr, duk_idx_t idx) {
duk_uidx_t vs_size;
duk_uidx_t vs_limit;
duk_uidx_t uidx;
duk_tval *tv;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(DUK_INVALID_INDEX < 0);
DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
@@ -17219,11 +17595,98 @@ DUK_EXTERNAL void duk_set_top(duk_context *ctx, duk_idx_t idx) {
}
}
-DUK_EXTERNAL duk_idx_t duk_get_top_index(duk_context *ctx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+/* Internal variant with a non-negative index and no runtime size checks. */
+#if defined(DUK_USE_PREFER_SIZE)
+DUK_INTERNAL void duk_set_top_unsafe(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+
+ duk_set_top(thr, idx);
+}
+#else /* DUK_USE_PREFER_SIZE */
+DUK_INTERNAL void duk_set_top_unsafe(duk_hthread *thr, duk_idx_t idx) {
+ duk_uidx_t uidx;
+ duk_uidx_t vs_size;
+ duk_tval *tv;
+
+ DUK_ASSERT_API_ENTRY(thr);
+ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
+ DUK_ASSERT(thr->valstack_end >= thr->valstack_bottom);
+ DUK_ASSERT(idx >= 0);
+ DUK_ASSERT(idx <= (duk_idx_t) (thr->valstack_end - thr->valstack_bottom));
+
+ /* XXX: byte arithmetic */
+ uidx = (duk_uidx_t) idx;
+ vs_size = (duk_uidx_t) (thr->valstack_top - thr->valstack_bottom);
+
+ if (uidx >= vs_size) {
+ /* Stack size increases or stays the same. */
+#if defined(DUK_USE_ASSERTIONS)
+ duk_uidx_t count;
+
+ count = uidx - vs_size;
+ while (count != 0) {
+ count--;
+ tv = thr->valstack_top + count;
+ DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(tv));
+ }
+#endif
+ thr->valstack_top = thr->valstack_bottom + uidx;
+ } else {
+ /* Stack size decreases. */
+#if defined(DUK_USE_REFERENCE_COUNTING)
+ duk_uidx_t count;
+ duk_tval *tv_end;
+
+ count = vs_size - uidx;
+ DUK_ASSERT(count > 0);
+ tv = thr->valstack_top;
+ tv_end = tv - count;
+ DUK_ASSERT(tv > tv_end); /* Because count > 0. */
+ do {
+ tv--;
+ DUK_ASSERT(tv >= thr->valstack_bottom);
+ DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ(thr, tv);
+ } while (tv != tv_end);
+ thr->valstack_top = tv_end;
+ DUK_REFZERO_CHECK_FAST(thr);
+#else /* DUK_USE_REFERENCE_COUNTING */
+ duk_uidx_t count;
+ duk_tval *tv_end;
+
+ count = vs_size - uidx;
+ tv = thr->valstack_top;
+ tv_end = tv - count;
+ DUK_ASSERT(tv > tv_end);
+ do {
+ tv--;
+ DUK_TVAL_SET_UNDEFINED(tv);
+ } while (tv != tv_end);
+ thr->valstack_top = tv_end;
+#endif /* DUK_USE_REFERENCE_COUNTING */
+ }
+}
+#endif /* DUK_USE_PREFER_SIZE */
+
+/* Internal helper: set top to 'top', and set [idx_wipe_start,top[ to
+ * 'undefined' (doing nothing if idx_wipe_start == top). Indices are
+ * positive and within value stack reserve. This is used by call handling.
+ */
+DUK_INTERNAL void duk_set_top_and_wipe(duk_hthread *thr, duk_idx_t top, duk_idx_t idx_wipe_start) {
+ DUK_ASSERT_API_ENTRY(thr);
+ DUK_ASSERT(top >= 0);
+ DUK_ASSERT(idx_wipe_start >= 0);
+ DUK_ASSERT(idx_wipe_start <= top);
+ DUK_ASSERT(thr->valstack_bottom + top <= thr->valstack_end);
+ DUK_ASSERT(thr->valstack_bottom + idx_wipe_start <= thr->valstack_end);
+
+ duk_set_top_unsafe(thr, idx_wipe_start);
+ duk_set_top_unsafe(thr, top);
+}
+
+DUK_EXTERNAL duk_idx_t duk_get_top_index(duk_hthread *thr) {
duk_idx_t ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
ret = (duk_idx_t) (thr->valstack_top - thr->valstack_bottom) - 1;
if (DUK_UNLIKELY(ret < 0)) {
@@ -17239,21 +17702,19 @@ DUK_EXTERNAL duk_idx_t duk_get_top_index(duk_context *ctx) {
/* Internal variant: call assumes there is at least one element on the value
* stack frame; this is only asserted for.
*/
-DUK_INTERNAL duk_idx_t duk_get_top_index_unsafe(duk_context *ctx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_INTERNAL duk_idx_t duk_get_top_index_unsafe(duk_hthread *thr) {
duk_idx_t ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
ret = (duk_idx_t) (thr->valstack_top - thr->valstack_bottom) - 1;
return ret;
}
-DUK_EXTERNAL duk_idx_t duk_require_top_index(duk_context *ctx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_idx_t duk_require_top_index(duk_hthread *thr) {
duk_idx_t ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
ret = (duk_idx_t) (thr->valstack_top - thr->valstack_bottom) - 1;
if (DUK_UNLIKELY(ret < 0)) {
@@ -17268,61 +17729,71 @@ DUK_EXTERNAL duk_idx_t duk_require_top_index(duk_context *ctx) {
*
* This resizing happens above the current "top": the value stack can be
* grown or shrunk, but the "top" is not affected. The value stack cannot
- * be resized to a size below the current "top".
+ * be resized to a size below the current reserve.
*
* The low level reallocation primitive must carefully recompute all value
* stack pointers, and must also work if ALL pointers are NULL. The resize
* is quite tricky because the valstack realloc may cause a mark-and-sweep,
* which may run finalizers. Running finalizers may resize the valstack
* recursively (the same value stack we're working on). So, after realloc
- * returns, we know that the valstack "top" should still be the same (there
- * should not be live values above the "top"), but its underlying size and
- * pointer may have changed.
+ * returns, we know that the valstack bottom, top, and reserve should still
+ * be the same (there should not be live values above the "top"), but its
+ * underlying size, alloc_end, and base pointer may have changed.
+ *
+ * 'new_size' is known to be <= DUK_USE_VALSTACK_LIMIT, which ensures that
+ * size_t and pointer arithmetic won't wrap in duk__resize_valstack().
*/
-/* XXX: perhaps refactor this to allow caller to specify some parameters, or
- * at least a 'compact' flag which skips any spare or round-up .. useful for
- * emergency gc.
+/* Low level valstack resize primitive, used for both grow and shrink. All
+ * adjustments for slack etc have already been done. Doesn't throw but does
+ * have allocation side effects.
*/
-
-DUK_LOCAL duk_bool_t duk__resize_valstack(duk_context *ctx, duk_size_t new_size) {
- duk_hthread *thr = (duk_hthread *) ctx;
- duk_ptrdiff_t old_bottom_offset;
- duk_ptrdiff_t old_top_offset;
- duk_ptrdiff_t old_end_offset_post;
-#if defined(DUK_USE_DEBUG)
- duk_ptrdiff_t old_end_offset_pre;
- duk_tval *old_valstack_pre;
- duk_tval *old_valstack_post;
-#endif
+DUK_LOCAL DUK_COLD DUK_NOINLINE duk_bool_t duk__resize_valstack(duk_hthread *thr, duk_size_t new_size) {
+ duk_tval *pre_valstack;
+ duk_tval *pre_bottom;
+ duk_tval *pre_top;
+ duk_tval *pre_end;
+ duk_tval *pre_alloc_end;
+ duk_ptrdiff_t ptr_diff;
duk_tval *new_valstack;
duk_size_t new_alloc_size;
+ duk_tval *tv_prev_alloc_end;
duk_tval *p;
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_ASSERT(thr != NULL);
+ DUK_ASSERT_HTHREAD_VALID(thr);
DUK_ASSERT(thr->valstack_bottom >= thr->valstack);
DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
DUK_ASSERT(thr->valstack_end >= thr->valstack_top);
+ DUK_ASSERT(thr->valstack_alloc_end >= thr->valstack_end);
DUK_ASSERT((duk_size_t) (thr->valstack_top - thr->valstack) <= new_size); /* can't resize below 'top' */
- DUK_ASSERT(new_size <= thr->valstack_max); /* valstack limit caller has check, prevents wrapping */
+ DUK_ASSERT(new_size <= DUK_USE_VALSTACK_LIMIT); /* valstack limit caller has check, prevents wrapping */
DUK_ASSERT(new_size <= DUK_SIZE_MAX / sizeof(duk_tval)); /* specific assert for wrapping */
- /* get pointer offsets for tweaking below */
- old_bottom_offset = (((duk_uint8_t *) thr->valstack_bottom) - ((duk_uint8_t *) thr->valstack));
- old_top_offset = (((duk_uint8_t *) thr->valstack_top) - ((duk_uint8_t *) thr->valstack));
-#if defined(DUK_USE_DEBUG)
- old_end_offset_pre = (((duk_uint8_t *) thr->valstack_end) - ((duk_uint8_t *) thr->valstack)); /* not very useful, used for debugging */
- old_valstack_pre = thr->valstack;
-#endif
+ /* Pre-realloc pointer copies for asserts and debug logs. */
+ pre_valstack = thr->valstack;
+ pre_bottom = thr->valstack_bottom;
+ pre_top = thr->valstack_top;
+ pre_end = thr->valstack_end;
+ pre_alloc_end = thr->valstack_alloc_end;
- /* Allocate a new valstack.
- *
- * Note: cannot use a plain DUK_REALLOC() because a mark-and-sweep may
- * invalidate the original thr->valstack base pointer inside the realloc
- * process. See doc/memory-management.rst.
+ DUK_UNREF(pre_valstack);
+ DUK_UNREF(pre_bottom);
+ DUK_UNREF(pre_top);
+ DUK_UNREF(pre_end);
+ DUK_UNREF(pre_alloc_end);
+
+ /* If finalizer torture enabled, force base pointer change every time
+ * when it would be allowed.
*/
+#if defined(DUK_USE_FINALIZER_TORTURE)
+ if (thr->heap->pf_prevent_count == 0) {
+ duk_hthread_valstack_torture_realloc(thr);
+ }
+#endif
+ /* Allocate a new valstack using DUK_REALLOC_DIRECT() to deal with
+ * a side effect changing the base pointer.
+ */
new_alloc_size = sizeof(duk_tval) * new_size;
new_valstack = (duk_tval *) DUK_REALLOC_INDIRECT(thr->heap, duk_hthread_get_valstack_ptr, (void *) thr, new_alloc_size);
if (DUK_UNLIKELY(new_valstack == NULL)) {
@@ -17335,69 +17806,78 @@ DUK_LOCAL duk_bool_t duk__resize_valstack(duk_context *ctx, duk_size_t new_size)
return 0;
}
- /* Note: the realloc may have triggered a mark-and-sweep which may
- * have resized our valstack internally. However, the mark-and-sweep
- * MUST NOT leave the stack bottom/top in a different state. Particular
- * assumptions and facts:
- *
- * - The thr->valstack pointer may be different after realloc,
- * and the offset between thr->valstack_end <-> thr->valstack
- * may have changed.
- * - The offset between thr->valstack_bottom <-> thr->valstack
- * and thr->valstack_top <-> thr->valstack MUST NOT have changed,
- * because mark-and-sweep must adhere to a strict stack policy.
- * In other words, logical bottom and top MUST NOT have changed.
- * - All values above the top are unreachable but are initialized
- * to UNDEFINED, up to the post-realloc valstack_end.
- * - 'old_end_offset' must be computed after realloc to be correct.
- */
-
- DUK_ASSERT((((duk_uint8_t *) thr->valstack_bottom) - ((duk_uint8_t *) thr->valstack)) == old_bottom_offset);
- DUK_ASSERT((((duk_uint8_t *) thr->valstack_top) - ((duk_uint8_t *) thr->valstack)) == old_top_offset);
-
- /* success, fixup pointers */
- old_end_offset_post = (((duk_uint8_t *) thr->valstack_end) - ((duk_uint8_t *) thr->valstack)); /* must be computed after realloc */
+ /* Debug log any changes in pointer(s) by side effects. These don't
+ * necessarily imply any incorrect behavior, but should be rare in
+ * practice.
+ */
#if defined(DUK_USE_DEBUG)
- old_valstack_post = thr->valstack;
+ if (thr->valstack != pre_valstack) {
+ DUK_D(DUK_DPRINT("valstack base pointer changed during valstack resize: %p -> %p",
+ (void *) pre_valstack, (void *) thr->valstack));
+ }
+ if (thr->valstack_bottom != pre_bottom) {
+ DUK_D(DUK_DPRINT("valstack bottom pointer changed during valstack resize: %p -> %p",
+ (void *) pre_bottom, (void *) thr->valstack_bottom));
+ }
+ if (thr->valstack_top != pre_top) {
+ DUK_D(DUK_DPRINT("valstack top pointer changed during valstack resize: %p -> %p",
+ (void *) pre_top, (void *) thr->valstack_top));
+ }
+ if (thr->valstack_end != pre_end) {
+ DUK_D(DUK_DPRINT("valstack end pointer changed during valstack resize: %p -> %p",
+ (void *) pre_end, (void *) thr->valstack_end));
+ }
+ if (thr->valstack_alloc_end != pre_alloc_end) {
+ DUK_D(DUK_DPRINT("valstack alloc_end pointer changed during valstack resize: %p -> %p",
+ (void *) pre_alloc_end, (void *) thr->valstack_alloc_end));
+ }
#endif
+
+ /* Assertions: offsets for bottom, top, and end (reserve) must not
+ * have changed even with side effects because they are always
+ * restored in unwind. For alloc_end there's no guarantee: it may
+ * have grown or shrunk (but remain above 'end').
+ */
+ DUK_ASSERT(thr->valstack_bottom - thr->valstack == pre_bottom - pre_valstack);
+ DUK_ASSERT(thr->valstack_top - thr->valstack == pre_top - pre_valstack);
+ DUK_ASSERT(thr->valstack_end - thr->valstack == pre_end - pre_valstack);
+ DUK_ASSERT(thr->valstack_alloc_end >= thr->valstack_end);
+
+ /* Write new pointers. Most pointers can be handled as a pointer
+ * difference.
+ */
+ ptr_diff = (duk_ptrdiff_t) ((duk_uint8_t *) new_valstack - (duk_uint8_t *) thr->valstack);
+ tv_prev_alloc_end = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_alloc_end + ptr_diff);
thr->valstack = new_valstack;
- thr->valstack_end = new_valstack + new_size;
-#if !defined(DUK_USE_PREFER_SIZE)
- thr->valstack_size = new_size;
-#endif
- thr->valstack_bottom = (duk_tval *) (void *) ((duk_uint8_t *) new_valstack + old_bottom_offset);
- thr->valstack_top = (duk_tval *) (void *) ((duk_uint8_t *) new_valstack + old_top_offset);
+ thr->valstack_bottom = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_bottom + ptr_diff);
+ thr->valstack_top = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_top + ptr_diff);
+ thr->valstack_end = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_end + ptr_diff);
+ thr->valstack_alloc_end = (duk_tval *) (void *) ((duk_uint8_t *) new_valstack + new_alloc_size);
+ /* Assertions: pointer sanity after pointer updates. */
DUK_ASSERT(thr->valstack_bottom >= thr->valstack);
DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
DUK_ASSERT(thr->valstack_end >= thr->valstack_top);
-
- /* useful for debugging */
-#if defined(DUK_USE_DEBUG)
- if (old_end_offset_pre != old_end_offset_post) {
- DUK_D(DUK_DPRINT("valstack was resized during valstack_resize(), probably by mark-and-sweep; "
- "end offset changed: %lu -> %lu",
- (unsigned long) old_end_offset_pre,
- (unsigned long) old_end_offset_post));
- }
- if (old_valstack_pre != old_valstack_post) {
- DUK_D(DUK_DPRINT("valstack pointer changed during valstack_resize(), probably by mark-and-sweep: %p -> %p",
- (void *) old_valstack_pre,
- (void *) old_valstack_post));
- }
-#endif
-
- DUK_DD(DUK_DDPRINT("resized valstack to %lu elements (%lu bytes), bottom=%ld, top=%ld, "
- "new pointers: start=%p end=%p bottom=%p top=%p",
- (unsigned long) new_size, (unsigned long) new_alloc_size,
- (long) (thr->valstack_bottom - thr->valstack),
- (long) (thr->valstack_top - thr->valstack),
- (void *) thr->valstack, (void *) thr->valstack_end,
- (void *) thr->valstack_bottom, (void *) thr->valstack_top));
-
- /* Init newly allocated slots (only). */
- p = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + old_end_offset_post);
- while (p < thr->valstack_end) {
+ DUK_ASSERT(thr->valstack_alloc_end >= thr->valstack_end);
+
+ DUK_D(DUK_DPRINT("resized valstack %lu -> %lu elements (%lu -> %lu bytes): "
+ "base=%p -> %p, bottom=%p -> %p (%ld), top=%p -> %p (%ld), "
+ "end=%p -> %p (%ld), alloc_end=%p -> %p (%ld);"
+ " tv_prev_alloc_end=%p (-> %ld inits; <0 means shrink)",
+ (unsigned long) (pre_alloc_end - pre_valstack),
+ (unsigned long) new_size,
+ (unsigned long) ((duk_uint8_t *) pre_alloc_end - (duk_uint8_t *) pre_valstack),
+ (unsigned long) new_alloc_size,
+ (void *) pre_valstack, (void *) thr->valstack,
+ (void *) pre_bottom, (void *) thr->valstack_bottom, (long) (thr->valstack_bottom - thr->valstack),
+ (void *) pre_top, (void *) thr->valstack_top, (long) (thr->valstack_top - thr->valstack),
+ (void *) pre_end, (void *) thr->valstack_end, (long) (thr->valstack_end - thr->valstack),
+ (void *) pre_alloc_end, (void *) thr->valstack_alloc_end, (long) (thr->valstack_alloc_end - thr->valstack),
+ (void *) tv_prev_alloc_end, (long) (thr->valstack_alloc_end - tv_prev_alloc_end)));
+
+ /* If allocation grew, init any new slots to 'undefined'. */
+ p = tv_prev_alloc_end;
+ while (p < thr->valstack_alloc_end) {
/* Never executed if new size is smaller. */
DUK_TVAL_SET_UNDEFINED(p);
p++;
@@ -17406,7 +17886,7 @@ DUK_LOCAL duk_bool_t duk__resize_valstack(duk_context *ctx, duk_size_t new_size)
/* Assert for value stack initialization policy. */
#if defined(DUK_USE_ASSERTIONS)
p = thr->valstack_top;
- while (p < thr->valstack_end) {
+ while (p < thr->valstack_alloc_end) {
DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(p));
p++;
}
@@ -17415,229 +17895,257 @@ DUK_LOCAL duk_bool_t duk__resize_valstack(duk_context *ctx, duk_size_t new_size)
return 1;
}
-DUK_LOCAL DUK_COLD DUK_NOINLINE duk_bool_t duk__valstack_do_resize(duk_context *ctx,
- duk_size_t min_new_size,
- duk_small_uint_t flags) {
- duk_hthread *thr = (duk_hthread *) ctx;
- duk_size_t old_size;
+DUK_LOCAL DUK_COLD DUK_NOINLINE duk_bool_t duk__valstack_grow(duk_hthread *thr, duk_size_t min_bytes, duk_bool_t throw_on_error) {
+ duk_size_t min_size;
duk_size_t new_size;
- duk_bool_t is_shrink;
- duk_small_uint_t compact_flag = (flags & DUK_VSRESIZE_FLAG_COMPACT);
- duk_small_uint_t throw_flag = (flags & DUK_VSRESIZE_FLAG_THROW);
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_ASSERT(thr != NULL);
- DUK_ASSERT(thr->valstack_bottom >= thr->valstack);
- DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
- DUK_ASSERT(thr->valstack_end >= thr->valstack_top);
+ DUK_ASSERT(min_bytes / sizeof(duk_tval) * sizeof(duk_tval) == min_bytes);
+ min_size = min_bytes / sizeof(duk_tval); /* from bytes to slots */
-#if defined(DUK_USE_PREFER_SIZE)
- old_size = (duk_size_t) (thr->valstack_end - thr->valstack);
+#if defined(DUK_USE_VALSTACK_GROW_SHIFT)
+ /* New size is minimum size plus a proportional slack, e.g. shift of
+ * 2 means a 25% slack.
+ */
+ new_size = min_size + (min_size >> DUK_USE_VALSTACK_GROW_SHIFT);
#else
- DUK_ASSERT((duk_size_t) (thr->valstack_end - thr->valstack) == thr->valstack_size);
- old_size = thr->valstack_size;
+ /* New size is tight with no slack. This is sometimes preferred in
+ * low memory environments.
+ */
+ new_size = min_size;
#endif
- if (min_new_size <= old_size) {
- is_shrink = 1;
- } else {
- is_shrink = 0;
- }
-
- new_size = min_new_size;
- if (!compact_flag) {
- if (is_shrink) {
- /* shrink case; leave some spare */
- new_size += DUK_VALSTACK_SHRINK_SPARE;
- }
-
- /* round up roughly to next 'grow step' */
- new_size = (new_size / DUK_VALSTACK_GROW_STEP + 1) * DUK_VALSTACK_GROW_STEP;
- }
-
- DUK_DD(DUK_DDPRINT("want to %s valstack: %lu -> %lu elements (min_new_size %lu)",
- (const char *) (new_size > old_size ? "grow" : "shrink"),
- (unsigned long) old_size, (unsigned long) new_size,
- (unsigned long) min_new_size));
-
- if (DUK_UNLIKELY(new_size > thr->valstack_max)) {
+ if (DUK_UNLIKELY(new_size > DUK_USE_VALSTACK_LIMIT || new_size < min_size /*wrap*/)) {
/* Note: may be triggered even if minimal new_size would not reach the limit,
- * plan limit accordingly (taking DUK_VALSTACK_GROW_STEP into account).
+ * plan limit accordingly.
*/
- if (throw_flag) {
+ if (throw_on_error) {
DUK_ERROR_RANGE(thr, DUK_STR_VALSTACK_LIMIT);
- } else {
- return 0;
}
+ return 0;
}
- /*
- * When resizing the valstack, a mark-and-sweep may be triggered for
- * the allocation of the new valstack. If the mark-and-sweep needs
- * to use our thread for something, it may cause *the same valstack*
- * to be resized recursively. This happens e.g. when mark-and-sweep
- * finalizers are called. This is taken into account carefully in
- * duk__resize_valstack().
- *
- * 'new_size' is known to be <= valstack_max, which ensures that
- * size_t and pointer arithmetic won't wrap in duk__resize_valstack().
- */
-
- if (DUK_UNLIKELY(!duk__resize_valstack(ctx, new_size))) {
- if (is_shrink) {
- DUK_DD(DUK_DDPRINT("valstack resize failed, but is a shrink, ignore"));
- return 1;
- }
-
- DUK_DD(DUK_DDPRINT("valstack resize failed"));
-
- if (throw_flag) {
+ if (duk__resize_valstack(thr, new_size) == 0) {
+ if (throw_on_error) {
DUK_ERROR_ALLOC_FAILED(thr);
- } else {
- return 0;
}
+ return 0;
}
- DUK_DDD(DUK_DDDPRINT("valstack resize successful"));
+ thr->valstack_end = thr->valstack + min_size;
+ DUK_ASSERT(thr->valstack_alloc_end >= thr->valstack_end);
+
return 1;
}
-DUK_INTERNAL duk_bool_t duk_valstack_resize_raw(duk_context *ctx,
- duk_size_t min_new_size,
- duk_small_uint_t flags) {
- duk_hthread *thr = (duk_hthread *) ctx;
- duk_size_t old_size;
+/* Hot, inlined value stack grow check. Because value stack almost never
+ * grows, the actual resize call is in a NOINLINE helper.
+ */
+DUK_INTERNAL DUK_INLINE void duk_valstack_grow_check_throw(duk_hthread *thr, duk_size_t min_bytes) {
+ duk_tval *tv;
- DUK_DDD(DUK_DDDPRINT("check valstack resize: min_new_size=%lu, curr_size=%ld, curr_top=%ld, "
- "curr_bottom=%ld, flags=%lx",
- (unsigned long) min_new_size,
- (long) (thr->valstack_end - thr->valstack),
- (long) (thr->valstack_top - thr->valstack),
- (long) (thr->valstack_bottom - thr->valstack),
- (unsigned long) flags));
+ tv = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + min_bytes);
+ if (DUK_LIKELY(thr->valstack_end >= tv)) {
+ return;
+ }
+ if (DUK_LIKELY(thr->valstack_alloc_end >= tv)) {
+ /* Values in [valstack_top,valstack_alloc_end[ are initialized
+ * to 'undefined' so we can just move the end pointer.
+ */
+ thr->valstack_end = tv;
+ return;
+ }
+ (void) duk__valstack_grow(thr, min_bytes, 1 /*throw_on_error*/);
+}
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_ASSERT(thr != NULL);
- DUK_ASSERT(thr->valstack_bottom >= thr->valstack);
- DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
- DUK_ASSERT(thr->valstack_end >= thr->valstack_top);
+/* Hot, inlined value stack grow check which doesn't throw. */
+DUK_INTERNAL DUK_INLINE duk_bool_t duk_valstack_grow_check_nothrow(duk_hthread *thr, duk_size_t min_bytes) {
+ duk_tval *tv;
-#if defined(DUK_USE_PREFER_SIZE)
- old_size = (duk_size_t) (thr->valstack_end - thr->valstack);
+ tv = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack + min_bytes);
+ if (DUK_LIKELY(thr->valstack_end >= tv)) {
+ return 1;
+ }
+ if (DUK_LIKELY(thr->valstack_alloc_end >= tv)) {
+ thr->valstack_end = tv;
+ return 1;
+ }
+ return duk__valstack_grow(thr, min_bytes, 0 /*throw_on_error*/);
+}
+
+/* Value stack shrink check, called from mark-and-sweep. */
+DUK_INTERNAL void duk_valstack_shrink_check_nothrow(duk_hthread *thr, duk_bool_t snug) {
+ duk_size_t alloc_bytes;
+ duk_size_t reserve_bytes;
+ duk_size_t shrink_bytes;
+
+ alloc_bytes = (duk_size_t) ((duk_uint8_t *) thr->valstack_alloc_end - (duk_uint8_t *) thr->valstack);
+ reserve_bytes = (duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack);
+ DUK_ASSERT(alloc_bytes >= reserve_bytes);
+
+ /* We're free to shrink the value stack allocation down to
+ * reserve_bytes but not more. If 'snug' (emergency GC)
+ * shrink whatever we can. Otherwise only shrink if the new
+ * size would be considerably smaller.
+ */
+
+#if defined(DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT)
+ if (snug) {
+ shrink_bytes = reserve_bytes;
+ } else {
+ duk_size_t proportion, slack;
+
+ /* Require that value stack shrinks by at least X% of its
+ * current size. For example, shift of 2 means at least
+ * 25%. The proportion is computed as bytes and may not
+ * be a multiple of sizeof(duk_tval); that's OK here.
+ */
+ proportion = alloc_bytes >> DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT;
+ if (alloc_bytes - reserve_bytes < proportion) {
+ /* Too little would be freed, do nothing. */
+ return;
+ }
+
+ /* Keep a slack after shrinking. The slack is again a
+ * proportion of the current size (the proportion should
+ * of course be smaller than the check proportion above).
+ */
+#if defined(DUK_USE_VALSTACK_SHRINK_SLACK_SHIFT)
+ DUK_ASSERT(DUK_USE_VALSTACK_SHRINK_SLACK_SHIFT > DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT);
+ slack = alloc_bytes >> DUK_USE_VALSTACK_SHRINK_SLACK_SHIFT;
#else
- DUK_ASSERT((duk_size_t) (thr->valstack_end - thr->valstack) == thr->valstack_size);
- old_size = thr->valstack_size;
+ slack = 0;
#endif
+ shrink_bytes = reserve_bytes +
+ slack / sizeof(duk_tval) * sizeof(duk_tval); /* multiple of duk_tval */
+ }
+#else /* DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT */
+ /* Always snug, useful in some low memory environments. */
+ DUK_UNREF(snug);
+ shrink_bytes = reserve_bytes;
+#endif /* DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT */
- if (DUK_LIKELY(min_new_size <= old_size)) {
- if (DUK_LIKELY((flags & DUK_VSRESIZE_FLAG_SHRINK) == 0 ||
- old_size - min_new_size < DUK_VALSTACK_SHRINK_THRESHOLD)) {
- DUK_DDD(DUK_DDDPRINT("no need to grow or shrink valstack"));
- return 1;
- }
+ DUK_D(DUK_DPRINT("valstack shrink check: alloc_bytes=%ld, reserve_bytes=%ld, shrink_bytes=%ld (unvalidated)",
+ (long) alloc_bytes, (long) reserve_bytes, (long) shrink_bytes));
+ DUK_ASSERT(shrink_bytes >= reserve_bytes);
+ if (shrink_bytes >= alloc_bytes) {
+ /* Skip if shrink target is same as current one (or higher,
+ * though that shouldn't happen in practice).
+ */
+ return;
}
+ DUK_ASSERT(shrink_bytes / sizeof(duk_tval) * sizeof(duk_tval) == shrink_bytes);
+
+ DUK_D(DUK_DPRINT("valstack shrink check: decided to shrink, snug: %ld", (long) snug));
- return duk__valstack_do_resize(ctx, min_new_size, flags);
+ duk__resize_valstack(thr, shrink_bytes / sizeof(duk_tval));
}
-DUK_EXTERNAL duk_bool_t duk_check_stack(duk_context *ctx, duk_idx_t extra) {
- duk_hthread *thr = (duk_hthread *) ctx;
- duk_size_t min_new_size;
+DUK_EXTERNAL duk_bool_t duk_check_stack(duk_hthread *thr, duk_idx_t extra) {
+ duk_size_t min_new_bytes;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(thr != NULL);
- if (DUK_UNLIKELY(extra < 0)) {
- /* Clamping to zero makes the API more robust to calling code
- * calculation errors.
- */
- extra = 0;
+ if (DUK_UNLIKELY(extra < 0 || extra > DUK_USE_VALSTACK_LIMIT)) {
+ if (extra < 0) {
+ /* Clamping to zero makes the API more robust to calling code
+ * calculation errors.
+ */
+ extra = 0;
+ } else {
+ /* Cause grow check to fail without wrapping arithmetic. */
+ extra = DUK_USE_VALSTACK_LIMIT;
+ }
}
- min_new_size = (thr->valstack_top - thr->valstack) + extra + DUK_VALSTACK_INTERNAL_EXTRA;
- return duk_valstack_resize_raw(ctx,
- min_new_size, /* min_new_size */
- 0 /* no shrink */ | /* flags */
- 0 /* no compact */ |
- 0 /* no throw */);
+ min_new_bytes = (duk_size_t) ((duk_uint8_t *) thr->valstack_top - (duk_uint8_t *) thr->valstack) +
+ sizeof(duk_tval) * ((duk_size_t) extra + DUK_VALSTACK_INTERNAL_EXTRA);
+ return duk_valstack_grow_check_nothrow(thr, min_new_bytes);
}
-DUK_EXTERNAL void duk_require_stack(duk_context *ctx, duk_idx_t extra) {
- duk_hthread *thr = (duk_hthread *) ctx;
- duk_size_t min_new_size;
+DUK_EXTERNAL void duk_require_stack(duk_hthread *thr, duk_idx_t extra) {
+ duk_size_t min_new_bytes;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(thr != NULL);
- if (DUK_UNLIKELY(extra < 0)) {
- /* Clamping to zero makes the API more robust to calling code
- * calculation errors.
- */
- extra = 0;
+ if (DUK_UNLIKELY(extra < 0 || extra > DUK_USE_VALSTACK_LIMIT)) {
+ if (extra < 0) {
+ /* Clamping to zero makes the API more robust to calling code
+ * calculation errors.
+ */
+ extra = 0;
+ } else {
+ /* Cause grow check to fail without wrapping arithmetic. */
+ extra = DUK_USE_VALSTACK_LIMIT;
+ }
}
- min_new_size = (thr->valstack_top - thr->valstack) + extra + DUK_VALSTACK_INTERNAL_EXTRA;
- (void) duk_valstack_resize_raw(ctx,
- min_new_size, /* min_new_size */
- 0 /* no shrink */ | /* flags */
- 0 /* no compact */ |
- DUK_VSRESIZE_FLAG_THROW);
+ min_new_bytes = (duk_size_t) ((duk_uint8_t *) thr->valstack_top - (duk_uint8_t *) thr->valstack) +
+ sizeof(duk_tval) * ((duk_size_t) extra + DUK_VALSTACK_INTERNAL_EXTRA);
+ duk_valstack_grow_check_throw(thr, min_new_bytes);
}
-DUK_EXTERNAL duk_bool_t duk_check_stack_top(duk_context *ctx, duk_idx_t top) {
- duk_size_t min_new_size;
+DUK_EXTERNAL duk_bool_t duk_check_stack_top(duk_hthread *thr, duk_idx_t top) {
+ duk_size_t min_new_bytes;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- if (DUK_UNLIKELY(top < 0)) {
- /* Clamping to zero makes the API more robust to calling code
- * calculation errors.
- */
- top = 0;
+ if (DUK_UNLIKELY(top < 0 || top > DUK_USE_VALSTACK_LIMIT)) {
+ if (top < 0) {
+ /* Clamping to zero makes the API more robust to calling code
+ * calculation errors.
+ */
+ top = 0;
+ } else {
+ /* Cause grow check to fail without wrapping arithmetic. */
+ top = DUK_USE_VALSTACK_LIMIT;
+ }
}
- min_new_size = top + DUK_VALSTACK_INTERNAL_EXTRA;
- return duk_valstack_resize_raw(ctx,
- min_new_size, /* min_new_size */
- 0 /* no shrink */ | /* flags */
- 0 /* no compact */ |
- 0 /* no throw */);
+ DUK_ASSERT(top >= 0);
+ min_new_bytes = (duk_size_t) ((duk_uint8_t *) thr->valstack_bottom - (duk_uint8_t *) thr->valstack) +
+ sizeof(duk_tval) * ((duk_size_t) top + DUK_VALSTACK_INTERNAL_EXTRA);
+ return duk_valstack_grow_check_nothrow(thr, min_new_bytes);
}
-DUK_EXTERNAL void duk_require_stack_top(duk_context *ctx, duk_idx_t top) {
- duk_size_t min_new_size;
+DUK_EXTERNAL void duk_require_stack_top(duk_hthread *thr, duk_idx_t top) {
+ duk_size_t min_new_bytes;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- if (DUK_UNLIKELY(top < 0)) {
- /* Clamping to zero makes the API more robust to calling code
- * calculation errors.
- */
- top = 0;
+ if (DUK_UNLIKELY(top < 0 || top > DUK_USE_VALSTACK_LIMIT)) {
+ if (top < 0) {
+ /* Clamping to zero makes the API more robust to calling code
+ * calculation errors.
+ */
+ top = 0;
+ } else {
+ /* Cause grow check to fail without wrapping arithmetic. */
+ top = DUK_USE_VALSTACK_LIMIT;
+ }
}
- min_new_size = top + DUK_VALSTACK_INTERNAL_EXTRA;
- (void) duk_valstack_resize_raw(ctx,
- min_new_size, /* min_new_size */
- 0 /* no shrink */ | /* flags */
- 0 /* no compact */ |
- DUK_VSRESIZE_FLAG_THROW);
+ DUK_ASSERT(top >= 0);
+ min_new_bytes = (duk_size_t) ((duk_uint8_t *) thr->valstack_bottom - (duk_uint8_t *) thr->valstack) +
+ sizeof(duk_tval) * ((duk_size_t) top + DUK_VALSTACK_INTERNAL_EXTRA);
+ duk_valstack_grow_check_throw(thr, min_new_bytes);
}
/*
* Basic stack manipulation: swap, dup, insert, replace, etc
*/
-DUK_EXTERNAL void duk_swap(duk_context *ctx, duk_idx_t idx1, duk_idx_t idx2) {
+DUK_EXTERNAL void duk_swap(duk_hthread *thr, duk_idx_t idx1, duk_idx_t idx2) {
duk_tval *tv1;
duk_tval *tv2;
duk_tval tv_tmp;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- tv1 = duk_require_tval(ctx, idx1);
+ tv1 = duk_require_tval(thr, idx1);
DUK_ASSERT(tv1 != NULL);
- tv2 = duk_require_tval(ctx, idx2);
+ tv2 = duk_require_tval(thr, idx2);
DUK_ASSERT(tv2 != NULL);
/* If tv1==tv2 this is a NOP, no check is needed */
@@ -17646,22 +18154,20 @@ DUK_EXTERNAL void duk_swap(duk_context *ctx, duk_idx_t idx1, duk_idx_t idx2) {
DUK_TVAL_SET_TVAL(tv2, &tv_tmp);
}
-DUK_EXTERNAL void duk_swap_top(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL void duk_swap_top(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
- duk_swap(ctx, idx, -1);
+ duk_swap(thr, idx, -1);
}
-DUK_EXTERNAL void duk_dup(duk_context *ctx, duk_idx_t from_idx) {
- duk_hthread *thr;
+DUK_EXTERNAL void duk_dup(duk_hthread *thr, duk_idx_t from_idx) {
duk_tval *tv_from;
duk_tval *tv_to;
- DUK_ASSERT_CTX_VALID(ctx);
- thr = (duk_hthread *) ctx;
+ DUK_ASSERT_API_ENTRY(thr);
DUK__CHECK_SPACE();
- tv_from = duk_require_tval(ctx, from_idx);
+ tv_from = duk_require_tval(thr, from_idx);
tv_to = thr->valstack_top++;
DUK_ASSERT(tv_from != NULL);
DUK_ASSERT(tv_to != NULL);
@@ -17669,16 +18175,14 @@ DUK_EXTERNAL void duk_dup(duk_context *ctx, duk_idx_t from_idx) {
DUK_TVAL_INCREF(thr, tv_to); /* no side effects */
}
-DUK_EXTERNAL void duk_dup_top(duk_context *ctx) {
+DUK_EXTERNAL void duk_dup_top(duk_hthread *thr) {
#if defined(DUK_USE_PREFER_SIZE)
- duk_dup(ctx, -1);
+ duk_dup(thr, -1);
#else
- duk_hthread *thr;
duk_tval *tv_from;
duk_tval *tv_to;
- DUK_ASSERT_CTX_VALID(ctx);
- thr = (duk_hthread *) ctx;
+ DUK_ASSERT_API_ENTRY(thr);
DUK__CHECK_SPACE();
if (DUK_UNLIKELY(thr->valstack_top - thr->valstack_bottom <= 0)) {
@@ -17694,36 +18198,42 @@ DUK_EXTERNAL void duk_dup_top(duk_context *ctx) {
#endif
}
-DUK_INTERNAL void duk_dup_0(duk_context *ctx) {
- duk_dup(ctx, 0);
+DUK_INTERNAL void duk_dup_0(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ duk_dup(thr, 0);
}
-DUK_INTERNAL void duk_dup_1(duk_context *ctx) {
- duk_dup(ctx, 1);
+DUK_INTERNAL void duk_dup_1(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ duk_dup(thr, 1);
}
-DUK_INTERNAL void duk_dup_2(duk_context *ctx) {
- duk_dup(ctx, 2);
+DUK_INTERNAL void duk_dup_2(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ duk_dup(thr, 2);
}
-DUK_INTERNAL void duk_dup_m2(duk_context *ctx) {
- duk_dup(ctx, -2);
+DUK_INTERNAL void duk_dup_m2(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ duk_dup(thr, -2);
}
-DUK_INTERNAL void duk_dup_m3(duk_context *ctx) {
- duk_dup(ctx, -3);
+DUK_INTERNAL void duk_dup_m3(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ duk_dup(thr, -3);
}
-DUK_INTERNAL void duk_dup_m4(duk_context *ctx) {
- duk_dup(ctx, -4);
+DUK_INTERNAL void duk_dup_m4(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ duk_dup(thr, -4);
}
-DUK_EXTERNAL void duk_insert(duk_context *ctx, duk_idx_t to_idx) {
+DUK_EXTERNAL void duk_insert(duk_hthread *thr, duk_idx_t to_idx) {
duk_tval *p;
duk_tval *q;
duk_tval tv_tmp;
duk_size_t nbytes;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- p = duk_require_tval(ctx, to_idx);
+ p = duk_require_tval(thr, to_idx);
DUK_ASSERT(p != NULL);
- q = duk_require_tval(ctx, -1);
+ q = duk_require_tval(thr, -1);
DUK_ASSERT(q != NULL);
DUK_ASSERT(q >= p);
@@ -17753,21 +18263,43 @@ DUK_EXTERNAL void duk_insert(duk_context *ctx, duk_idx_t to_idx) {
}
}
-DUK_EXTERNAL void duk_replace(duk_context *ctx, duk_idx_t to_idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_INTERNAL void duk_insert_undefined(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+ DUK_ASSERT(idx >= 0); /* Doesn't support negative indices. */
+
+ duk_push_undefined(thr);
+ duk_insert(thr, idx);
+}
+
+DUK_INTERNAL void duk_insert_undefined_n(duk_hthread *thr, duk_idx_t idx, duk_idx_t count) {
+ duk_tval *tv, *tv_end;
+
+ DUK_ASSERT_API_ENTRY(thr);
+ DUK_ASSERT(idx >= 0); /* Doesn't support negative indices or count. */
+ DUK_ASSERT(count >= 0);
+
+ tv = duk_reserve_gap(thr, idx, count);
+ tv_end = tv + count;
+ while (tv != tv_end) {
+ DUK_TVAL_SET_UNDEFINED(tv);
+ tv++;
+ }
+}
+
+DUK_EXTERNAL void duk_replace(duk_hthread *thr, duk_idx_t to_idx) {
duk_tval *tv1;
duk_tval *tv2;
duk_tval tv_tmp;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- tv1 = duk_require_tval(ctx, -1);
+ tv1 = duk_require_tval(thr, -1);
DUK_ASSERT(tv1 != NULL);
- tv2 = duk_require_tval(ctx, to_idx);
+ tv2 = duk_require_tval(thr, to_idx);
DUK_ASSERT(tv2 != NULL);
/* For tv1 == tv2, both pointing to stack top, the end result
- * is same as duk_pop(ctx).
+ * is same as duk_pop(thr).
*/
DUK_TVAL_SET_TVAL(&tv_tmp, tv2);
DUK_TVAL_SET_TVAL(tv2, tv1);
@@ -17776,25 +18308,22 @@ DUK_EXTERNAL void duk_replace(duk_context *ctx, duk_idx_t to_idx) {
DUK_TVAL_DECREF(thr, &tv_tmp); /* side effects */
}
-DUK_EXTERNAL void duk_copy(duk_context *ctx, duk_idx_t from_idx, duk_idx_t to_idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_copy(duk_hthread *thr, duk_idx_t from_idx, duk_idx_t to_idx) {
duk_tval *tv1;
duk_tval *tv2;
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_UNREF(thr); /* w/o refcounting */
+ DUK_ASSERT_API_ENTRY(thr);
- tv1 = duk_require_tval(ctx, from_idx);
+ tv1 = duk_require_tval(thr, from_idx);
DUK_ASSERT(tv1 != NULL);
- tv2 = duk_require_tval(ctx, to_idx);
+ tv2 = duk_require_tval(thr, to_idx);
DUK_ASSERT(tv2 != NULL);
/* For tv1 == tv2, this is a no-op (no explicit check needed). */
DUK_TVAL_SET_TVAL_UPDREF(thr, tv2, tv1); /* side effects */
}
-DUK_EXTERNAL void duk_remove(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_remove(duk_hthread *thr, duk_idx_t idx) {
duk_tval *p;
duk_tval *q;
#if defined(DUK_USE_REFERENCE_COUNTING)
@@ -17802,11 +18331,11 @@ DUK_EXTERNAL void duk_remove(duk_context *ctx, duk_idx_t idx) {
#endif
duk_size_t nbytes;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- p = duk_require_tval(ctx, idx);
+ p = duk_require_tval(thr, idx);
DUK_ASSERT(p != NULL);
- q = duk_require_tval(ctx, -1);
+ q = duk_require_tval(thr, -1);
DUK_ASSERT(q != NULL);
DUK_ASSERT(q >= p);
@@ -17833,17 +18362,74 @@ DUK_EXTERNAL void duk_remove(duk_context *ctx, duk_idx_t idx) {
#endif
}
-DUK_INTERNAL_DECL void duk_remove_m2(duk_context *ctx) {
- duk_remove(ctx, -2);
+DUK_INTERNAL void duk_remove_unsafe(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+
+ duk_remove(thr, idx); /* XXX: no optimization for now */
+}
+
+DUK_INTERNAL void duk_remove_m2(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+
+ duk_remove(thr, -2);
+}
+
+DUK_INTERNAL void duk_remove_n(duk_hthread *thr, duk_idx_t idx, duk_idx_t count) {
+#if defined(DUK_USE_PREFER_SIZE)
+ /* XXX: maybe too slow even when preferring size? */
+ DUK_ASSERT_API_ENTRY(thr);
+ DUK_ASSERT(count >= 0);
+ DUK_ASSERT(idx >= 0);
+
+ while (count-- > 0) {
+ duk_remove(thr, idx);
+ }
+#else /* DUK_USE_PREFER_SIZE */
+ duk_tval *tv_src;
+ duk_tval *tv_dst;
+ duk_tval *tv_newtop;
+ duk_tval *tv;
+ duk_size_t bytes;
+
+ DUK_ASSERT_API_ENTRY(thr);
+ DUK_ASSERT(count >= 0);
+ DUK_ASSERT(idx >= 0);
+
+ tv_dst = thr->valstack_bottom + idx;
+ DUK_ASSERT(tv_dst <= thr->valstack_top);
+ tv_src = tv_dst + count;
+ DUK_ASSERT(tv_src <= thr->valstack_top);
+ bytes = (duk_size_t) ((duk_uint8_t *) thr->valstack_top - (duk_uint8_t *) tv_src);
+
+ for (tv = tv_dst; tv < tv_src; tv++) {
+ DUK_TVAL_DECREF_NORZ(thr, tv);
+ }
+
+ DUK_MEMMOVE((void *) tv_dst, (const void *) tv_src, bytes);
+
+ tv_newtop = thr->valstack_top - count;
+ for (tv = tv_newtop; tv < thr->valstack_top; tv++) {
+ DUK_TVAL_SET_UNDEFINED(tv);
+ }
+ thr->valstack_top = tv_newtop;
+
+ /* When not preferring size, only NORZ macros are used; caller
+ * is expected to DUK_REFZERO_CHECK().
+ */
+#endif /* DUK_USE_PREFER_SIZE */
+}
+
+DUK_INTERNAL void duk_remove_n_unsafe(duk_hthread *thr, duk_idx_t idx, duk_idx_t count) {
+ DUK_ASSERT_API_ENTRY(thr);
+
+ duk_remove_n(thr, idx, count); /* XXX: no optimization for now */
}
/*
* Stack slice primitives
*/
-DUK_EXTERNAL void duk_xcopymove_raw(duk_context *to_ctx, duk_context *from_ctx, duk_idx_t count, duk_bool_t is_copy) {
- duk_hthread *to_thr = (duk_hthread *) to_ctx;
- duk_hthread *from_thr = (duk_hthread *) from_ctx;
+DUK_EXTERNAL void duk_xcopymove_raw(duk_hthread *to_thr, duk_hthread *from_thr, duk_idx_t count, duk_bool_t is_copy) {
void *src;
duk_size_t nbytes;
duk_tval *p;
@@ -17851,23 +18437,25 @@ DUK_EXTERNAL void duk_xcopymove_raw(duk_context *to_ctx, duk_context *from_ctx,
/* XXX: several pointer comparison issues here */
- DUK_ASSERT_CTX_VALID(to_ctx);
- DUK_ASSERT_CTX_VALID(from_ctx);
- DUK_ASSERT(to_ctx != NULL);
- DUK_ASSERT(from_ctx != NULL);
+ DUK_ASSERT_API_ENTRY(to_thr);
+ DUK_ASSERT_CTX_VALID(to_thr);
+ DUK_ASSERT_CTX_VALID(from_thr);
+ DUK_ASSERT(to_thr->heap == from_thr->heap);
- if (DUK_UNLIKELY(to_ctx == from_ctx)) {
+ if (DUK_UNLIKELY(to_thr == from_thr)) {
DUK_ERROR_TYPE(to_thr, DUK_STR_INVALID_CONTEXT);
return;
}
- if (DUK_UNLIKELY((count < 0) ||
- (count > (duk_idx_t) to_thr->valstack_max))) {
- /* Maximum value check ensures 'nbytes' won't wrap below. */
+ if (DUK_UNLIKELY((duk_uidx_t) count > (duk_uidx_t) DUK_USE_VALSTACK_LIMIT)) {
+ /* Maximum value check ensures 'nbytes' won't wrap below.
+ * Also handles negative count.
+ */
DUK_ERROR_RANGE_INVALID_COUNT(to_thr);
return;
}
+ DUK_ASSERT(count >= 0);
- nbytes = sizeof(duk_tval) * count;
+ nbytes = sizeof(duk_tval) * (duk_size_t) count;
if (DUK_UNLIKELY(nbytes == 0)) {
return;
}
@@ -17880,7 +18468,7 @@ DUK_EXTERNAL void duk_xcopymove_raw(duk_context *to_ctx, duk_context *from_ctx,
DUK_ERROR_RANGE_INVALID_COUNT(to_thr);
}
- /* copy values (no overlap even if to_ctx == from_ctx; that's not
+ /* copy values (no overlap even if to_thr == from_thr; that's not
* allowed now anyway)
*/
DUK_ASSERT(nbytes > 0);
@@ -17910,43 +18498,72 @@ DUK_EXTERNAL void duk_xcopymove_raw(duk_context *to_ctx, duk_context *from_ctx,
}
}
+/* Internal helper: reserve a gap of 'count' elements at 'idx_base' and return a
+ * pointer to the gap. Values in the gap are garbage and MUST be initialized by
+ * the caller before any side effects may occur. The caller must ensure there's
+ * enough stack reserve for 'count' values.
+ */
+DUK_INTERNAL duk_tval *duk_reserve_gap(duk_hthread *thr, duk_idx_t idx_base, duk_idx_t count) {
+ duk_tval *tv_src;
+ duk_tval *tv_dst;
+ duk_size_t gap_bytes;
+ duk_size_t copy_bytes;
+
+ /* Caller is responsible for ensuring there's enough preallocated
+ * value stack.
+ */
+ DUK_ASSERT_API_ENTRY(thr);
+ DUK_ASSERT(count >= 0);
+ DUK_ASSERT((duk_size_t) (thr->valstack_end - thr->valstack_top) >= (duk_size_t) count);
+
+ tv_src = thr->valstack_bottom + idx_base;
+ gap_bytes = (duk_size_t) count * sizeof(duk_tval);
+ tv_dst = (duk_tval *) (void *) ((duk_uint8_t *) tv_src + gap_bytes);
+ copy_bytes = (duk_size_t) ((duk_uint8_t *) thr->valstack_top - (duk_uint8_t *) tv_src);
+ thr->valstack_top = (duk_tval *) (void *) ((duk_uint8_t *) thr->valstack_top + gap_bytes);
+ DUK_MEMMOVE((void *) tv_dst, (const void *) tv_src, copy_bytes);
+
+ /* Values in the gap are left as garbage: caller must fill them in
+ * and INCREF them before any side effects.
+ */
+ return tv_src;
+}
+
/*
* Get/opt/require
*/
-DUK_EXTERNAL void duk_require_undefined(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_require_undefined(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
if (DUK_UNLIKELY(!DUK_TVAL_IS_UNDEFINED(tv))) {
DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, "undefined", DUK_STR_NOT_UNDEFINED);
}
}
-DUK_EXTERNAL void duk_require_null(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_require_null(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
if (DUK_UNLIKELY(!DUK_TVAL_IS_NULL(tv))) {
DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, "null", DUK_STR_NOT_NULL);
}
}
-DUK_LOCAL DUK_ALWAYS_INLINE duk_bool_t duk__get_boolean_raw(duk_context *ctx, duk_idx_t idx, duk_bool_t def_value) {
+DUK_LOCAL DUK_ALWAYS_INLINE duk_bool_t duk__get_boolean_raw(duk_hthread *thr, duk_idx_t idx, duk_bool_t def_value) {
duk_bool_t ret;
duk_tval *tv;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_CTX_VALID(thr);
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
if (DUK_TVAL_IS_BOOLEAN(tv)) {
ret = DUK_TVAL_GET_BOOLEAN(tv);
@@ -17959,26 +18576,25 @@ DUK_LOCAL DUK_ALWAYS_INLINE duk_bool_t duk__get_boolean_raw(duk_context *ctx, du
return ret;
}
-DUK_EXTERNAL duk_bool_t duk_get_boolean(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_bool_t duk_get_boolean(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
- return duk__get_boolean_raw(ctx, idx, 0); /* default: false */
+ return duk__get_boolean_raw(thr, idx, 0); /* default: false */
}
-DUK_EXTERNAL duk_bool_t duk_get_boolean_default(duk_context *ctx, duk_idx_t idx, duk_bool_t def_value) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_bool_t duk_get_boolean_default(duk_hthread *thr, duk_idx_t idx, duk_bool_t def_value) {
+ DUK_ASSERT_API_ENTRY(thr);
- return duk__get_boolean_raw(ctx, idx, def_value);
+ return duk__get_boolean_raw(thr, idx, def_value);
}
-DUK_EXTERNAL duk_bool_t duk_require_boolean(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_bool_t duk_require_boolean(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
duk_bool_t ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
if (DUK_LIKELY(DUK_TVAL_IS_BOOLEAN(tv))) {
ret = DUK_TVAL_GET_BOOLEAN(tv);
@@ -17989,22 +18605,22 @@ DUK_EXTERNAL duk_bool_t duk_require_boolean(duk_context *ctx, duk_idx_t idx) {
}
}
-DUK_EXTERNAL duk_bool_t duk_opt_boolean(duk_context *ctx, duk_idx_t idx, duk_bool_t def_value) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_bool_t duk_opt_boolean(duk_hthread *thr, duk_idx_t idx, duk_bool_t def_value) {
+ DUK_ASSERT_API_ENTRY(thr);
- if (duk_check_type_mask(ctx, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) {
+ if (duk_check_type_mask(thr, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) {
return def_value;
}
- return duk_require_boolean(ctx, idx);
+ return duk_require_boolean(thr, idx);
}
-DUK_LOCAL DUK_ALWAYS_INLINE duk_double_t duk__get_number_raw(duk_context *ctx, duk_idx_t idx, duk_double_t def_value) {
+DUK_LOCAL DUK_ALWAYS_INLINE duk_double_t duk__get_number_raw(duk_hthread *thr, duk_idx_t idx, duk_double_t def_value) {
duk_double_union ret;
duk_tval *tv;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_CTX_VALID(thr);
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
#if defined(DUK_USE_FASTINT)
if (DUK_TVAL_IS_FASTINT(tv)) {
@@ -18027,22 +18643,23 @@ DUK_LOCAL DUK_ALWAYS_INLINE duk_double_t duk__get_number_raw(duk_context *ctx, d
return ret.d;
}
-DUK_EXTERNAL duk_double_t duk_get_number(duk_context *ctx, duk_idx_t idx) {
- return duk__get_number_raw(ctx, idx, DUK_DOUBLE_NAN); /* default: NaN */
+DUK_EXTERNAL duk_double_t duk_get_number(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk__get_number_raw(thr, idx, DUK_DOUBLE_NAN); /* default: NaN */
}
-DUK_EXTERNAL duk_double_t duk_get_number_default(duk_context *ctx, duk_idx_t idx, duk_double_t def_value) {
- return duk__get_number_raw(ctx, idx, def_value);
+DUK_EXTERNAL duk_double_t duk_get_number_default(duk_hthread *thr, duk_idx_t idx, duk_double_t def_value) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk__get_number_raw(thr, idx, def_value);
}
-DUK_EXTERNAL duk_double_t duk_require_number(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_double_t duk_require_number(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
duk_double_union ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
if (DUK_UNLIKELY(!DUK_TVAL_IS_NUMBER(tv))) {
DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, "number", DUK_STR_NOT_NUMBER);
@@ -18058,78 +18675,78 @@ DUK_EXTERNAL duk_double_t duk_require_number(duk_context *ctx, duk_idx_t idx) {
return ret.d;
}
-DUK_EXTERNAL duk_double_t duk_opt_number(duk_context *ctx, duk_idx_t idx, duk_double_t def_value) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_double_t duk_opt_number(duk_hthread *thr, duk_idx_t idx, duk_double_t def_value) {
+ DUK_ASSERT_API_ENTRY(thr);
- if (duk_check_type_mask(ctx, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) {
+ if (duk_check_type_mask(thr, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) {
/* User provided default is not NaN normalized. */
return def_value;
}
- return duk_require_number(ctx, idx);
+ return duk_require_number(thr, idx);
}
-DUK_EXTERNAL duk_int_t duk_get_int(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_int_t duk_get_int(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
- return (duk_int_t) duk__api_coerce_d2i(ctx, idx, 0 /*def_value*/, 0 /*require*/);
+ return (duk_int_t) duk__api_coerce_d2i(thr, idx, 0 /*def_value*/, 0 /*require*/);
}
-DUK_EXTERNAL duk_uint_t duk_get_uint(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_uint_t duk_get_uint(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
- return (duk_uint_t) duk__api_coerce_d2ui(ctx, idx, 0 /*def_value*/, 0 /*require*/);
+ return (duk_uint_t) duk__api_coerce_d2ui(thr, idx, 0 /*def_value*/, 0 /*require*/);
}
-DUK_EXTERNAL duk_int_t duk_get_int_default(duk_context *ctx, duk_idx_t idx, duk_int_t def_value) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_int_t duk_get_int_default(duk_hthread *thr, duk_idx_t idx, duk_int_t def_value) {
+ DUK_ASSERT_API_ENTRY(thr);
- return (duk_int_t) duk__api_coerce_d2i(ctx, idx, def_value, 0 /*require*/);
+ return (duk_int_t) duk__api_coerce_d2i(thr, idx, def_value, 0 /*require*/);
}
-DUK_EXTERNAL duk_uint_t duk_get_uint_default(duk_context *ctx, duk_idx_t idx, duk_uint_t def_value) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_uint_t duk_get_uint_default(duk_hthread *thr, duk_idx_t idx, duk_uint_t def_value) {
+ DUK_ASSERT_API_ENTRY(thr);
- return (duk_uint_t) duk__api_coerce_d2ui(ctx, idx, def_value, 0 /*require*/);
+ return (duk_uint_t) duk__api_coerce_d2ui(thr, idx, def_value, 0 /*require*/);
}
-DUK_EXTERNAL duk_int_t duk_require_int(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_int_t duk_require_int(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
- return (duk_int_t) duk__api_coerce_d2i(ctx, idx, 0 /*def_value*/, 1 /*require*/);
+ return (duk_int_t) duk__api_coerce_d2i(thr, idx, 0 /*def_value*/, 1 /*require*/);
}
-DUK_EXTERNAL duk_uint_t duk_require_uint(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_uint_t duk_require_uint(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
- return (duk_uint_t) duk__api_coerce_d2ui(ctx, idx, 0 /*def_value*/, 1 /*require*/);
+ return (duk_uint_t) duk__api_coerce_d2ui(thr, idx, 0 /*def_value*/, 1 /*require*/);
}
-DUK_EXTERNAL duk_int_t duk_opt_int(duk_context *ctx, duk_idx_t idx, duk_int_t def_value) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_int_t duk_opt_int(duk_hthread *thr, duk_idx_t idx, duk_int_t def_value) {
+ DUK_ASSERT_API_ENTRY(thr);
- if (duk_check_type_mask(ctx, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) {
+ if (duk_check_type_mask(thr, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) {
return def_value;
}
- return duk_require_int(ctx, idx);
+ return duk_require_int(thr, idx);
}
-DUK_EXTERNAL duk_uint_t duk_opt_uint(duk_context *ctx, duk_idx_t idx, duk_uint_t def_value) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_uint_t duk_opt_uint(duk_hthread *thr, duk_idx_t idx, duk_uint_t def_value) {
+ DUK_ASSERT_API_ENTRY(thr);
- if (duk_check_type_mask(ctx, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) {
+ if (duk_check_type_mask(thr, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) {
return def_value;
}
- return duk_require_uint(ctx, idx);
+ return duk_require_uint(thr, idx);
}
-DUK_EXTERNAL const char *duk_get_lstring(duk_context *ctx, duk_idx_t idx, duk_size_t *out_len) {
+DUK_EXTERNAL const char *duk_get_lstring(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_len) {
duk_hstring *h;
const char *ret;
duk_size_t len;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- h = duk_get_hstring(ctx, idx);
+ h = duk_get_hstring(thr, idx);
if (h != NULL) {
len = DUK_HSTRING_GET_BYTELEN(h);
ret = (const char *) DUK_HSTRING_GET_DATA(h);
@@ -18144,12 +18761,12 @@ DUK_EXTERNAL const char *duk_get_lstring(duk_context *ctx, duk_idx_t idx, duk_si
return ret;
}
-DUK_EXTERNAL const char *duk_require_lstring(duk_context *ctx, duk_idx_t idx, duk_size_t *out_len) {
+DUK_EXTERNAL const char *duk_require_lstring(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_len) {
duk_hstring *h;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- h = duk_require_hstring(ctx, idx);
+ h = duk_require_hstring(thr, idx);
DUK_ASSERT(h != NULL);
if (out_len) {
*out_len = DUK_HSTRING_GET_BYTELEN(h);
@@ -18157,12 +18774,12 @@ DUK_EXTERNAL const char *duk_require_lstring(duk_context *ctx, duk_idx_t idx, du
return (const char *) DUK_HSTRING_GET_DATA(h);
}
-DUK_INTERNAL const char *duk_require_lstring_notsymbol(duk_context *ctx, duk_idx_t idx, duk_size_t *out_len) {
+DUK_INTERNAL const char *duk_require_lstring_notsymbol(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_len) {
duk_hstring *h;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- h = duk_require_hstring_notsymbol(ctx, idx);
+ h = duk_require_hstring_notsymbol(thr, idx);
DUK_ASSERT(h != NULL);
if (out_len) {
*out_len = DUK_HSTRING_GET_BYTELEN(h);
@@ -18170,12 +18787,12 @@ DUK_INTERNAL const char *duk_require_lstring_notsymbol(duk_context *ctx, duk_idx
return (const char *) DUK_HSTRING_GET_DATA(h);
}
-DUK_EXTERNAL const char *duk_get_string(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL const char *duk_get_string(duk_hthread *thr, duk_idx_t idx) {
duk_hstring *h;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- h = duk_get_hstring(ctx, idx);
+ h = duk_get_hstring(thr, idx);
if (h != NULL) {
return (const char *) DUK_HSTRING_GET_DATA(h);
} else {
@@ -18183,35 +18800,35 @@ DUK_EXTERNAL const char *duk_get_string(duk_context *ctx, duk_idx_t idx) {
}
}
-DUK_EXTERNAL const char *duk_opt_lstring(duk_context *ctx, duk_idx_t idx, duk_size_t *out_len, const char *def_ptr, duk_size_t def_len) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL const char *duk_opt_lstring(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_len, const char *def_ptr, duk_size_t def_len) {
+ DUK_ASSERT_API_ENTRY(thr);
- if (duk_check_type_mask(ctx, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) {
+ if (duk_check_type_mask(thr, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) {
if (out_len != NULL) {
*out_len = def_len;
}
return def_ptr;
}
- return duk_require_lstring(ctx, idx, out_len);
+ return duk_require_lstring(thr, idx, out_len);
}
-DUK_EXTERNAL const char *duk_opt_string(duk_context *ctx, duk_idx_t idx, const char *def_ptr) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL const char *duk_opt_string(duk_hthread *thr, duk_idx_t idx, const char *def_ptr) {
+ DUK_ASSERT_API_ENTRY(thr);
- if (duk_check_type_mask(ctx, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) {
+ if (duk_check_type_mask(thr, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) {
return def_ptr;
}
- return duk_require_string(ctx, idx);
+ return duk_require_string(thr, idx);
}
-DUK_EXTERNAL const char *duk_get_lstring_default(duk_context *ctx, duk_idx_t idx, duk_size_t *out_len, const char *def_ptr, duk_size_t def_len) {
+DUK_EXTERNAL const char *duk_get_lstring_default(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_len, const char *def_ptr, duk_size_t def_len) {
duk_hstring *h;
const char *ret;
duk_size_t len;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- h = duk_get_hstring(ctx, idx);
+ h = duk_get_hstring(thr, idx);
if (h != NULL) {
len = DUK_HSTRING_GET_BYTELEN(h);
ret = (const char *) DUK_HSTRING_GET_DATA(h);
@@ -18226,12 +18843,12 @@ DUK_EXTERNAL const char *duk_get_lstring_default(duk_context *ctx, duk_idx_t idx
return ret;
}
-DUK_EXTERNAL const char *duk_get_string_default(duk_context *ctx, duk_idx_t idx, const char *def_value) {
+DUK_EXTERNAL const char *duk_get_string_default(duk_hthread *thr, duk_idx_t idx, const char *def_value) {
duk_hstring *h;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- h = duk_get_hstring(ctx, idx);
+ h = duk_get_hstring(thr, idx);
if (h != NULL) {
return (const char *) DUK_HSTRING_GET_DATA(h);
} else {
@@ -18239,12 +18856,12 @@ DUK_EXTERNAL const char *duk_get_string_default(duk_context *ctx, duk_idx_t idx,
}
}
-DUK_INTERNAL const char *duk_get_string_notsymbol(duk_context *ctx, duk_idx_t idx) {
+DUK_INTERNAL const char *duk_get_string_notsymbol(duk_hthread *thr, duk_idx_t idx) {
duk_hstring *h;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- h = duk_get_hstring_notsymbol(ctx, idx);
+ h = duk_get_hstring_notsymbol(thr, idx);
if (h) {
return (const char *) DUK_HSTRING_GET_DATA(h);
} else {
@@ -18252,29 +18869,41 @@ DUK_INTERNAL const char *duk_get_string_notsymbol(duk_context *ctx, duk_idx_t id
}
}
-DUK_EXTERNAL const char *duk_require_string(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL const char *duk_require_string(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
- return duk_require_lstring(ctx, idx, NULL);
+ return duk_require_lstring(thr, idx, NULL);
}
-DUK_INTERNAL const char *duk_require_string_notsymbol(duk_context *ctx, duk_idx_t idx) {
+DUK_INTERNAL const char *duk_require_string_notsymbol(duk_hthread *thr, duk_idx_t idx) {
duk_hstring *h;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- h = duk_require_hstring_notsymbol(ctx, idx);
+ h = duk_require_hstring_notsymbol(thr, idx);
DUK_ASSERT(h != NULL);
return (const char *) DUK_HSTRING_GET_DATA(h);
}
-DUK_LOCAL void *duk__get_pointer_raw(duk_context *ctx, duk_idx_t idx, void *def_value) {
+DUK_EXTERNAL void duk_require_object(duk_hthread *thr, duk_idx_t idx) {
+ duk_tval *tv;
+
+ DUK_ASSERT_API_ENTRY(thr);
+
+ tv = duk_get_tval_or_unused(thr, idx);
+ DUK_ASSERT(tv != NULL);
+ if (DUK_UNLIKELY(!DUK_TVAL_IS_OBJECT(tv))) {
+ DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, "object", DUK_STR_NOT_OBJECT);
+ }
+}
+
+DUK_LOCAL void *duk__get_pointer_raw(duk_hthread *thr, duk_idx_t idx, void *def_value) {
duk_tval *tv;
void *p;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_CTX_VALID(thr);
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
if (!DUK_TVAL_IS_POINTER(tv)) {
return def_value;
@@ -18284,34 +18913,35 @@ DUK_LOCAL void *duk__get_pointer_raw(duk_context *ctx, duk_idx_t idx, void *def_
return p;
}
-DUK_EXTERNAL void *duk_get_pointer(duk_context *ctx, duk_idx_t idx) {
- return duk__get_pointer_raw(ctx, idx, NULL /*def_value*/);
+DUK_EXTERNAL void *duk_get_pointer(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk__get_pointer_raw(thr, idx, NULL /*def_value*/);
}
-DUK_EXTERNAL void *duk_opt_pointer(duk_context *ctx, duk_idx_t idx, void *def_value) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL void *duk_opt_pointer(duk_hthread *thr, duk_idx_t idx, void *def_value) {
+ DUK_ASSERT_API_ENTRY(thr);
- if (duk_check_type_mask(ctx, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) {
+ if (duk_check_type_mask(thr, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) {
return def_value;
}
- return duk_require_pointer(ctx, idx);
+ return duk_require_pointer(thr, idx);
}
-DUK_EXTERNAL void *duk_get_pointer_default(duk_context *ctx, duk_idx_t idx, void *def_value) {
- return duk__get_pointer_raw(ctx, idx, def_value);
+DUK_EXTERNAL void *duk_get_pointer_default(duk_hthread *thr, duk_idx_t idx, void *def_value) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk__get_pointer_raw(thr, idx, def_value);
}
-DUK_EXTERNAL void *duk_require_pointer(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void *duk_require_pointer(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
void *p;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
/* Note: here we must be wary of the fact that a pointer may be
* valid and be a NULL.
*/
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
if (DUK_UNLIKELY(!DUK_TVAL_IS_POINTER(tv))) {
DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, "pointer", DUK_STR_NOT_POINTER);
@@ -18321,13 +18951,13 @@ DUK_EXTERNAL void *duk_require_pointer(duk_context *ctx, duk_idx_t idx) {
}
#if 0 /*unused*/
-DUK_INTERNAL void *duk_get_voidptr(duk_context *ctx, duk_idx_t idx) {
+DUK_INTERNAL void *duk_get_voidptr(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
duk_heaphdr *h;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
if (!DUK_TVAL_IS_HEAP_ALLOCATED(tv)) {
return NULL;
@@ -18339,21 +18969,19 @@ DUK_INTERNAL void *duk_get_voidptr(duk_context *ctx, duk_idx_t idx) {
}
#endif
-DUK_LOCAL void *duk__get_buffer_helper(duk_context *ctx, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_size, duk_bool_t throw_flag) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_LOCAL void *duk__get_buffer_helper(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_size, duk_bool_t throw_flag) {
duk_hbuffer *h;
void *ret;
duk_size_t len;
duk_tval *tv;
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_UNREF(thr);
+ DUK_ASSERT_CTX_VALID(thr);
if (out_size != NULL) {
*out_size = 0;
}
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
if (DUK_LIKELY(DUK_TVAL_IS_BUFFER(tv))) {
h = DUK_TVAL_GET_BUFFER(tv);
@@ -18375,34 +19003,34 @@ DUK_LOCAL void *duk__get_buffer_helper(duk_context *ctx, duk_idx_t idx, duk_size
return ret;
}
-DUK_EXTERNAL void *duk_get_buffer(duk_context *ctx, duk_idx_t idx, duk_size_t *out_size) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL void *duk_get_buffer(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size) {
+ DUK_ASSERT_API_ENTRY(thr);
- return duk__get_buffer_helper(ctx, idx, out_size, NULL /*def_ptr*/, 0 /*def_size*/, 0 /*throw_flag*/);
+ return duk__get_buffer_helper(thr, idx, out_size, NULL /*def_ptr*/, 0 /*def_size*/, 0 /*throw_flag*/);
}
-DUK_EXTERNAL void *duk_opt_buffer(duk_context *ctx, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_size) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL void *duk_opt_buffer(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_size) {
+ DUK_ASSERT_API_ENTRY(thr);
- if (duk_check_type_mask(ctx, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) {
+ if (duk_check_type_mask(thr, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) {
if (out_size != NULL) {
*out_size = def_size;
}
return def_ptr;
}
- return duk_require_buffer(ctx, idx, out_size);
+ return duk_require_buffer(thr, idx, out_size);
}
-DUK_EXTERNAL void *duk_get_buffer_default(duk_context *ctx, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_len) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL void *duk_get_buffer_default(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_len) {
+ DUK_ASSERT_API_ENTRY(thr);
- return duk__get_buffer_helper(ctx, idx, out_size, def_ptr, def_len, 0 /*throw_flag*/);
+ return duk__get_buffer_helper(thr, idx, out_size, def_ptr, def_len, 0 /*throw_flag*/);
}
-DUK_EXTERNAL void *duk_require_buffer(duk_context *ctx, duk_idx_t idx, duk_size_t *out_size) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL void *duk_require_buffer(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size) {
+ DUK_ASSERT_API_ENTRY(thr);
- return duk__get_buffer_helper(ctx, idx, out_size, NULL /*def_ptr*/, 0 /*def_size*/, 1 /*throw_flag*/);
+ return duk__get_buffer_helper(thr, idx, out_size, NULL /*def_ptr*/, 0 /*def_size*/, 1 /*throw_flag*/);
}
/* Get the active buffer data area for a plain buffer or a buffer object.
@@ -18410,12 +19038,10 @@ DUK_EXTERNAL void *duk_require_buffer(duk_context *ctx, duk_idx_t idx, duk_size_
* have a NULL data pointer when its size is zero, the optional 'out_isbuffer'
* argument allows caller to detect this reliably.
*/
-DUK_INTERNAL void *duk_get_buffer_data_raw(duk_context *ctx, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_size, duk_bool_t throw_flag, duk_bool_t *out_isbuffer) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_INTERNAL void *duk_get_buffer_data_raw(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_size, duk_bool_t throw_flag, duk_bool_t *out_isbuffer) {
duk_tval *tv;
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_UNREF(thr);
+ DUK_ASSERT_API_ENTRY(thr);
if (out_isbuffer != NULL) {
*out_isbuffer = 0;
@@ -18424,7 +19050,7 @@ DUK_INTERNAL void *duk_get_buffer_data_raw(duk_context *ctx, duk_idx_t idx, duk_
*out_size = def_size;
}
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
if (DUK_TVAL_IS_BUFFER(tv)) {
@@ -18473,28 +19099,31 @@ DUK_INTERNAL void *duk_get_buffer_data_raw(duk_context *ctx, duk_idx_t idx, duk_
return def_ptr;
}
-DUK_EXTERNAL void *duk_get_buffer_data(duk_context *ctx, duk_idx_t idx, duk_size_t *out_size) {
- return duk_get_buffer_data_raw(ctx, idx, out_size, NULL /*def_ptr*/, 0 /*def_size*/, 0 /*throw_flag*/, NULL);
+DUK_EXTERNAL void *duk_get_buffer_data(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk_get_buffer_data_raw(thr, idx, out_size, NULL /*def_ptr*/, 0 /*def_size*/, 0 /*throw_flag*/, NULL);
}
-DUK_EXTERNAL void *duk_get_buffer_data_default(duk_context *ctx, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_size) {
- return duk_get_buffer_data_raw(ctx, idx, out_size, def_ptr, def_size, 0 /*throw_flag*/, NULL);
+DUK_EXTERNAL void *duk_get_buffer_data_default(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_size) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk_get_buffer_data_raw(thr, idx, out_size, def_ptr, def_size, 0 /*throw_flag*/, NULL);
}
-DUK_EXTERNAL void *duk_opt_buffer_data(duk_context *ctx, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_size) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL void *duk_opt_buffer_data(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, void *def_ptr, duk_size_t def_size) {
+ DUK_ASSERT_API_ENTRY(thr);
- if (duk_check_type_mask(ctx, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) {
+ if (duk_check_type_mask(thr, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) {
if (out_size != NULL) {
*out_size = def_size;
}
return def_ptr;
}
- return duk_require_buffer_data(ctx, idx, out_size);
+ return duk_require_buffer_data(thr, idx, out_size);
}
-DUK_EXTERNAL void *duk_require_buffer_data(duk_context *ctx, duk_idx_t idx, duk_size_t *out_size) {
- return duk_get_buffer_data_raw(ctx, idx, out_size, NULL /*def_ptr*/, 0 /*def_size*/, 1 /*throw_flag*/, NULL);
+DUK_EXTERNAL void *duk_require_buffer_data(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk_get_buffer_data_raw(thr, idx, out_size, NULL /*def_ptr*/, 0 /*def_size*/, 1 /*throw_flag*/, NULL);
}
/* Raw helper for getting a value from the stack, checking its tag.
@@ -18502,13 +19131,13 @@ DUK_EXTERNAL void *duk_require_buffer_data(duk_context *ctx, duk_idx_t idx, duk_
* tag in the packed representation.
*/
-DUK_LOCAL duk_heaphdr *duk__get_tagged_heaphdr_raw(duk_context *ctx, duk_idx_t idx, duk_uint_t tag) {
+DUK_LOCAL duk_heaphdr *duk__get_tagged_heaphdr_raw(duk_hthread *thr, duk_idx_t idx, duk_uint_t tag) {
duk_tval *tv;
duk_heaphdr *ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_CTX_VALID(thr);
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
if (DUK_TVAL_GET_TAG(tv) != tag) {
return (duk_heaphdr *) NULL;
@@ -18520,121 +19149,161 @@ DUK_LOCAL duk_heaphdr *duk__get_tagged_heaphdr_raw(duk_context *ctx, duk_idx_t i
}
-DUK_INTERNAL duk_hstring *duk_get_hstring(duk_context *ctx, duk_idx_t idx) {
- return (duk_hstring *) duk__get_tagged_heaphdr_raw(ctx, idx, DUK_TAG_STRING);
+DUK_INTERNAL duk_hstring *duk_get_hstring(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return (duk_hstring *) duk__get_tagged_heaphdr_raw(thr, idx, DUK_TAG_STRING);
}
-DUK_INTERNAL duk_hstring *duk_get_hstring_notsymbol(duk_context *ctx, duk_idx_t idx) {
- duk_hstring *res = (duk_hstring *) duk__get_tagged_heaphdr_raw(ctx, idx, DUK_TAG_STRING);
- if (DUK_UNLIKELY(res && DUK_HSTRING_HAS_SYMBOL(res))) {
+DUK_INTERNAL duk_hstring *duk_get_hstring_notsymbol(duk_hthread *thr, duk_idx_t idx) {
+ duk_hstring *h;
+
+ DUK_ASSERT_API_ENTRY(thr);
+
+ h = (duk_hstring *) duk__get_tagged_heaphdr_raw(thr, idx, DUK_TAG_STRING);
+ if (DUK_UNLIKELY(h && DUK_HSTRING_HAS_SYMBOL(h))) {
return NULL;
}
- return res;
+ return h;
}
-DUK_INTERNAL duk_hstring *duk_require_hstring(duk_context *ctx, duk_idx_t idx) {
+DUK_INTERNAL duk_hstring *duk_require_hstring(duk_hthread *thr, duk_idx_t idx) {
duk_hstring *h;
- h = (duk_hstring *) duk__get_tagged_heaphdr_raw(ctx, idx, DUK_TAG_STRING);
+
+ DUK_ASSERT_API_ENTRY(thr);
+
+ h = (duk_hstring *) duk__get_tagged_heaphdr_raw(thr, idx, DUK_TAG_STRING);
if (DUK_UNLIKELY(h == NULL)) {
- DUK_ERROR_REQUIRE_TYPE_INDEX(ctx, idx, "string", DUK_STR_NOT_STRING);
+ DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, "string", DUK_STR_NOT_STRING);
}
return h;
}
-DUK_INTERNAL duk_hstring *duk_require_hstring_notsymbol(duk_context *ctx, duk_idx_t idx) {
+DUK_INTERNAL duk_hstring *duk_require_hstring_notsymbol(duk_hthread *thr, duk_idx_t idx) {
duk_hstring *h;
- h = (duk_hstring *) duk__get_tagged_heaphdr_raw(ctx, idx, DUK_TAG_STRING);
+
+ DUK_ASSERT_API_ENTRY(thr);
+
+ h = (duk_hstring *) duk__get_tagged_heaphdr_raw(thr, idx, DUK_TAG_STRING);
if (DUK_UNLIKELY(h == NULL || DUK_HSTRING_HAS_SYMBOL(h))) {
- DUK_ERROR_REQUIRE_TYPE_INDEX(ctx, idx, "string", DUK_STR_NOT_STRING);
+ DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, "string", DUK_STR_NOT_STRING);
}
return h;
}
-DUK_INTERNAL duk_hobject *duk_get_hobject(duk_context *ctx, duk_idx_t idx) {
- return (duk_hobject *) duk__get_tagged_heaphdr_raw(ctx, idx, DUK_TAG_OBJECT);
+DUK_INTERNAL duk_hobject *duk_get_hobject(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return (duk_hobject *) duk__get_tagged_heaphdr_raw(thr, idx, DUK_TAG_OBJECT);
}
-DUK_INTERNAL duk_hobject *duk_require_hobject(duk_context *ctx, duk_idx_t idx) {
+DUK_INTERNAL duk_hobject *duk_require_hobject(duk_hthread *thr, duk_idx_t idx) {
duk_hobject *h;
- h = (duk_hobject *) duk__get_tagged_heaphdr_raw(ctx, idx, DUK_TAG_OBJECT);
+
+ DUK_ASSERT_API_ENTRY(thr);
+
+ h = (duk_hobject *) duk__get_tagged_heaphdr_raw(thr, idx, DUK_TAG_OBJECT);
if (DUK_UNLIKELY(h == NULL)) {
- DUK_ERROR_REQUIRE_TYPE_INDEX(ctx, idx, "object", DUK_STR_NOT_OBJECT);
+ DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, "object", DUK_STR_NOT_OBJECT);
}
return h;
}
-DUK_INTERNAL duk_hbuffer *duk_get_hbuffer(duk_context *ctx, duk_idx_t idx) {
- return (duk_hbuffer *) duk__get_tagged_heaphdr_raw(ctx, idx, DUK_TAG_BUFFER);
+DUK_INTERNAL duk_hbuffer *duk_get_hbuffer(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return (duk_hbuffer *) duk__get_tagged_heaphdr_raw(thr, idx, DUK_TAG_BUFFER);
}
-DUK_INTERNAL duk_hbuffer *duk_require_hbuffer(duk_context *ctx, duk_idx_t idx) {
+DUK_INTERNAL duk_hbuffer *duk_require_hbuffer(duk_hthread *thr, duk_idx_t idx) {
duk_hbuffer *h;
- h = (duk_hbuffer *) duk__get_tagged_heaphdr_raw(ctx, idx, DUK_TAG_BUFFER);
+
+ DUK_ASSERT_API_ENTRY(thr);
+
+ h = (duk_hbuffer *) duk__get_tagged_heaphdr_raw(thr, idx, DUK_TAG_BUFFER);
if (DUK_UNLIKELY(h == NULL)) {
- DUK_ERROR_REQUIRE_TYPE_INDEX(ctx, idx, "buffer", DUK_STR_NOT_BUFFER);
+ DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, "buffer", DUK_STR_NOT_BUFFER);
}
return h;
}
-DUK_INTERNAL duk_hthread *duk_get_hthread(duk_context *ctx, duk_idx_t idx) {
- duk_hobject *h = (duk_hobject *) duk__get_tagged_heaphdr_raw(ctx, idx, DUK_TAG_OBJECT);
+DUK_INTERNAL duk_hthread *duk_get_hthread(duk_hthread *thr, duk_idx_t idx) {
+ duk_hobject *h;
+
+ DUK_ASSERT_API_ENTRY(thr);
+
+ h = (duk_hobject *) duk__get_tagged_heaphdr_raw(thr, idx, DUK_TAG_OBJECT);
if (DUK_UNLIKELY(h != NULL && !DUK_HOBJECT_IS_THREAD(h))) {
h = NULL;
}
return (duk_hthread *) h;
}
-DUK_INTERNAL duk_hthread *duk_require_hthread(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
- duk_hobject *h = (duk_hobject *) duk__get_tagged_heaphdr_raw(ctx, idx, DUK_TAG_OBJECT);
+DUK_INTERNAL duk_hthread *duk_require_hthread(duk_hthread *thr, duk_idx_t idx) {
+ duk_hobject *h;
+
+ DUK_ASSERT_API_ENTRY(thr);
+
+ h = (duk_hobject *) duk__get_tagged_heaphdr_raw(thr, idx, DUK_TAG_OBJECT);
if (DUK_UNLIKELY(!(h != NULL && DUK_HOBJECT_IS_THREAD(h)))) {
DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, "thread", DUK_STR_NOT_THREAD);
}
return (duk_hthread *) h;
}
-DUK_INTERNAL duk_hcompfunc *duk_get_hcompfunc(duk_context *ctx, duk_idx_t idx) {
- duk_hobject *h = (duk_hobject *) duk__get_tagged_heaphdr_raw(ctx, idx, DUK_TAG_OBJECT);
+DUK_INTERNAL duk_hcompfunc *duk_get_hcompfunc(duk_hthread *thr, duk_idx_t idx) {
+ duk_hobject *h;
+
+ DUK_ASSERT_API_ENTRY(thr);
+
+ h = (duk_hobject *) duk__get_tagged_heaphdr_raw(thr, idx, DUK_TAG_OBJECT);
if (DUK_UNLIKELY(h != NULL && !DUK_HOBJECT_IS_COMPFUNC(h))) {
h = NULL;
}
return (duk_hcompfunc *) h;
}
-DUK_INTERNAL duk_hcompfunc *duk_require_hcompfunc(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
- duk_hobject *h = (duk_hobject *) duk__get_tagged_heaphdr_raw(ctx, idx, DUK_TAG_OBJECT);
+DUK_INTERNAL duk_hcompfunc *duk_require_hcompfunc(duk_hthread *thr, duk_idx_t idx) {
+ duk_hobject *h;
+
+ DUK_ASSERT_API_ENTRY(thr);
+
+ h = (duk_hobject *) duk__get_tagged_heaphdr_raw(thr, idx, DUK_TAG_OBJECT);
if (DUK_UNLIKELY(!(h != NULL && DUK_HOBJECT_IS_COMPFUNC(h)))) {
DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, "compiledfunction", DUK_STR_NOT_COMPFUNC);
}
return (duk_hcompfunc *) h;
}
-DUK_INTERNAL duk_hnatfunc *duk_get_hnatfunc(duk_context *ctx, duk_idx_t idx) {
- duk_hobject *h = (duk_hobject *) duk__get_tagged_heaphdr_raw(ctx, idx, DUK_TAG_OBJECT);
+DUK_INTERNAL duk_hnatfunc *duk_get_hnatfunc(duk_hthread *thr, duk_idx_t idx) {
+ duk_hobject *h;
+
+ DUK_ASSERT_API_ENTRY(thr);
+
+ h = (duk_hobject *) duk__get_tagged_heaphdr_raw(thr, idx, DUK_TAG_OBJECT);
if (DUK_UNLIKELY(h != NULL && !DUK_HOBJECT_IS_NATFUNC(h))) {
h = NULL;
}
return (duk_hnatfunc *) h;
}
-DUK_INTERNAL duk_hnatfunc *duk_require_hnatfunc(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
- duk_hobject *h = (duk_hobject *) duk__get_tagged_heaphdr_raw(ctx, idx, DUK_TAG_OBJECT);
+DUK_INTERNAL duk_hnatfunc *duk_require_hnatfunc(duk_hthread *thr, duk_idx_t idx) {
+ duk_hobject *h;
+
+ DUK_ASSERT_API_ENTRY(thr);
+
+ h = (duk_hobject *) duk__get_tagged_heaphdr_raw(thr, idx, DUK_TAG_OBJECT);
if (DUK_UNLIKELY(!(h != NULL && DUK_HOBJECT_IS_NATFUNC(h)))) {
DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, "nativefunction", DUK_STR_NOT_NATFUNC);
}
return (duk_hnatfunc *) h;
}
-DUK_EXTERNAL duk_c_function duk_get_c_function(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL duk_c_function duk_get_c_function(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
duk_hobject *h;
duk_hnatfunc *f;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
if (DUK_UNLIKELY(!DUK_TVAL_IS_OBJECT(tv))) {
return NULL;
@@ -18651,21 +19320,21 @@ DUK_EXTERNAL duk_c_function duk_get_c_function(duk_context *ctx, duk_idx_t idx)
return f->func;
}
-DUK_EXTERNAL duk_c_function duk_opt_c_function(duk_context *ctx, duk_idx_t idx, duk_c_function def_value) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_c_function duk_opt_c_function(duk_hthread *thr, duk_idx_t idx, duk_c_function def_value) {
+ DUK_ASSERT_API_ENTRY(thr);
- if (duk_check_type_mask(ctx, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) {
+ if (duk_check_type_mask(thr, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) {
return def_value;
}
- return duk_require_c_function(ctx, idx);
+ return duk_require_c_function(thr, idx);
}
-DUK_EXTERNAL duk_c_function duk_get_c_function_default(duk_context *ctx, duk_idx_t idx, duk_c_function def_value) {
+DUK_EXTERNAL duk_c_function duk_get_c_function_default(duk_hthread *thr, duk_idx_t idx, duk_c_function def_value) {
duk_c_function ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- ret = duk_get_c_function(ctx, idx);
+ ret = duk_get_c_function(thr, idx);
if (ret != NULL) {
return ret;
}
@@ -18673,62 +19342,64 @@ DUK_EXTERNAL duk_c_function duk_get_c_function_default(duk_context *ctx, duk_idx
return def_value;
}
-DUK_EXTERNAL duk_c_function duk_require_c_function(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_c_function duk_require_c_function(duk_hthread *thr, duk_idx_t idx) {
duk_c_function ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- ret = duk_get_c_function(ctx, idx);
+ ret = duk_get_c_function(thr, idx);
if (DUK_UNLIKELY(!ret)) {
DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, "nativefunction", DUK_STR_NOT_NATFUNC);
}
return ret;
}
-DUK_EXTERNAL void duk_require_function(duk_context *ctx, duk_idx_t idx) {
- if (DUK_UNLIKELY(!duk_is_function(ctx, idx))) {
- DUK_ERROR_REQUIRE_TYPE_INDEX((duk_hthread *) ctx, idx, "function", DUK_STR_NOT_FUNCTION);
+DUK_EXTERNAL void duk_require_function(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+ if (DUK_UNLIKELY(!duk_is_function(thr, idx))) {
+ DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, "function", DUK_STR_NOT_FUNCTION);
}
}
-DUK_INTERNAL_DECL void duk_require_constructable(duk_context *ctx, duk_idx_t idx) {
+DUK_INTERNAL void duk_require_constructable(duk_hthread *thr, duk_idx_t idx) {
duk_hobject *h;
- h = duk_require_hobject_accept_mask(ctx, idx, DUK_TYPE_MASK_LIGHTFUNC);
+ DUK_ASSERT_API_ENTRY(thr);
+
+ h = duk_require_hobject_accept_mask(thr, idx, DUK_TYPE_MASK_LIGHTFUNC);
if (DUK_UNLIKELY(h != NULL && !DUK_HOBJECT_HAS_CONSTRUCTABLE(h))) {
- DUK_ERROR_REQUIRE_TYPE_INDEX((duk_hthread *) ctx, idx, "constructable", DUK_STR_NOT_CONSTRUCTABLE);
+ DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, "constructable", DUK_STR_NOT_CONSTRUCTABLE);
}
/* Lightfuncs (h == NULL) are constructable. */
}
-DUK_EXTERNAL duk_context *duk_get_context(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_hthread *duk_get_context(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
- return (duk_context *) duk_get_hthread(ctx, idx);
+ return duk_get_hthread(thr, idx);
}
-DUK_EXTERNAL duk_context *duk_require_context(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_hthread *duk_require_context(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
- return (duk_context *) duk_require_hthread(ctx, idx);
+ return duk_require_hthread(thr, idx);
}
-DUK_EXTERNAL duk_context *duk_opt_context(duk_context *ctx, duk_idx_t idx, duk_context *def_value) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_hthread *duk_opt_context(duk_hthread *thr, duk_idx_t idx, duk_hthread *def_value) {
+ DUK_ASSERT_API_ENTRY(thr);
- if (duk_check_type_mask(ctx, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) {
+ if (duk_check_type_mask(thr, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) {
return def_value;
}
- return duk_require_context(ctx, idx);
+ return duk_require_context(thr, idx);
}
-DUK_EXTERNAL_DECL duk_context *duk_get_context_default(duk_context *ctx, duk_idx_t idx, duk_context *def_value) {
- duk_context *ret;
+DUK_EXTERNAL duk_hthread *duk_get_context_default(duk_hthread *thr, duk_idx_t idx, duk_hthread *def_value) {
+ duk_hthread *ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- ret = duk_get_context(ctx, idx);
+ ret = duk_get_context(thr, idx);
if (ret != NULL) {
return ret;
}
@@ -18736,13 +19407,13 @@ DUK_EXTERNAL_DECL duk_context *duk_get_context_default(duk_context *ctx, duk_idx
return def_value;
}
-DUK_EXTERNAL void *duk_get_heapptr(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL void *duk_get_heapptr(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
void *ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
if (DUK_UNLIKELY(!DUK_TVAL_IS_HEAP_ALLOCATED(tv))) {
return (void *) NULL;
@@ -18753,21 +19424,21 @@ DUK_EXTERNAL void *duk_get_heapptr(duk_context *ctx, duk_idx_t idx) {
return ret;
}
-DUK_EXTERNAL void *duk_opt_heapptr(duk_context *ctx, duk_idx_t idx, void *def_value) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL void *duk_opt_heapptr(duk_hthread *thr, duk_idx_t idx, void *def_value) {
+ DUK_ASSERT_API_ENTRY(thr);
- if (duk_check_type_mask(ctx, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) {
+ if (duk_check_type_mask(thr, idx, DUK_TYPE_MASK_NONE | DUK_TYPE_MASK_UNDEFINED)) {
return def_value;
}
- return duk_require_heapptr(ctx, idx);
+ return duk_require_heapptr(thr, idx);
}
-DUK_EXTERNAL_DECL void *duk_get_heapptr_default(duk_context *ctx, duk_idx_t idx, void *def_value) {
+DUK_EXTERNAL void *duk_get_heapptr_default(duk_hthread *thr, duk_idx_t idx, void *def_value) {
void *ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- ret = duk_get_heapptr(ctx, idx);
+ ret = duk_get_heapptr(thr, idx);
if (ret != NULL) {
return ret;
}
@@ -18775,14 +19446,13 @@ DUK_EXTERNAL_DECL void *duk_get_heapptr_default(duk_context *ctx, duk_idx_t idx,
return def_value;
}
-DUK_EXTERNAL void *duk_require_heapptr(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void *duk_require_heapptr(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
void *ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
if (DUK_UNLIKELY(!DUK_TVAL_IS_HEAP_ALLOCATED(tv))) {
DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, "heapobject", DUK_STR_UNEXPECTED_TYPE);
@@ -18794,22 +19464,22 @@ DUK_EXTERNAL void *duk_require_heapptr(duk_context *ctx, duk_idx_t idx) {
}
/* Internal helper for getting/requiring a duk_hobject with possible promotion. */
-DUK_LOCAL duk_hobject *duk__get_hobject_promote_mask_raw(duk_context *ctx, duk_idx_t idx, duk_uint_t type_mask) {
+DUK_LOCAL duk_hobject *duk__get_hobject_promote_mask_raw(duk_hthread *thr, duk_idx_t idx, duk_uint_t type_mask) {
duk_uint_t val_mask;
duk_hobject *res;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_CTX_VALID(thr);
- res = duk_get_hobject(ctx, idx); /* common case, not promoted */
+ res = duk_get_hobject(thr, idx); /* common case, not promoted */
if (DUK_LIKELY(res != NULL)) {
DUK_ASSERT(res != NULL);
return res;
}
- val_mask = duk_get_type_mask(ctx, idx);
+ val_mask = duk_get_type_mask(thr, idx);
if (val_mask & type_mask) {
if (type_mask & DUK_TYPE_MASK_PROMOTE) {
- res = duk_to_hobject(ctx, idx);
+ res = duk_to_hobject(thr, idx);
DUK_ASSERT(res != NULL);
return res;
} else {
@@ -18818,7 +19488,7 @@ DUK_LOCAL duk_hobject *duk__get_hobject_promote_mask_raw(duk_context *ctx, duk_i
}
if (type_mask & DUK_TYPE_MASK_THROW) {
- DUK_ERROR_REQUIRE_TYPE_INDEX((duk_hthread *) ctx, idx, "object", DUK_STR_NOT_OBJECT);
+ DUK_ERROR_REQUIRE_TYPE_INDEX(thr, idx, "object", DUK_STR_NOT_OBJECT);
}
return NULL;
}
@@ -18830,48 +19500,49 @@ DUK_LOCAL duk_hobject *duk__get_hobject_promote_mask_raw(duk_context *ctx, duk_i
* Return value is NULL if value is neither an object nor a plain type allowed
* by the mask.
*/
-DUK_INTERNAL duk_hobject *duk_get_hobject_promote_mask(duk_context *ctx, duk_idx_t idx, duk_uint_t type_mask) {
- return duk__get_hobject_promote_mask_raw(ctx, idx, type_mask | DUK_TYPE_MASK_PROMOTE);
+DUK_INTERNAL duk_hobject *duk_get_hobject_promote_mask(duk_hthread *thr, duk_idx_t idx, duk_uint_t type_mask) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk__get_hobject_promote_mask_raw(thr, idx, type_mask | DUK_TYPE_MASK_PROMOTE);
}
/* Like duk_get_hobject_promote_mask() but throw a TypeError instead of
* returning a NULL.
*/
-DUK_INTERNAL duk_hobject *duk_require_hobject_promote_mask(duk_context *ctx, duk_idx_t idx, duk_uint_t type_mask) {
- return duk__get_hobject_promote_mask_raw(ctx, idx, type_mask | DUK_TYPE_MASK_THROW | DUK_TYPE_MASK_PROMOTE);
+DUK_INTERNAL duk_hobject *duk_require_hobject_promote_mask(duk_hthread *thr, duk_idx_t idx, duk_uint_t type_mask) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk__get_hobject_promote_mask_raw(thr, idx, type_mask | DUK_TYPE_MASK_THROW | DUK_TYPE_MASK_PROMOTE);
}
/* Require a duk_hobject * at 'idx'; if the value is not an object but matches the
* supplied 'type_mask', return a NULL instead. Otherwise throw a TypeError.
*/
-DUK_INTERNAL duk_hobject *duk_require_hobject_accept_mask(duk_context *ctx, duk_idx_t idx, duk_uint_t type_mask) {
- return duk__get_hobject_promote_mask_raw(ctx, idx, type_mask | DUK_TYPE_MASK_THROW);
+DUK_INTERNAL duk_hobject *duk_require_hobject_accept_mask(duk_hthread *thr, duk_idx_t idx, duk_uint_t type_mask) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk__get_hobject_promote_mask_raw(thr, idx, type_mask | DUK_TYPE_MASK_THROW);
}
-DUK_INTERNAL duk_hobject *duk_get_hobject_with_class(duk_context *ctx, duk_idx_t idx, duk_small_uint_t classnum) {
+DUK_INTERNAL duk_hobject *duk_get_hobject_with_class(duk_hthread *thr, duk_idx_t idx, duk_small_uint_t classnum) {
duk_hobject *h;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT_DISABLE(classnum >= 0); /* unsigned */
DUK_ASSERT(classnum <= DUK_HOBJECT_CLASS_MAX);
- h = (duk_hobject *) duk__get_tagged_heaphdr_raw(ctx, idx, DUK_TAG_OBJECT);
+ h = (duk_hobject *) duk__get_tagged_heaphdr_raw(thr, idx, DUK_TAG_OBJECT);
if (DUK_UNLIKELY(h != NULL && DUK_HOBJECT_GET_CLASS_NUMBER(h) != classnum)) {
h = NULL;
}
return h;
}
-DUK_INTERNAL duk_hobject *duk_require_hobject_with_class(duk_context *ctx, duk_idx_t idx, duk_small_uint_t classnum) {
- duk_hthread *thr;
+DUK_INTERNAL duk_hobject *duk_require_hobject_with_class(duk_hthread *thr, duk_idx_t idx, duk_small_uint_t classnum) {
duk_hobject *h;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT_DISABLE(classnum >= 0); /* unsigned */
DUK_ASSERT(classnum <= DUK_HOBJECT_CLASS_MAX);
- thr = (duk_hthread *) ctx;
- h = (duk_hobject *) duk__get_tagged_heaphdr_raw(ctx, idx, DUK_TAG_OBJECT);
+ h = (duk_hobject *) duk__get_tagged_heaphdr_raw(thr, idx, DUK_TAG_OBJECT);
if (DUK_UNLIKELY(!(h != NULL && DUK_HOBJECT_GET_CLASS_NUMBER(h) == classnum))) {
duk_hstring *h_class;
h_class = DUK_HTHREAD_GET_STRING(thr, DUK_HOBJECT_CLASS_NUMBER_TO_STRIDX(classnum));
@@ -18882,12 +19553,12 @@ DUK_INTERNAL duk_hobject *duk_require_hobject_with_class(duk_context *ctx, duk_i
return h;
}
-DUK_EXTERNAL duk_size_t duk_get_length(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL duk_size_t duk_get_length(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
switch (DUK_TVAL_GET_TAG(tv)) {
@@ -18897,17 +19568,20 @@ DUK_EXTERNAL duk_size_t duk_get_length(duk_context *ctx, duk_idx_t idx) {
case DUK_TAG_POINTER:
return 0;
#if defined(DUK_USE_PREFER_SIZE)
- /* All of these types (besides object) have a virtual, non-configurable
- * .length property which is within size_t range so we can just look it
- * up without specific type checks.
+ /* String and buffer have a virtual non-configurable .length property
+ * which is within size_t range so it can be looked up without specific
+ * type checks. Lightfuncs inherit from %NativeFunctionPrototype%
+ * which provides an inherited .length accessor; it could be overwritten
+ * to produce unexpected types or values, but just number convert and
+ * duk_size_t cast for now.
*/
case DUK_TAG_STRING:
case DUK_TAG_BUFFER:
case DUK_TAG_LIGHTFUNC: {
duk_size_t ret;
- duk_get_prop_stridx(ctx, idx, DUK_STRIDX_LENGTH);
- ret = (duk_size_t) duk_to_number_m1(ctx);
- duk_pop(ctx);
+ duk_get_prop_stridx(thr, idx, DUK_STRIDX_LENGTH);
+ ret = (duk_size_t) duk_to_number_m1(thr);
+ duk_pop_unsafe(thr);
return ret;
}
#else /* DUK_USE_PREFER_SIZE */
@@ -18925,15 +19599,22 @@ DUK_EXTERNAL duk_size_t duk_get_length(duk_context *ctx, duk_idx_t idx) {
return (duk_size_t) DUK_HBUFFER_GET_SIZE(h);
}
case DUK_TAG_LIGHTFUNC: {
- duk_small_uint_t lf_flags;
- lf_flags = DUK_TVAL_GET_LIGHTFUNC_FLAGS(tv);
- return (duk_size_t) DUK_LFUNC_FLAGS_GET_LENGTH(lf_flags);
+ /* We could look up the length from the lightfunc duk_tval,
+ * but since Duktape 2.2 lightfunc .length comes from
+ * %NativeFunctionPrototype% which can be overridden, so
+ * look up the property explicitly.
+ */
+ duk_size_t ret;
+ duk_get_prop_stridx(thr, idx, DUK_STRIDX_LENGTH);
+ ret = (duk_size_t) duk_to_number_m1(thr);
+ duk_pop_unsafe(thr);
+ return ret;
}
#endif /* DUK_USE_PREFER_SIZE */
case DUK_TAG_OBJECT: {
duk_hobject *h = DUK_TVAL_GET_OBJECT(tv);
DUK_ASSERT(h != NULL);
- return (duk_size_t) duk_hobject_get_length((duk_hthread *) ctx, h);
+ return (duk_size_t) duk_hobject_get_length(thr, h);
}
#if defined(DUK_USE_FASTINT)
case DUK_TAG_FASTINT:
@@ -18952,17 +19633,16 @@ DUK_EXTERNAL duk_size_t duk_get_length(duk_context *ctx, duk_idx_t idx) {
*
* Used internally when we're 100% sure that a certain index is valid and
* contains an object of a certain type. For example, if we duk_push_object()
- * we can then safely duk_known_hobject(ctx, -1). These helpers just assert
+ * we can then safely duk_known_hobject(thr, -1). These helpers just assert
* for the index and type, and if the assumptions are not valid, memory unsafe
* behavior happens.
*/
-DUK_LOCAL duk_heaphdr *duk__known_heaphdr(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_LOCAL duk_heaphdr *duk__known_heaphdr(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
duk_heaphdr *h;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_CTX_VALID(thr);
if (idx < 0) {
tv = thr->valstack_top + idx;
} else {
@@ -18975,37 +19655,42 @@ DUK_LOCAL duk_heaphdr *duk__known_heaphdr(duk_context *ctx, duk_idx_t idx) {
return h;
}
-DUK_INTERNAL duk_hstring *duk_known_hstring(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT(duk_get_hstring(ctx, idx) != NULL);
- return (duk_hstring *) duk__known_heaphdr(ctx, idx);
+DUK_INTERNAL duk_hstring *duk_known_hstring(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+ DUK_ASSERT(duk_get_hstring(thr, idx) != NULL);
+ return (duk_hstring *) duk__known_heaphdr(thr, idx);
}
-DUK_INTERNAL duk_hobject *duk_known_hobject(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT(duk_get_hobject(ctx, idx) != NULL);
- return (duk_hobject *) duk__known_heaphdr(ctx, idx);
+DUK_INTERNAL duk_hobject *duk_known_hobject(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+ DUK_ASSERT(duk_get_hobject(thr, idx) != NULL);
+ return (duk_hobject *) duk__known_heaphdr(thr, idx);
}
-DUK_INTERNAL duk_hbuffer *duk_known_hbuffer(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT(duk_get_hbuffer(ctx, idx) != NULL);
- return (duk_hbuffer *) duk__known_heaphdr(ctx, idx);
+DUK_INTERNAL duk_hbuffer *duk_known_hbuffer(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+ DUK_ASSERT(duk_get_hbuffer(thr, idx) != NULL);
+ return (duk_hbuffer *) duk__known_heaphdr(thr, idx);
}
-DUK_INTERNAL duk_hcompfunc *duk_known_hcompfunc(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT(duk_get_hcompfunc(ctx, idx) != NULL);
- return (duk_hcompfunc *) duk__known_heaphdr(ctx, idx);
+DUK_INTERNAL duk_hcompfunc *duk_known_hcompfunc(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+ DUK_ASSERT(duk_get_hcompfunc(thr, idx) != NULL);
+ return (duk_hcompfunc *) duk__known_heaphdr(thr, idx);
}
-DUK_INTERNAL duk_hnatfunc *duk_known_hnatfunc(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT(duk_get_hnatfunc(ctx, idx) != NULL);
- return (duk_hnatfunc *) duk__known_heaphdr(ctx, idx);
+DUK_INTERNAL duk_hnatfunc *duk_known_hnatfunc(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+ DUK_ASSERT(duk_get_hnatfunc(thr, idx) != NULL);
+ return (duk_hnatfunc *) duk__known_heaphdr(thr, idx);
}
-DUK_EXTERNAL void duk_set_length(duk_context *ctx, duk_idx_t idx, duk_size_t len) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL void duk_set_length(duk_hthread *thr, duk_idx_t idx, duk_size_t len) {
+ DUK_ASSERT_API_ENTRY(thr);
- idx = duk_normalize_index(ctx, idx);
- duk_push_uint(ctx, (duk_uint_t) len);
- duk_put_prop_stridx(ctx, idx, DUK_STRIDX_LENGTH);
+ idx = duk_normalize_index(thr, idx);
+ duk_push_uint(thr, (duk_uint_t) len);
+ duk_put_prop_stridx(thr, idx, DUK_STRIDX_LENGTH);
}
/*
@@ -19018,68 +19703,63 @@ DUK_EXTERNAL void duk_set_length(duk_context *ctx, duk_idx_t idx, duk_size_t len
/* E5 Section 8.12.8 */
-DUK_LOCAL duk_bool_t duk__defaultvalue_coerce_attempt(duk_context *ctx, duk_idx_t idx, duk_small_int_t func_stridx) {
- if (duk_get_prop_stridx(ctx, idx, func_stridx)) {
+DUK_LOCAL duk_bool_t duk__defaultvalue_coerce_attempt(duk_hthread *thr, duk_idx_t idx, duk_small_uint_t func_stridx) {
+ if (duk_get_prop_stridx(thr, idx, func_stridx)) {
/* [ ... func ] */
- if (duk_is_callable(ctx, -1)) {
- duk_dup(ctx, idx); /* -> [ ... func this ] */
- duk_call_method(ctx, 0); /* -> [ ... retval ] */
- if (duk_is_primitive(ctx, -1)) {
- duk_replace(ctx, idx);
+ if (duk_is_callable(thr, -1)) {
+ duk_dup(thr, idx); /* -> [ ... func this ] */
+ duk_call_method(thr, 0); /* -> [ ... retval ] */
+ if (duk_is_primitive(thr, -1)) {
+ duk_replace(thr, idx);
return 1;
}
/* [ ... retval ]; popped below */
}
}
- duk_pop(ctx); /* [ ... func/retval ] -> [ ... ] */
+ duk_pop_unsafe(thr); /* [ ... func/retval ] -> [ ... ] */
return 0;
}
-DUK_EXTERNAL void duk_to_undefined(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_to_undefined(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_UNREF(thr);
+ DUK_ASSERT_API_ENTRY(thr);
- tv = duk_require_tval(ctx, idx);
+ tv = duk_require_tval(thr, idx);
DUK_ASSERT(tv != NULL);
DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */
}
-DUK_EXTERNAL void duk_to_null(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_to_null(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_UNREF(thr);
+ DUK_ASSERT_API_ENTRY(thr);
- tv = duk_require_tval(ctx, idx);
+ tv = duk_require_tval(thr, idx);
DUK_ASSERT(tv != NULL);
DUK_TVAL_SET_NULL_UPDREF(thr, tv); /* side effects */
}
/* E5 Section 9.1 */
-DUK_EXTERNAL void duk_to_primitive(duk_context *ctx, duk_idx_t idx, duk_int_t hint) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_to_primitive(duk_hthread *thr, duk_idx_t idx, duk_int_t hint) {
/* inline initializer for coercers[] is not allowed by old compilers like BCC */
- duk_small_int_t coercers[2];
+ duk_small_uint_t coercers[2];
duk_small_uint_t class_number;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(hint == DUK_HINT_NONE || hint == DUK_HINT_NUMBER || hint == DUK_HINT_STRING);
- idx = duk_require_normalize_index(ctx, idx);
+ idx = duk_require_normalize_index(thr, idx);
- if (!duk_check_type_mask(ctx, idx, DUK_TYPE_MASK_OBJECT |
+ if (!duk_check_type_mask(thr, idx, DUK_TYPE_MASK_OBJECT |
DUK_TYPE_MASK_LIGHTFUNC |
DUK_TYPE_MASK_BUFFER)) {
/* Any other values stay as is. */
- DUK_ASSERT(!duk_is_buffer(ctx, idx)); /* duk_to_string() relies on this behavior */
+ DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */
return;
}
- class_number = duk_get_class_number(ctx, idx);
+ class_number = duk_get_class_number(thr, idx);
/* XXX: Symbol objects normally coerce via the ES2015-revised ToPrimitive()
* algorithm which consults value[@@toPrimitive] and avoids calling
@@ -19094,11 +19774,11 @@ DUK_EXTERNAL void duk_to_primitive(duk_context *ctx, duk_idx_t idx, duk_int_t hi
duk_hstring *h_str;
/* XXX: pretty awkward, index based API for internal value access? */
- h_obj = duk_known_hobject(ctx, idx);
+ h_obj = duk_known_hobject(thr, idx);
h_str = duk_hobject_get_internal_value_string(thr->heap, h_obj);
if (h_str) {
- duk_push_hstring(ctx, h_str);
- duk_replace(ctx, idx);
+ duk_push_hstring(thr, h_str);
+ duk_replace(thr, idx);
return;
}
}
@@ -19127,13 +19807,13 @@ DUK_EXTERNAL void duk_to_primitive(duk_context *ctx, duk_idx_t idx, duk_int_t hi
coercers[1] = DUK_STRIDX_VALUE_OF;
}
- if (duk__defaultvalue_coerce_attempt(ctx, idx, coercers[0])) {
- DUK_ASSERT(!duk_is_buffer(ctx, idx)); /* duk_to_string() relies on this behavior */
+ if (duk__defaultvalue_coerce_attempt(thr, idx, coercers[0])) {
+ DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */
return;
}
- if (duk__defaultvalue_coerce_attempt(ctx, idx, coercers[1])) {
- DUK_ASSERT(!duk_is_buffer(ctx, idx)); /* duk_to_string() relies on this behavior */
+ if (duk__defaultvalue_coerce_attempt(thr, idx, coercers[1])) {
+ DUK_ASSERT(!duk_is_buffer(thr, idx)); /* duk_to_string() relies on this behavior */
return;
}
@@ -19141,16 +19821,14 @@ DUK_EXTERNAL void duk_to_primitive(duk_context *ctx, duk_idx_t idx, duk_int_t hi
}
/* E5 Section 9.2 */
-DUK_EXTERNAL duk_bool_t duk_to_boolean(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_bool_t duk_to_boolean(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
duk_bool_t val;
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_UNREF(thr);
+ DUK_ASSERT_API_ENTRY(thr);
- idx = duk_require_normalize_index(ctx, idx);
- tv = DUK_GET_TVAL_POSIDX(ctx, idx);
+ idx = duk_require_normalize_index(thr, idx);
+ tv = DUK_GET_TVAL_POSIDX(thr, idx);
DUK_ASSERT(tv != NULL);
val = duk_js_toboolean(tv);
@@ -19162,43 +19840,64 @@ DUK_EXTERNAL duk_bool_t duk_to_boolean(duk_context *ctx, duk_idx_t idx) {
return val;
}
-DUK_EXTERNAL duk_double_t duk_to_number(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_double_t duk_to_number(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
duk_double_t d;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
/* XXX: No need to normalize; the whole operation could be inlined here to
* avoid 'tv' re-lookup.
*/
- idx = duk_require_normalize_index(ctx, idx);
- tv = DUK_GET_TVAL_POSIDX(ctx, idx);
+ idx = duk_require_normalize_index(thr, idx);
+ tv = DUK_GET_TVAL_POSIDX(thr, idx);
DUK_ASSERT(tv != NULL);
d = duk_js_tonumber(thr, tv); /* XXX: fastint coercion? now result will always be a non-fastint */
/* ToNumber() may have side effects so must relookup 'tv'. */
- tv = DUK_GET_TVAL_POSIDX(ctx, idx);
+ tv = DUK_GET_TVAL_POSIDX(thr, idx);
DUK_TVAL_SET_NUMBER_UPDREF(thr, tv, d); /* side effects */
return d;
}
-DUK_INTERNAL duk_double_t duk_to_number_m1(duk_context *ctx) {
- return duk_to_number(ctx, -1);
+DUK_INTERNAL duk_double_t duk_to_number_m1(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk_to_number(thr, -1);
}
-DUK_INTERNAL duk_double_t duk_to_number_m2(duk_context *ctx) {
- return duk_to_number(ctx, -2);
+DUK_INTERNAL duk_double_t duk_to_number_m2(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk_to_number(thr, -2);
}
-DUK_INTERNAL duk_double_t duk_to_number_tval(duk_context *ctx, duk_tval *tv) {
+DUK_INTERNAL duk_double_t duk_to_number_tval(duk_hthread *thr, duk_tval *tv) {
+#if defined(DUK_USE_PREFER_SIZE)
duk_double_t res;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- duk_push_tval(ctx, tv);
- res = duk_to_number(ctx, -1);
- duk_pop(ctx);
+ duk_push_tval(thr, tv);
+ res = duk_to_number_m1(thr);
+ duk_pop_unsafe(thr);
return res;
+#else
+ duk_double_t res;
+ duk_tval *tv_dst;
+
+ DUK_ASSERT_API_ENTRY(thr);
+ DUK__ASSERT_SPACE();
+
+ tv_dst = thr->valstack_top++;
+ DUK_TVAL_SET_TVAL(tv_dst, tv);
+ DUK_TVAL_INCREF(thr, tv_dst); /* decref not necessary */
+ res = duk_to_number_m1(thr); /* invalidates tv_dst */
+
+ tv_dst = --thr->valstack_top;
+ DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv_dst));
+ DUK_ASSERT(!DUK_TVAL_NEEDS_REFCOUNT_UPDATE(tv_dst)); /* plain number */
+ DUK_TVAL_SET_UNDEFINED(tv_dst); /* valstack init policy */
+
+ return res;
+#endif
}
/* XXX: combine all the integer conversions: they share everything
@@ -19207,14 +19906,13 @@ DUK_INTERNAL duk_double_t duk_to_number_tval(duk_context *ctx, duk_tval *tv) {
typedef duk_double_t (*duk__toint_coercer)(duk_hthread *thr, duk_tval *tv);
-DUK_LOCAL duk_double_t duk__to_int_uint_helper(duk_context *ctx, duk_idx_t idx, duk__toint_coercer coerce_func) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_LOCAL duk_double_t duk__to_int_uint_helper(duk_hthread *thr, duk_idx_t idx, duk__toint_coercer coerce_func) {
duk_tval *tv;
duk_double_t d;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_CTX_VALID(thr);
- tv = duk_require_tval(ctx, idx);
+ tv = duk_require_tval(thr, idx);
DUK_ASSERT(tv != NULL);
#if defined(DUK_USE_FASTINT)
@@ -19231,93 +19929,92 @@ DUK_LOCAL duk_double_t duk__to_int_uint_helper(duk_context *ctx, duk_idx_t idx,
/* XXX: fastint? */
/* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */
- tv = duk_require_tval(ctx, idx);
+ tv = duk_require_tval(thr, idx);
DUK_TVAL_SET_NUMBER_UPDREF(thr, tv, d); /* side effects */
return d;
}
-DUK_EXTERNAL duk_int_t duk_to_int(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL duk_int_t duk_to_int(duk_hthread *thr, duk_idx_t idx) {
/* Value coercion (in stack): ToInteger(), E5 Section 9.4,
* API return value coercion: custom.
*/
- DUK_ASSERT_CTX_VALID(ctx);
- (void) duk__to_int_uint_helper(ctx, idx, duk_js_tointeger);
- return (duk_int_t) duk__api_coerce_d2i(ctx, idx, 0 /*def_value*/, 0 /*require*/);
+ DUK_ASSERT_API_ENTRY(thr);
+ (void) duk__to_int_uint_helper(thr, idx, duk_js_tointeger);
+ return (duk_int_t) duk__api_coerce_d2i(thr, idx, 0 /*def_value*/, 0 /*require*/);
}
-DUK_EXTERNAL duk_uint_t duk_to_uint(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL duk_uint_t duk_to_uint(duk_hthread *thr, duk_idx_t idx) {
/* Value coercion (in stack): ToInteger(), E5 Section 9.4,
* API return value coercion: custom.
*/
- DUK_ASSERT_CTX_VALID(ctx);
- (void) duk__to_int_uint_helper(ctx, idx, duk_js_tointeger);
- return (duk_uint_t) duk__api_coerce_d2ui(ctx, idx, 0 /*def_value*/, 0 /*require*/);
+ DUK_ASSERT_API_ENTRY(thr);
+ (void) duk__to_int_uint_helper(thr, idx, duk_js_tointeger);
+ return (duk_uint_t) duk__api_coerce_d2ui(thr, idx, 0 /*def_value*/, 0 /*require*/);
}
-DUK_EXTERNAL duk_int32_t duk_to_int32(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_int32_t duk_to_int32(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
duk_int32_t ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- tv = duk_require_tval(ctx, idx);
+ tv = duk_require_tval(thr, idx);
DUK_ASSERT(tv != NULL);
ret = duk_js_toint32(thr, tv);
/* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */
- tv = duk_require_tval(ctx, idx);
+ tv = duk_require_tval(thr, idx);
DUK_TVAL_SET_I32_UPDREF(thr, tv, ret); /* side effects */
return ret;
}
-DUK_EXTERNAL duk_uint32_t duk_to_uint32(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_uint32_t duk_to_uint32(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
duk_uint32_t ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- tv = duk_require_tval(ctx, idx);
+ tv = duk_require_tval(thr, idx);
DUK_ASSERT(tv != NULL);
ret = duk_js_touint32(thr, tv);
/* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */
- tv = duk_require_tval(ctx, idx);
+ tv = duk_require_tval(thr, idx);
DUK_TVAL_SET_U32_UPDREF(thr, tv, ret); /* side effects */
return ret;
}
-DUK_EXTERNAL duk_uint16_t duk_to_uint16(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_uint16_t duk_to_uint16(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
duk_uint16_t ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- tv = duk_require_tval(ctx, idx);
+ tv = duk_require_tval(thr, idx);
DUK_ASSERT(tv != NULL);
ret = duk_js_touint16(thr, tv);
/* Relookup in case coerce_func() has side effects, e.g. ends up coercing an object */
- tv = duk_require_tval(ctx, idx);
+ tv = duk_require_tval(thr, idx);
DUK_TVAL_SET_U32_UPDREF(thr, tv, ret); /* side effects */
return ret;
}
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
/* Special coercion for Uint8ClampedArray. */
-DUK_INTERNAL duk_uint8_t duk_to_uint8clamped(duk_context *ctx, duk_idx_t idx) {
+DUK_INTERNAL duk_uint8_t duk_to_uint8clamped(duk_hthread *thr, duk_idx_t idx) {
duk_double_t d;
duk_double_t t;
duk_uint8_t ret;
+ DUK_ASSERT_API_ENTRY(thr);
+
/* XXX: Simplify this algorithm, should be possible to come up with
* a shorter and faster algorithm by inspecting IEEE representation
* directly.
*/
- d = duk_to_number(ctx, idx);
+ d = duk_to_number(thr, idx);
if (d <= 0.0) {
return 0;
} else if (d >= 255) {
@@ -19342,41 +20039,41 @@ DUK_INTERNAL duk_uint8_t duk_to_uint8clamped(duk_context *ctx, duk_idx_t idx) {
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
-DUK_EXTERNAL const char *duk_to_lstring(duk_context *ctx, duk_idx_t idx, duk_size_t *out_len) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL const char *duk_to_lstring(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_len) {
+ DUK_ASSERT_API_ENTRY(thr);
- (void) duk_to_string(ctx, idx);
- DUK_ASSERT(duk_is_string(ctx, idx));
- return duk_require_lstring(ctx, idx, out_len);
+ (void) duk_to_string(thr, idx);
+ DUK_ASSERT(duk_is_string(thr, idx));
+ return duk_require_lstring(thr, idx, out_len);
}
-DUK_LOCAL duk_ret_t duk__safe_to_string_raw(duk_context *ctx, void *udata) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_LOCAL duk_ret_t duk__safe_to_string_raw(duk_hthread *thr, void *udata) {
+ DUK_ASSERT_CTX_VALID(thr);
DUK_UNREF(udata);
- duk_to_string(ctx, -1);
+ duk_to_string(thr, -1);
return 1;
}
-DUK_EXTERNAL const char *duk_safe_to_lstring(duk_context *ctx, duk_idx_t idx, duk_size_t *out_len) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL const char *duk_safe_to_lstring(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_len) {
+ DUK_ASSERT_API_ENTRY(thr);
- idx = duk_require_normalize_index(ctx, idx);
+ idx = duk_require_normalize_index(thr, idx);
/* We intentionally ignore the duk_safe_call() return value and only
* check the output type. This way we don't also need to check that
* the returned value is indeed a string in the success case.
*/
- duk_dup(ctx, idx);
- (void) duk_safe_call(ctx, duk__safe_to_string_raw, NULL /*udata*/, 1 /*nargs*/, 1 /*nrets*/);
- if (!duk_is_string(ctx, -1)) {
+ duk_dup(thr, idx);
+ (void) duk_safe_call(thr, duk__safe_to_string_raw, NULL /*udata*/, 1 /*nargs*/, 1 /*nrets*/);
+ if (!duk_is_string(thr, -1)) {
/* Error: try coercing error to string once. */
- (void) duk_safe_call(ctx, duk__safe_to_string_raw, NULL /*udata*/, 1 /*nargs*/, 1 /*nrets*/);
- if (!duk_is_string(ctx, -1)) {
+ (void) duk_safe_call(thr, duk__safe_to_string_raw, NULL /*udata*/, 1 /*nargs*/, 1 /*nrets*/);
+ if (!duk_is_string(thr, -1)) {
/* Double error */
- duk_pop(ctx);
- duk_push_hstring_stridx(ctx, DUK_STRIDX_UC_ERROR);
+ duk_pop_unsafe(thr);
+ duk_push_hstring_stridx(thr, DUK_STRIDX_UC_ERROR);
} else {
;
}
@@ -19384,50 +20081,49 @@ DUK_EXTERNAL const char *duk_safe_to_lstring(duk_context *ctx, duk_idx_t idx, du
/* String; may be a symbol, accepted. */
;
}
- DUK_ASSERT(duk_is_string(ctx, -1));
+ DUK_ASSERT(duk_is_string(thr, -1));
- duk_replace(ctx, idx);
- DUK_ASSERT(duk_get_string(ctx, idx) != NULL);
- return duk_get_lstring(ctx, idx, out_len);
+ duk_replace(thr, idx);
+ DUK_ASSERT(duk_get_string(thr, idx) != NULL);
+ return duk_get_lstring(thr, idx, out_len);
}
-DUK_INTERNAL duk_hstring *duk_to_property_key_hstring(duk_context *ctx, duk_idx_t idx) {
+DUK_INTERNAL duk_hstring *duk_to_property_key_hstring(duk_hthread *thr, duk_idx_t idx) {
duk_hstring *h;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- duk_to_primitive(ctx, idx, DUK_HINT_STRING); /* needed for e.g. Symbol objects */
- h = duk_get_hstring(ctx, idx);
+ duk_to_primitive(thr, idx, DUK_HINT_STRING); /* needed for e.g. Symbol objects */
+ h = duk_get_hstring(thr, idx);
if (h == NULL) {
/* The "is string?" check may seem unnecessary, but as things
* are duk_to_hstring() invokes ToString() which fails for
* symbols. But since symbols are already strings for Duktape
* C API, we check for that before doing the coercion.
*/
- h = duk_to_hstring(ctx, idx);
+ h = duk_to_hstring(thr, idx);
}
DUK_ASSERT(h != NULL);
return h;
}
#if defined(DUK_USE_DEBUGGER_SUPPORT) /* only needed by debugger for now */
-DUK_INTERNAL duk_hstring *duk_safe_to_hstring(duk_context *ctx, duk_idx_t idx) {
- (void) duk_safe_to_string(ctx, idx);
- DUK_ASSERT(duk_is_string(ctx, idx));
- DUK_ASSERT(duk_get_hstring(ctx, idx) != NULL);
- return duk_known_hstring(ctx, idx);
+DUK_INTERNAL duk_hstring *duk_safe_to_hstring(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+
+ (void) duk_safe_to_string(thr, idx);
+ DUK_ASSERT(duk_is_string(thr, idx));
+ DUK_ASSERT(duk_get_hstring(thr, idx) != NULL);
+ return duk_known_hstring(thr, idx);
}
#endif
/* Push Object.prototype.toString() output for 'tv'. */
-DUK_INTERNAL void duk_push_class_string_tval(duk_context *ctx, duk_tval *tv) {
- duk_hthread *thr;
+DUK_INTERNAL void duk_push_class_string_tval(duk_hthread *thr, duk_tval *tv) {
duk_small_uint_t stridx;
duk_hstring *h_strclass;
- DUK_ASSERT_CTX_VALID(ctx);
- thr = (duk_hthread *) ctx;
- DUK_UNREF(thr);
+ DUK_ASSERT_API_ENTRY(thr);
switch (DUK_TVAL_GET_TAG(tv)) {
case DUK_TAG_UNUSED: /* Treat like 'undefined', shouldn't happen. */
@@ -19499,21 +20195,20 @@ DUK_INTERNAL void duk_push_class_string_tval(duk_context *ctx, duk_tval *tv) {
h_strclass = DUK_HTHREAD_GET_STRING(thr, stridx);
DUK_ASSERT(h_strclass != NULL);
- duk_push_sprintf(ctx, "[object %s]", (const char *) DUK_HSTRING_GET_DATA(h_strclass));
+ duk_push_sprintf(thr, "[object %s]", (const char *) DUK_HSTRING_GET_DATA(h_strclass));
}
/* XXX: other variants like uint, u32 etc */
-DUK_INTERNAL duk_int_t duk_to_int_clamped_raw(duk_context *ctx, duk_idx_t idx, duk_int_t minval, duk_int_t maxval, duk_bool_t *out_clamped) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_INTERNAL duk_int_t duk_to_int_clamped_raw(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval, duk_bool_t *out_clamped) {
duk_tval *tv;
duk_tval tv_tmp;
duk_double_t d, dmin, dmax;
duk_int_t res;
duk_bool_t clamped = 0;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- tv = duk_require_tval(ctx, idx);
+ tv = duk_require_tval(thr, idx);
DUK_ASSERT(tv != NULL);
d = duk_js_tointeger(thr, tv); /* E5 Section 9.4, ToInteger() */
@@ -19535,7 +20230,7 @@ DUK_INTERNAL duk_int_t duk_to_int_clamped_raw(duk_context *ctx, duk_idx_t idx, d
/* 'd' and 'res' agree here */
/* Relookup in case duk_js_tointeger() ends up e.g. coercing an object. */
- tv = duk_get_tval(ctx, idx);
+ tv = duk_get_tval(thr, idx);
DUK_ASSERT(tv != NULL); /* not popped by side effect */
DUK_TVAL_SET_TVAL(&tv_tmp, tv);
#if defined(DUK_USE_FASTINT)
@@ -19566,40 +20261,42 @@ DUK_INTERNAL duk_int_t duk_to_int_clamped_raw(duk_context *ctx, duk_idx_t idx, d
return res;
}
-DUK_INTERNAL duk_int_t duk_to_int_clamped(duk_context *ctx, duk_idx_t idx, duk_idx_t minval, duk_idx_t maxval) {
+DUK_INTERNAL duk_int_t duk_to_int_clamped(duk_hthread *thr, duk_idx_t idx, duk_idx_t minval, duk_idx_t maxval) {
duk_bool_t dummy;
- return duk_to_int_clamped_raw(ctx, idx, minval, maxval, &dummy);
+
+ DUK_ASSERT_API_ENTRY(thr);
+
+ return duk_to_int_clamped_raw(thr, idx, minval, maxval, &dummy);
}
-DUK_INTERNAL duk_int_t duk_to_int_check_range(duk_context *ctx, duk_idx_t idx, duk_int_t minval, duk_int_t maxval) {
- return duk_to_int_clamped_raw(ctx, idx, minval, maxval, NULL); /* out_clamped==NULL -> RangeError if outside range */
+DUK_INTERNAL duk_int_t duk_to_int_check_range(duk_hthread *thr, duk_idx_t idx, duk_int_t minval, duk_int_t maxval) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk_to_int_clamped_raw(thr, idx, minval, maxval, NULL); /* out_clamped==NULL -> RangeError if outside range */
}
-DUK_EXTERNAL const char *duk_to_string(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL const char *duk_to_string(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_UNREF(thr);
+ DUK_ASSERT_API_ENTRY(thr);
- idx = duk_require_normalize_index(ctx, idx);
- tv = DUK_GET_TVAL_POSIDX(ctx, idx);
+ idx = duk_require_normalize_index(thr, idx);
+ tv = DUK_GET_TVAL_POSIDX(thr, idx);
DUK_ASSERT(tv != NULL);
switch (DUK_TVAL_GET_TAG(tv)) {
case DUK_TAG_UNDEFINED: {
- duk_push_hstring_stridx(ctx, DUK_STRIDX_LC_UNDEFINED);
+ duk_push_hstring_stridx(thr, DUK_STRIDX_LC_UNDEFINED);
break;
}
case DUK_TAG_NULL: {
- duk_push_hstring_stridx(ctx, DUK_STRIDX_LC_NULL);
+ duk_push_hstring_stridx(thr, DUK_STRIDX_LC_NULL);
break;
}
case DUK_TAG_BOOLEAN: {
if (DUK_TVAL_GET_BOOLEAN(tv)) {
- duk_push_hstring_stridx(ctx, DUK_STRIDX_TRUE);
+ duk_push_hstring_stridx(thr, DUK_STRIDX_TRUE);
} else {
- duk_push_hstring_stridx(ctx, DUK_STRIDX_FALSE);
+ duk_push_hstring_stridx(thr, DUK_STRIDX_FALSE);
}
break;
}
@@ -19614,7 +20311,7 @@ DUK_EXTERNAL const char *duk_to_string(duk_context *ctx, duk_idx_t idx) {
h = DUK_TVAL_GET_STRING(tv);
DUK_ASSERT(h != NULL);
if (DUK_UNLIKELY(DUK_HSTRING_HAS_SYMBOL(h))) {
- DUK_ERROR_TYPE((duk_hthread *) ctx, DUK_STR_CANNOT_STRING_COERCE_SYMBOL);
+ DUK_ERROR_TYPE(thr, DUK_STR_CANNOT_STRING_COERCE_SYMBOL);
} else {
goto skip_replace;
}
@@ -19630,27 +20327,27 @@ DUK_EXTERNAL const char *duk_to_string(duk_context *ctx, duk_idx_t idx) {
* Symbol objects: duk_to_primitive() results in a plain symbol
* value, and duk_to_string() then causes a TypeError.
*/
- duk_to_primitive(ctx, idx, DUK_HINT_STRING);
- DUK_ASSERT(!duk_is_buffer(ctx, idx)); /* ToPrimitive() must guarantee */
- DUK_ASSERT(!duk_is_object(ctx, idx));
- return duk_to_string(ctx, idx); /* Note: recursive call */
+ duk_to_primitive(thr, idx, DUK_HINT_STRING);
+ DUK_ASSERT(!duk_is_buffer(thr, idx)); /* ToPrimitive() must guarantee */
+ DUK_ASSERT(!duk_is_object(thr, idx));
+ return duk_to_string(thr, idx); /* Note: recursive call */
}
case DUK_TAG_POINTER: {
void *ptr = DUK_TVAL_GET_POINTER(tv);
if (ptr != NULL) {
- duk_push_sprintf(ctx, DUK_STR_FMT_PTR, (void *) ptr);
+ duk_push_sprintf(thr, DUK_STR_FMT_PTR, (void *) ptr);
} else {
/* Represent a null pointer as 'null' to be consistent with
* the JX format variant. Native '%p' format for a NULL
* pointer may be e.g. '(nil)'.
*/
- duk_push_hstring_stridx(ctx, DUK_STRIDX_LC_NULL);
+ duk_push_hstring_stridx(thr, DUK_STRIDX_LC_NULL);
}
break;
}
case DUK_TAG_LIGHTFUNC: {
/* Should match Function.prototype.toString() */
- duk_push_lightfunc_tostring(ctx, tv);
+ duk_push_lightfunc_tostring(thr, tv);
break;
}
#if defined(DUK_USE_FASTINT)
@@ -19660,8 +20357,8 @@ DUK_EXTERNAL const char *duk_to_string(duk_context *ctx, duk_idx_t idx) {
/* number */
DUK_ASSERT(!DUK_TVAL_IS_UNUSED(tv));
DUK_ASSERT(DUK_TVAL_IS_NUMBER(tv));
- duk_push_tval(ctx, tv);
- duk_numconv_stringify(ctx,
+ duk_push_tval(thr, tv);
+ duk_numconv_stringify(thr,
10 /*radix*/,
0 /*precision:shortest*/,
0 /*force_exponential*/);
@@ -19669,34 +20366,39 @@ DUK_EXTERNAL const char *duk_to_string(duk_context *ctx, duk_idx_t idx) {
}
}
- duk_replace(ctx, idx);
+ duk_replace(thr, idx);
skip_replace:
- DUK_ASSERT(duk_is_string(ctx, idx));
- return duk_require_string(ctx, idx);
+ DUK_ASSERT(duk_is_string(thr, idx));
+ return duk_require_string(thr, idx);
}
-DUK_INTERNAL duk_hstring *duk_to_hstring(duk_context *ctx, duk_idx_t idx) {
+DUK_INTERNAL duk_hstring *duk_to_hstring(duk_hthread *thr, duk_idx_t idx) {
duk_hstring *ret;
- DUK_ASSERT_CTX_VALID(ctx);
- duk_to_string(ctx, idx);
- ret = duk_get_hstring(ctx, idx);
+
+ DUK_ASSERT_API_ENTRY(thr);
+
+ duk_to_string(thr, idx);
+ ret = duk_get_hstring(thr, idx);
DUK_ASSERT(ret != NULL);
return ret;
}
-DUK_INTERNAL duk_hstring *duk_to_hstring_m1(duk_context *ctx) {
- return duk_to_hstring(ctx, -1);
+DUK_INTERNAL duk_hstring *duk_to_hstring_m1(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk_to_hstring(thr, -1);
}
-DUK_INTERNAL duk_hstring *duk_to_hstring_acceptsymbol(duk_context *ctx, duk_idx_t idx) {
+DUK_INTERNAL duk_hstring *duk_to_hstring_acceptsymbol(duk_hthread *thr, duk_idx_t idx) {
duk_hstring *ret;
- DUK_ASSERT_CTX_VALID(ctx);
- ret = duk_get_hstring(ctx, idx);
+
+ DUK_ASSERT_API_ENTRY(thr);
+
+ ret = duk_get_hstring(thr, idx);
if (DUK_UNLIKELY(ret && DUK_HSTRING_HAS_SYMBOL(ret))) {
return ret;
}
- return duk_to_hstring(ctx, idx);
+ return duk_to_hstring(thr, idx);
}
/* Convert a plain buffer or any buffer object into a string, using the buffer
@@ -19706,34 +20408,34 @@ DUK_INTERNAL duk_hstring *duk_to_hstring_acceptsymbol(duk_context *ctx, duk_idx_
* string with the same bytes as in the buffer but rather (usually)
* '[object ArrayBuffer]'.
*/
-DUK_EXTERNAL const char *duk_buffer_to_string(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL const char *duk_buffer_to_string(duk_hthread *thr, duk_idx_t idx) {
void *ptr_src;
duk_size_t len;
const char *res;
- idx = duk_require_normalize_index(ctx, idx);
+ DUK_ASSERT_API_ENTRY(thr);
- ptr_src = duk_require_buffer_data(ctx, idx, &len);
+ idx = duk_require_normalize_index(thr, idx);
+
+ ptr_src = duk_require_buffer_data(thr, idx, &len);
DUK_ASSERT(ptr_src != NULL || len == 0);
- res = duk_push_lstring(ctx, (const char *) ptr_src, len);
- duk_replace(ctx, idx);
+ res = duk_push_lstring(thr, (const char *) ptr_src, len);
+ duk_replace(thr, idx);
return res;
}
-DUK_EXTERNAL void *duk_to_buffer_raw(duk_context *ctx, duk_idx_t idx, duk_size_t *out_size, duk_uint_t mode) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void *duk_to_buffer_raw(duk_hthread *thr, duk_idx_t idx, duk_size_t *out_size, duk_uint_t mode) {
duk_hbuffer *h_buf;
const duk_uint8_t *src_data;
duk_size_t src_size;
duk_uint8_t *dst_data;
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_UNREF(thr);
+ DUK_ASSERT_API_ENTRY(thr);
- idx = duk_require_normalize_index(ctx, idx);
+ idx = duk_require_normalize_index(thr, idx);
- h_buf = duk_get_hbuffer(ctx, idx);
+ h_buf = duk_get_hbuffer(thr, idx);
if (h_buf != NULL) {
/* Buffer is kept as is, with the fixed/dynamic nature of the
* buffer only changed if requested. An external buffer
@@ -19762,10 +20464,10 @@ DUK_EXTERNAL void *duk_to_buffer_raw(duk_context *ctx, duk_idx_t idx, duk_size_t
* explicitly requested). Symbols are rejected with a TypeError.
* XXX: C API could maybe allow symbol-to-buffer coercion?
*/
- src_data = (const duk_uint8_t *) duk_to_lstring(ctx, idx, &src_size);
+ src_data = (const duk_uint8_t *) duk_to_lstring(thr, idx, &src_size);
}
- dst_data = (duk_uint8_t *) duk_push_buffer(ctx, src_size, (mode == DUK_BUF_MODE_DYNAMIC) /*dynamic*/);
+ dst_data = (duk_uint8_t *) duk_push_buffer(thr, src_size, (mode == DUK_BUF_MODE_DYNAMIC) /*dynamic*/);
if (DUK_LIKELY(src_size > 0)) {
/* When src_size == 0, src_data may be NULL (if source
* buffer is dynamic), and dst_data may be NULL (if
@@ -19774,7 +20476,7 @@ DUK_EXTERNAL void *duk_to_buffer_raw(duk_context *ctx, duk_idx_t idx, duk_size_t
*/
DUK_MEMCPY((void *) dst_data, (const void *) src_data, (size_t) src_size);
}
- duk_replace(ctx, idx);
+ duk_replace(thr, idx);
skip_copy:
if (out_size) {
@@ -19783,14 +20485,14 @@ DUK_EXTERNAL void *duk_to_buffer_raw(duk_context *ctx, duk_idx_t idx, duk_size_t
return dst_data;
}
-DUK_EXTERNAL void *duk_to_pointer(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL void *duk_to_pointer(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
void *res;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- idx = duk_require_normalize_index(ctx, idx);
- tv = DUK_GET_TVAL_POSIDX(ctx, idx);
+ idx = duk_require_normalize_index(thr, idx);
+ tv = DUK_GET_TVAL_POSIDX(thr, idx);
DUK_ASSERT(tv != NULL);
switch (DUK_TVAL_GET_TAG(tv)) {
@@ -19828,12 +20530,12 @@ DUK_EXTERNAL void *duk_to_pointer(duk_context *ctx, duk_idx_t idx) {
break;
}
- duk_push_pointer(ctx, res);
- duk_replace(ctx, idx);
+ duk_push_pointer(thr, res);
+ duk_replace(thr, idx);
return res;
}
-DUK_LOCAL void duk__push_func_from_lightfunc(duk_context *ctx, duk_c_function func, duk_small_uint_t lf_flags) {
+DUK_LOCAL void duk__push_func_from_lightfunc(duk_hthread *thr, duk_c_function func, duk_small_uint_t lf_flags) {
duk_idx_t nargs;
duk_uint_t flags = 0; /* shared flags for a subset of types */
duk_small_uint_t lf_len;
@@ -19846,44 +20548,40 @@ DUK_LOCAL void duk__push_func_from_lightfunc(duk_context *ctx, duk_c_function fu
flags = DUK_HOBJECT_FLAG_EXTENSIBLE |
DUK_HOBJECT_FLAG_CONSTRUCTABLE |
+ DUK_HOBJECT_FLAG_CALLABLE |
DUK_HOBJECT_FLAG_FASTREFS |
DUK_HOBJECT_FLAG_NATFUNC |
DUK_HOBJECT_FLAG_NEWENV |
DUK_HOBJECT_FLAG_STRICT |
DUK_HOBJECT_FLAG_NOTAIL |
- /* DUK_HOBJECT_FLAG_EXOTIC_DUKFUNC: omitted here intentionally */
DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION);
- (void) duk__push_c_function_raw(ctx, func, nargs, flags);
+ (void) duk__push_c_function_raw(thr, func, nargs, flags, DUK_BIDX_NATIVE_FUNCTION_PROTOTYPE);
lf_len = DUK_LFUNC_FLAGS_GET_LENGTH(lf_flags);
if ((duk_idx_t) lf_len != nargs) {
/* Explicit length is only needed if it differs from 'nargs'. */
- duk_push_int(ctx, (duk_int_t) lf_len);
- duk_xdef_prop_stridx_short(ctx, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_NONE);
+ duk_push_int(thr, (duk_int_t) lf_len);
+ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_LENGTH, DUK_PROPDESC_FLAGS_NONE);
}
#if defined(DUK_USE_FUNC_NAME_PROPERTY)
- duk_push_lightfunc_name_raw(ctx, func, lf_flags);
- duk_xdef_prop_stridx_short(ctx, -2, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_C);
+ duk_push_lightfunc_name_raw(thr, func, lf_flags);
+ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_NAME, DUK_PROPDESC_FLAGS_C);
#endif
- nf = duk_known_hnatfunc(ctx, -1);
+ nf = duk_known_hnatfunc(thr, -1);
nf->magic = (duk_int16_t) DUK_LFUNC_FLAGS_GET_MAGIC(lf_flags);
-
- /* Enable DUKFUNC exotic behavior once properties are set up. */
- DUK_HOBJECT_SET_EXOTIC_DUKFUNC((duk_hobject *) nf);
}
-DUK_EXTERNAL void duk_to_object(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_to_object(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
duk_uint_t flags = 0; /* shared flags for a subset of types */
duk_small_int_t proto = 0;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- idx = duk_require_normalize_index(ctx, idx);
- tv = DUK_GET_TVAL_POSIDX(ctx, idx);
+ idx = duk_require_normalize_index(thr, idx);
+ tv = DUK_GET_TVAL_POSIDX(thr, idx);
DUK_ASSERT(tv != NULL);
switch (DUK_TVAL_GET_TAG(tv)) {
@@ -19962,7 +20660,7 @@ DUK_EXTERNAL void duk_to_object(duk_context *ctx, duk_idx_t idx) {
duk_c_function func;
DUK_TVAL_GET_LIGHTFUNC(tv, func, lf_flags);
- duk__push_func_from_lightfunc(ctx, func, lf_flags);
+ duk__push_func_from_lightfunc(thr, func, lf_flags);
goto replace_value;
}
#if defined(DUK_USE_FASTINT)
@@ -19978,11 +20676,11 @@ DUK_EXTERNAL void duk_to_object(duk_context *ctx, duk_idx_t idx) {
goto create_object;
}
}
- DUK_ASSERT(duk_is_object(ctx, idx));
+ DUK_ASSERT(duk_is_object(thr, idx));
return;
create_object:
- (void) duk_push_object_helper(ctx, flags, proto);
+ (void) duk_push_object_helper(thr, flags, proto);
/* Note: Boolean prototype's internal value property is not writable,
* but duk_xdef_prop_stridx() disregards the write protection. Boolean
@@ -19991,19 +20689,21 @@ DUK_EXTERNAL void duk_to_object(duk_context *ctx, duk_idx_t idx) {
* String and buffer special behaviors are already enabled which is not
* ideal, but a write to the internal value is not affected by them.
*/
- duk_dup(ctx, idx);
- duk_xdef_prop_stridx_short(ctx, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE);
+ duk_dup(thr, idx);
+ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_NONE);
replace_value:
- duk_replace(ctx, idx);
- DUK_ASSERT(duk_is_object(ctx, idx));
+ duk_replace(thr, idx);
+ DUK_ASSERT(duk_is_object(thr, idx));
}
-DUK_INTERNAL duk_hobject *duk_to_hobject(duk_context *ctx, duk_idx_t idx) {
+DUK_INTERNAL duk_hobject *duk_to_hobject(duk_hthread *thr, duk_idx_t idx) {
duk_hobject *ret;
- DUK_ASSERT_CTX_VALID(ctx);
- duk_to_object(ctx, idx);
- ret = duk_known_hobject(ctx, idx);
+
+ DUK_ASSERT_API_ENTRY(thr);
+
+ duk_to_object(thr, idx);
+ ret = duk_known_hobject(thr, idx);
return ret;
}
@@ -20011,20 +20711,20 @@ DUK_INTERNAL duk_hobject *duk_to_hobject(duk_context *ctx, duk_idx_t idx) {
* Type checking
*/
-DUK_LOCAL duk_bool_t duk__tag_check(duk_context *ctx, duk_idx_t idx, duk_small_uint_t tag) {
+DUK_LOCAL duk_bool_t duk__tag_check(duk_hthread *thr, duk_idx_t idx, duk_small_uint_t tag) {
duk_tval *tv;
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
return (DUK_TVAL_GET_TAG(tv) == tag);
}
-DUK_LOCAL duk_bool_t duk__obj_flag_any_default_false(duk_context *ctx, duk_idx_t idx, duk_uint_t flag_mask) {
+DUK_LOCAL duk_bool_t duk__obj_flag_any_default_false(duk_hthread *thr, duk_idx_t idx, duk_uint_t flag_mask) {
duk_hobject *obj;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- obj = duk_get_hobject(ctx, idx);
+ obj = duk_get_hobject(thr, idx);
if (obj) {
return (DUK_HEAPHDR_CHECK_FLAG_BITS((duk_heaphdr *) obj, flag_mask) ? 1 : 0);
}
@@ -20070,19 +20770,19 @@ DUK_INTERNAL duk_int_t duk_get_type_tval(duk_tval *tv) {
#endif /* DUK_USE_PACKED_TVAL */
}
-DUK_EXTERNAL duk_int_t duk_get_type(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL duk_int_t duk_get_type(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
return duk_get_type_tval(tv);
}
#if defined(DUK_USE_VERBOSE_ERRORS) && defined(DUK_USE_PARANOID_ERRORS)
-DUK_LOCAL const char *duk__type_names[] = {
+DUK_LOCAL const char * const duk__type_names[] = {
"none",
"undefined",
"null",
@@ -20095,22 +20795,26 @@ DUK_LOCAL const char *duk__type_names[] = {
"lightfunc"
};
-DUK_INTERNAL const char *duk_get_type_name(duk_context *ctx, duk_idx_t idx) {
+DUK_INTERNAL const char *duk_get_type_name(duk_hthread *thr, duk_idx_t idx) {
duk_int_t type_tag;
- type_tag = duk_get_type(ctx, idx);
+ DUK_ASSERT_API_ENTRY(thr);
+
+ type_tag = duk_get_type(thr, idx);
DUK_ASSERT(type_tag >= DUK_TYPE_MIN && type_tag <= DUK_TYPE_MAX);
DUK_ASSERT(DUK_TYPE_MIN == 0 && sizeof(duk__type_names) / sizeof(const char *) == DUK_TYPE_MAX + 1);
return duk__type_names[type_tag];
}
-#endif
+#endif /* DUK_USE_VERBOSE_ERRORS && DUK_USE_PARANOID_ERRORS */
-DUK_INTERNAL duk_small_uint_t duk_get_class_number(duk_context *ctx, duk_idx_t idx) {
+DUK_INTERNAL duk_small_uint_t duk_get_class_number(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
duk_hobject *obj;
- tv = duk_get_tval_or_unused(ctx, idx);
+ DUK_ASSERT_API_ENTRY(thr);
+
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
switch (DUK_TVAL_GET_TAG(tv)) {
@@ -20130,10 +20834,10 @@ DUK_INTERNAL duk_small_uint_t duk_get_class_number(duk_context *ctx, duk_idx_t i
}
}
-DUK_EXTERNAL duk_bool_t duk_check_type(duk_context *ctx, duk_idx_t idx, duk_int_t type) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_bool_t duk_check_type(duk_hthread *thr, duk_idx_t idx, duk_int_t type) {
+ DUK_ASSERT_API_ENTRY(thr);
- return (duk_get_type(ctx, idx) == type) ? 1 : 0;
+ return (duk_get_type(thr, idx) == type) ? 1 : 0;
}
DUK_INTERNAL duk_uint_t duk_get_type_mask_tval(duk_tval *tv) {
@@ -20171,27 +20875,25 @@ DUK_INTERNAL duk_uint_t duk_get_type_mask_tval(duk_tval *tv) {
#else /* DUK_USE_PACKED_TVAL */
DUK_ASSERT(DUK_TVAL_IS_VALID_TAG(tv));
DUK_ASSERT(sizeof(duk__type_mask_from_tag) / sizeof(duk_uint_t) == DUK_TAG_MAX - DUK_TAG_MIN + 1);
- return (duk_int_t) duk__type_mask_from_tag[DUK_TVAL_GET_TAG(tv) - DUK_TAG_MIN];
+ return duk__type_mask_from_tag[DUK_TVAL_GET_TAG(tv) - DUK_TAG_MIN];
#endif /* DUK_USE_PACKED_TVAL */
}
-DUK_EXTERNAL duk_uint_t duk_get_type_mask(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL duk_uint_t duk_get_type_mask(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
return duk_get_type_mask_tval(tv);
}
-DUK_EXTERNAL duk_bool_t duk_check_type_mask(duk_context *ctx, duk_idx_t idx, duk_uint_t mask) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_bool_t duk_check_type_mask(duk_hthread *thr, duk_idx_t idx, duk_uint_t mask) {
+ DUK_ASSERT_API_ENTRY(thr);
- DUK_ASSERT_CTX_VALID(ctx);
-
- if (DUK_LIKELY(duk_get_type_mask(ctx, idx) & mask)) {
+ if (DUK_LIKELY((duk_get_type_mask(thr, idx) & mask) != 0U)) {
return 1;
}
if (mask & DUK_TYPE_MASK_THROW) {
@@ -20201,25 +20903,25 @@ DUK_EXTERNAL duk_bool_t duk_check_type_mask(duk_context *ctx, duk_idx_t idx, duk
return 0;
}
-DUK_EXTERNAL duk_bool_t duk_is_undefined(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
- return duk__tag_check(ctx, idx, DUK_TAG_UNDEFINED);
+DUK_EXTERNAL duk_bool_t duk_is_undefined(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk__tag_check(thr, idx, DUK_TAG_UNDEFINED);
}
-DUK_EXTERNAL duk_bool_t duk_is_null(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
- return duk__tag_check(ctx, idx, DUK_TAG_NULL);
+DUK_EXTERNAL duk_bool_t duk_is_null(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk__tag_check(thr, idx, DUK_TAG_NULL);
}
-DUK_EXTERNAL duk_bool_t duk_is_boolean(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
- return duk__tag_check(ctx, idx, DUK_TAG_BOOLEAN);
+DUK_EXTERNAL duk_bool_t duk_is_boolean(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk__tag_check(thr, idx, DUK_TAG_BOOLEAN);
}
-DUK_EXTERNAL duk_bool_t duk_is_number(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL duk_bool_t duk_is_number(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
/*
* Number is special because it doesn't have a specific
@@ -20228,12 +20930,12 @@ DUK_EXTERNAL duk_bool_t duk_is_number(duk_context *ctx, duk_idx_t idx) {
/* XXX: shorter version for unpacked representation? */
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
return DUK_TVAL_IS_NUMBER(tv);
}
-DUK_EXTERNAL duk_bool_t duk_is_nan(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL duk_bool_t duk_is_nan(duk_hthread *thr, duk_idx_t idx) {
/* XXX: This will now return false for non-numbers, even though they would
* coerce to NaN (as a general rule). In particular, duk_get_number()
* returns a NaN for non-numbers, so should this function also return
@@ -20242,45 +20944,45 @@ DUK_EXTERNAL duk_bool_t duk_is_nan(duk_context *ctx, duk_idx_t idx) {
duk_tval *tv;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
/* XXX: for packed duk_tval an explicit "is number" check is unnecessary */
if (!DUK_TVAL_IS_NUMBER(tv)) {
return 0;
}
- return DUK_ISNAN(DUK_TVAL_GET_NUMBER(tv));
+ return (duk_bool_t) DUK_ISNAN(DUK_TVAL_GET_NUMBER(tv));
}
-DUK_EXTERNAL duk_bool_t duk_is_string(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
- return duk__tag_check(ctx, idx, DUK_TAG_STRING);
+DUK_EXTERNAL duk_bool_t duk_is_string(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk__tag_check(thr, idx, DUK_TAG_STRING);
}
-DUK_INTERNAL duk_bool_t duk_is_string_notsymbol(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
- return duk_get_hstring_notsymbol(ctx, idx) != NULL;
+DUK_INTERNAL duk_bool_t duk_is_string_notsymbol(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk_get_hstring_notsymbol(thr, idx) != NULL;
}
-DUK_EXTERNAL duk_bool_t duk_is_object(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
- return duk__tag_check(ctx, idx, DUK_TAG_OBJECT);
+DUK_EXTERNAL duk_bool_t duk_is_object(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk__tag_check(thr, idx, DUK_TAG_OBJECT);
}
-DUK_EXTERNAL duk_bool_t duk_is_buffer(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
- return duk__tag_check(ctx, idx, DUK_TAG_BUFFER);
+DUK_EXTERNAL duk_bool_t duk_is_buffer(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk__tag_check(thr, idx, DUK_TAG_BUFFER);
}
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
-DUK_EXTERNAL duk_bool_t duk_is_buffer_data(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL duk_bool_t duk_is_buffer_data(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
if (DUK_TVAL_IS_BUFFER(tv)) {
return 1;
@@ -20294,29 +20996,29 @@ DUK_EXTERNAL duk_bool_t duk_is_buffer_data(duk_context *ctx, duk_idx_t idx) {
return 0;
}
#else /* DUK_USE_BUFFEROBJECT_SUPPORT */
-DUK_EXTERNAL duk_bool_t duk_is_buffer_data(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_bool_t duk_is_buffer_data(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
- return duk_is_buffer(ctx, idx);
+ return duk_is_buffer(thr, idx);
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
-DUK_EXTERNAL duk_bool_t duk_is_pointer(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
- return duk__tag_check(ctx, idx, DUK_TAG_POINTER);
+DUK_EXTERNAL duk_bool_t duk_is_pointer(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk__tag_check(thr, idx, DUK_TAG_POINTER);
}
-DUK_EXTERNAL duk_bool_t duk_is_lightfunc(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
- return duk__tag_check(ctx, idx, DUK_TAG_LIGHTFUNC);
+DUK_EXTERNAL duk_bool_t duk_is_lightfunc(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk__tag_check(thr, idx, DUK_TAG_LIGHTFUNC);
}
-DUK_EXTERNAL duk_bool_t duk_is_symbol(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL duk_bool_t duk_is_symbol(duk_hthread *thr, duk_idx_t idx) {
duk_hstring *h;
- DUK_ASSERT_CTX_VALID(ctx);
- h = duk_get_hstring(ctx, idx);
+ DUK_ASSERT_API_ENTRY(thr);
+ h = duk_get_hstring(thr, idx);
/* Use DUK_LIKELY() here because caller may be more likely to type
* check an expected symbol than not.
*/
@@ -20326,73 +21028,110 @@ DUK_EXTERNAL duk_bool_t duk_is_symbol(duk_context *ctx, duk_idx_t idx) {
return 0;
}
-DUK_EXTERNAL duk_bool_t duk_is_array(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL duk_bool_t duk_is_array(duk_hthread *thr, duk_idx_t idx) {
duk_hobject *obj;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- obj = duk_get_hobject(ctx, idx);
+ obj = duk_get_hobject(thr, idx);
if (obj) {
return (DUK_HOBJECT_GET_CLASS_NUMBER(obj) == DUK_HOBJECT_CLASS_ARRAY ? 1 : 0);
}
return 0;
}
-DUK_EXTERNAL duk_bool_t duk_is_function(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL duk_bool_t duk_is_function(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
+ if (DUK_TVAL_IS_OBJECT(tv)) {
+ duk_hobject *h;
+ h = DUK_TVAL_GET_OBJECT(tv);
+ DUK_ASSERT(h != NULL);
+ return DUK_HOBJECT_HAS_CALLABLE(h) ? 1 : 0;
+ }
if (DUK_TVAL_IS_LIGHTFUNC(tv)) {
return 1;
}
- return duk__obj_flag_any_default_false(ctx,
- idx,
- DUK_HOBJECT_FLAG_COMPFUNC |
- DUK_HOBJECT_FLAG_NATFUNC |
- DUK_HOBJECT_FLAG_BOUNDFUNC);
+ return 0;
+}
+
+DUK_INTERNAL duk_bool_t duk_is_callable_tval(duk_hthread *thr, duk_tval *tv) {
+ DUK_ASSERT_API_ENTRY(thr);
+
+ DUK_UNREF(thr);
+
+ if (DUK_TVAL_IS_OBJECT(tv)) {
+ duk_hobject *h;
+ h = DUK_TVAL_GET_OBJECT(tv);
+ DUK_ASSERT(h != NULL);
+ return DUK_HOBJECT_HAS_CALLABLE(h) ? 1 : 0;
+ }
+ if (DUK_TVAL_IS_LIGHTFUNC(tv)) {
+ return 1;
+ }
+ return 0;
}
-DUK_EXTERNAL duk_bool_t duk_is_c_function(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
- return duk__obj_flag_any_default_false(ctx,
+DUK_EXTERNAL duk_bool_t duk_is_constructable(duk_hthread *thr, duk_idx_t idx) {
+ duk_tval *tv;
+
+ DUK_ASSERT_API_ENTRY(thr);
+
+ tv = duk_get_tval_or_unused(thr, idx);
+ if (DUK_TVAL_IS_OBJECT(tv)) {
+ duk_hobject *h;
+ h = DUK_TVAL_GET_OBJECT(tv);
+ DUK_ASSERT(h != NULL);
+ return DUK_HOBJECT_HAS_CONSTRUCTABLE(h) ? 1 : 0;
+ }
+ if (DUK_TVAL_IS_LIGHTFUNC(tv)) {
+ return 1;
+ }
+ return 0;
+}
+
+DUK_EXTERNAL duk_bool_t duk_is_c_function(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk__obj_flag_any_default_false(thr,
idx,
DUK_HOBJECT_FLAG_NATFUNC);
}
-DUK_EXTERNAL duk_bool_t duk_is_ecmascript_function(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
- return duk__obj_flag_any_default_false(ctx,
+DUK_EXTERNAL duk_bool_t duk_is_ecmascript_function(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk__obj_flag_any_default_false(thr,
idx,
DUK_HOBJECT_FLAG_COMPFUNC);
}
-DUK_EXTERNAL duk_bool_t duk_is_bound_function(duk_context *ctx, duk_idx_t idx) {
- DUK_ASSERT_CTX_VALID(ctx);
- return duk__obj_flag_any_default_false(ctx,
+DUK_EXTERNAL duk_bool_t duk_is_bound_function(duk_hthread *thr, duk_idx_t idx) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk__obj_flag_any_default_false(thr,
idx,
DUK_HOBJECT_FLAG_BOUNDFUNC);
}
-DUK_EXTERNAL duk_bool_t duk_is_thread(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL duk_bool_t duk_is_thread(duk_hthread *thr, duk_idx_t idx) {
duk_hobject *obj;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- obj = duk_get_hobject(ctx, idx);
+ obj = duk_get_hobject(thr, idx);
if (obj) {
return (DUK_HOBJECT_GET_CLASS_NUMBER(obj) == DUK_HOBJECT_CLASS_THREAD ? 1 : 0);
}
return 0;
}
-DUK_EXTERNAL duk_bool_t duk_is_fixed_buffer(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL duk_bool_t duk_is_fixed_buffer(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
if (DUK_TVAL_IS_BUFFER(tv)) {
duk_hbuffer *h = DUK_TVAL_GET_BUFFER(tv);
@@ -20402,12 +21141,12 @@ DUK_EXTERNAL duk_bool_t duk_is_fixed_buffer(duk_context *ctx, duk_idx_t idx) {
return 0;
}
-DUK_EXTERNAL duk_bool_t duk_is_dynamic_buffer(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL duk_bool_t duk_is_dynamic_buffer(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
if (DUK_TVAL_IS_BUFFER(tv)) {
duk_hbuffer *h = DUK_TVAL_GET_BUFFER(tv);
@@ -20417,12 +21156,12 @@ DUK_EXTERNAL duk_bool_t duk_is_dynamic_buffer(duk_context *ctx, duk_idx_t idx) {
return 0;
}
-DUK_EXTERNAL duk_bool_t duk_is_external_buffer(duk_context *ctx, duk_idx_t idx) {
+DUK_EXTERNAL duk_bool_t duk_is_external_buffer(duk_hthread *thr, duk_idx_t idx) {
duk_tval *tv;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- tv = duk_get_tval_or_unused(ctx, idx);
+ tv = duk_get_tval_or_unused(thr, idx);
DUK_ASSERT(tv != NULL);
if (DUK_TVAL_IS_BUFFER(tv)) {
duk_hbuffer *h = DUK_TVAL_GET_BUFFER(tv);
@@ -20432,20 +21171,22 @@ DUK_EXTERNAL duk_bool_t duk_is_external_buffer(duk_context *ctx, duk_idx_t idx)
return 0;
}
-DUK_EXTERNAL duk_errcode_t duk_get_error_code(duk_context *ctx, duk_idx_t idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_errcode_t duk_get_error_code(duk_hthread *thr, duk_idx_t idx) {
duk_hobject *h;
duk_uint_t sanity;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- h = duk_get_hobject(ctx, idx);
+ h = duk_get_hobject(thr, idx);
sanity = DUK_HOBJECT_PROTOTYPE_CHAIN_SANITY;
do {
if (!h) {
return DUK_ERR_NONE;
}
+
+ /* XXX: something more convenient? */
+
if (h == thr->builtins[DUK_BIDX_EVAL_ERROR_PROTOTYPE]) {
return DUK_ERR_EVAL_ERROR;
}
@@ -20478,24 +21219,21 @@ DUK_EXTERNAL duk_errcode_t duk_get_error_code(duk_context *ctx, duk_idx_t idx) {
* Pushers
*/
-DUK_INTERNAL void duk_push_tval(duk_context *ctx, duk_tval *tv) {
- duk_hthread *thr;
+DUK_INTERNAL void duk_push_tval(duk_hthread *thr, duk_tval *tv) {
duk_tval *tv_slot;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(tv != NULL);
- thr = (duk_hthread *) ctx;
+
DUK__CHECK_SPACE();
tv_slot = thr->valstack_top++;
DUK_TVAL_SET_TVAL(tv_slot, tv);
DUK_TVAL_INCREF(thr, tv); /* no side effects */
}
-DUK_EXTERNAL void duk_push_undefined(duk_context *ctx) {
- duk_hthread *thr;
+DUK_EXTERNAL void duk_push_undefined(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
- DUK_ASSERT_CTX_VALID(ctx);
- thr = (duk_hthread *) ctx;
DUK__CHECK_SPACE();
/* Because value stack init policy is 'undefined above top',
@@ -20505,60 +21243,50 @@ DUK_EXTERNAL void duk_push_undefined(duk_context *ctx) {
DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top - 1));
}
-DUK_EXTERNAL void duk_push_null(duk_context *ctx) {
- duk_hthread *thr;
+DUK_EXTERNAL void duk_push_null(duk_hthread *thr) {
duk_tval *tv_slot;
- DUK_ASSERT_CTX_VALID(ctx);
- thr = (duk_hthread *) ctx;
+ DUK_ASSERT_API_ENTRY(thr);
DUK__CHECK_SPACE();
tv_slot = thr->valstack_top++;
DUK_TVAL_SET_NULL(tv_slot);
}
-DUK_EXTERNAL void duk_push_boolean(duk_context *ctx, duk_bool_t val) {
- duk_hthread *thr;
+DUK_EXTERNAL void duk_push_boolean(duk_hthread *thr, duk_bool_t val) {
duk_tval *tv_slot;
duk_small_int_t b;
- DUK_ASSERT_CTX_VALID(ctx);
- thr = (duk_hthread *) ctx;
+ DUK_ASSERT_API_ENTRY(thr);
DUK__CHECK_SPACE();
b = (val ? 1 : 0); /* ensure value is 1 or 0 (not other non-zero) */
tv_slot = thr->valstack_top++;
DUK_TVAL_SET_BOOLEAN(tv_slot, b);
}
-DUK_EXTERNAL void duk_push_true(duk_context *ctx) {
- duk_hthread *thr;
+DUK_EXTERNAL void duk_push_true(duk_hthread *thr) {
duk_tval *tv_slot;
- DUK_ASSERT_CTX_VALID(ctx);
- thr = (duk_hthread *) ctx;
+ DUK_ASSERT_API_ENTRY(thr);
DUK__CHECK_SPACE();
tv_slot = thr->valstack_top++;
DUK_TVAL_SET_BOOLEAN_TRUE(tv_slot);
}
-DUK_EXTERNAL void duk_push_false(duk_context *ctx) {
- duk_hthread *thr;
+DUK_EXTERNAL void duk_push_false(duk_hthread *thr) {
duk_tval *tv_slot;
- DUK_ASSERT_CTX_VALID(ctx);
- thr = (duk_hthread *) ctx;
+ DUK_ASSERT_API_ENTRY(thr);
DUK__CHECK_SPACE();
tv_slot = thr->valstack_top++;
DUK_TVAL_SET_BOOLEAN_FALSE(tv_slot);
}
/* normalize NaN which may not match our canonical internal NaN */
-DUK_EXTERNAL void duk_push_number(duk_context *ctx, duk_double_t val) {
- duk_hthread *thr;
+DUK_EXTERNAL void duk_push_number(duk_hthread *thr, duk_double_t val) {
duk_tval *tv_slot;
duk_double_union du;
- DUK_ASSERT_CTX_VALID(ctx);
- thr = (duk_hthread *) ctx;
+ DUK_ASSERT_API_ENTRY(thr);
DUK__CHECK_SPACE();
du.d = val;
DUK_DBLUNION_NORMALIZE_NAN_CHECK(&du);
@@ -20566,13 +21294,11 @@ DUK_EXTERNAL void duk_push_number(duk_context *ctx, duk_double_t val) {
DUK_TVAL_SET_NUMBER(tv_slot, du.d);
}
-DUK_EXTERNAL void duk_push_int(duk_context *ctx, duk_int_t val) {
+DUK_EXTERNAL void duk_push_int(duk_hthread *thr, duk_int_t val) {
#if defined(DUK_USE_FASTINT)
- duk_hthread *thr;
duk_tval *tv_slot;
- DUK_ASSERT_CTX_VALID(ctx);
- thr = (duk_hthread *) ctx;
+ DUK_ASSERT_API_ENTRY(thr);
DUK__CHECK_SPACE();
tv_slot = thr->valstack_top++;
#if DUK_INT_MAX <= 0x7fffffffL
@@ -20586,12 +21312,10 @@ DUK_EXTERNAL void duk_push_int(duk_context *ctx, duk_int_t val) {
}
#endif
#else /* DUK_USE_FASTINT */
- duk_hthread *thr;
duk_tval *tv_slot;
duk_double_t d;
- DUK_ASSERT_CTX_VALID(ctx);
- thr = (duk_hthread *) ctx;
+ DUK_ASSERT_API_ENTRY(thr);
DUK__CHECK_SPACE();
d = (duk_double_t) val;
tv_slot = thr->valstack_top++;
@@ -20599,13 +21323,11 @@ DUK_EXTERNAL void duk_push_int(duk_context *ctx, duk_int_t val) {
#endif /* DUK_USE_FASTINT */
}
-DUK_EXTERNAL void duk_push_uint(duk_context *ctx, duk_uint_t val) {
+DUK_EXTERNAL void duk_push_uint(duk_hthread *thr, duk_uint_t val) {
#if defined(DUK_USE_FASTINT)
- duk_hthread *thr;
duk_tval *tv_slot;
- DUK_ASSERT_CTX_VALID(ctx);
- thr = (duk_hthread *) ctx;
+ DUK_ASSERT_API_ENTRY(thr);
DUK__CHECK_SPACE();
tv_slot = thr->valstack_top++;
#if DUK_UINT_MAX <= 0xffffffffUL
@@ -20620,12 +21342,10 @@ DUK_EXTERNAL void duk_push_uint(duk_context *ctx, duk_uint_t val) {
}
#endif
#else /* DUK_USE_FASTINT */
- duk_hthread *thr;
duk_tval *tv_slot;
duk_double_t d;
- DUK_ASSERT_CTX_VALID(ctx);
- thr = (duk_hthread *) ctx;
+ DUK_ASSERT_API_ENTRY(thr);
DUK__CHECK_SPACE();
d = (duk_double_t) val;
tv_slot = thr->valstack_top++;
@@ -20633,13 +21353,11 @@ DUK_EXTERNAL void duk_push_uint(duk_context *ctx, duk_uint_t val) {
#endif /* DUK_USE_FASTINT */
}
-DUK_EXTERNAL void duk_push_nan(duk_context *ctx) {
- duk_hthread *thr;
+DUK_EXTERNAL void duk_push_nan(duk_hthread *thr) {
duk_tval *tv_slot;
duk_double_union du;
- DUK_ASSERT_CTX_VALID(ctx);
- thr = (duk_hthread *) ctx;
+ DUK_ASSERT_API_ENTRY(thr);
DUK__CHECK_SPACE();
DUK_DBLUNION_SET_NAN(&du);
DUK_ASSERT(DUK_DBLUNION_IS_NORMALIZED(&du));
@@ -20647,12 +21365,11 @@ DUK_EXTERNAL void duk_push_nan(duk_context *ctx) {
DUK_TVAL_SET_NUMBER(tv_slot, du.d);
}
-DUK_EXTERNAL const char *duk_push_lstring(duk_context *ctx, const char *str, duk_size_t len) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL const char *duk_push_lstring(duk_hthread *thr, const char *str, duk_size_t len) {
duk_hstring *h;
duk_tval *tv_slot;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
/* check stack before interning (avoid hanging temp) */
DUK__CHECK_SPACE();
@@ -20681,52 +21398,47 @@ DUK_EXTERNAL const char *duk_push_lstring(duk_context *ctx, const char *str, duk
return (const char *) DUK_HSTRING_GET_DATA(h);
}
-DUK_EXTERNAL const char *duk_push_string(duk_context *ctx, const char *str) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL const char *duk_push_string(duk_hthread *thr, const char *str) {
+ DUK_ASSERT_API_ENTRY(thr);
if (str) {
- return duk_push_lstring(ctx, str, DUK_STRLEN(str));
+ return duk_push_lstring(thr, str, DUK_STRLEN(str));
} else {
- duk_push_null(ctx);
+ duk_push_null(thr);
return NULL;
}
}
-DUK_EXTERNAL void duk_push_pointer(duk_context *ctx, void *val) {
- duk_hthread *thr;
+DUK_EXTERNAL void duk_push_pointer(duk_hthread *thr, void *val) {
duk_tval *tv_slot;
- DUK_ASSERT_CTX_VALID(ctx);
- thr = (duk_hthread *) ctx;
+ DUK_ASSERT_API_ENTRY(thr);
DUK__CHECK_SPACE();
tv_slot = thr->valstack_top++;
DUK_TVAL_SET_POINTER(tv_slot, val);
}
-DUK_INTERNAL duk_hstring *duk_push_uint_to_hstring(duk_context *ctx, duk_uint_t i) {
+DUK_INTERNAL duk_hstring *duk_push_uint_to_hstring(duk_hthread *thr, duk_uint_t i) {
duk_hstring *h_tmp;
+ DUK_ASSERT_API_ENTRY(thr);
+
/* XXX: this could be a direct DUK_SPRINTF to a buffer followed by duk_push_string() */
- duk_push_uint(ctx, (duk_uint_t) i);
- h_tmp = duk_to_hstring_m1(ctx);
+ duk_push_uint(thr, (duk_uint_t) i);
+ h_tmp = duk_to_hstring_m1(thr);
DUK_ASSERT(h_tmp != NULL);
return h_tmp;
}
-DUK_LOCAL void duk__push_this_helper(duk_context *ctx, duk_small_uint_t check_object_coercible) {
- duk_hthread *thr;
+DUK_LOCAL void duk__push_this_helper(duk_hthread *thr, duk_small_uint_t check_object_coercible) {
duk_tval *tv_slot;
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_ASSERT_DISABLE(thr->callstack_top >= 0); /* avoid warning (unsigned) */
- thr = (duk_hthread *) ctx;
- DUK_ASSERT(thr->callstack_top <= thr->callstack_size);
DUK__CHECK_SPACE();
DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top)); /* because of valstack init policy */
tv_slot = thr->valstack_top++;
- if (DUK_UNLIKELY(thr->callstack_top == 0)) {
+ if (DUK_UNLIKELY(thr->callstack_curr == NULL)) {
if (check_object_coercible) {
goto type_error;
}
@@ -20752,132 +21464,119 @@ DUK_LOCAL void duk__push_this_helper(duk_context *ctx, duk_small_uint_t check_ob
DUK_ERROR_TYPE(thr, DUK_STR_NOT_OBJECT_COERCIBLE);
}
-DUK_EXTERNAL void duk_push_this(duk_context *ctx) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL void duk_push_this(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
- duk__push_this_helper(ctx, 0 /*check_object_coercible*/);
+ duk__push_this_helper(thr, 0 /*check_object_coercible*/);
}
-DUK_INTERNAL void duk_push_this_check_object_coercible(duk_context *ctx) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_INTERNAL void duk_push_this_check_object_coercible(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
- duk__push_this_helper(ctx, 1 /*check_object_coercible*/);
+ duk__push_this_helper(thr, 1 /*check_object_coercible*/);
}
-DUK_INTERNAL duk_hobject *duk_push_this_coercible_to_object(duk_context *ctx) {
+DUK_INTERNAL duk_hobject *duk_push_this_coercible_to_object(duk_hthread *thr) {
duk_hobject *h;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- duk__push_this_helper(ctx, 1 /*check_object_coercible*/);
- h = duk_to_hobject(ctx, -1);
+ duk__push_this_helper(thr, 1 /*check_object_coercible*/);
+ h = duk_to_hobject(thr, -1);
DUK_ASSERT(h != NULL);
return h;
}
-DUK_INTERNAL duk_hstring *duk_push_this_coercible_to_string(duk_context *ctx) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_INTERNAL duk_hstring *duk_push_this_coercible_to_string(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
- duk__push_this_helper(ctx, 1 /*check_object_coercible*/);
- return duk_to_hstring_m1(ctx); /* This will reject all Symbol values; accepts Symbol objects. */
+ duk__push_this_helper(thr, 1 /*check_object_coercible*/);
+ return duk_to_hstring_m1(thr); /* This will reject all Symbol values; accepts Symbol objects. */
}
-DUK_INTERNAL duk_tval *duk_get_borrowed_this_tval(duk_context *ctx) {
- duk_hthread *thr;
-
- DUK_ASSERT(ctx != NULL);
- thr = (duk_hthread *) ctx;
+DUK_INTERNAL duk_tval *duk_get_borrowed_this_tval(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(thr->callstack_top > 0); /* caller required to know */
- DUK_ASSERT(thr->callstack_curr != NULL);
+ DUK_ASSERT(thr->callstack_curr != NULL); /* caller required to know */
DUK_ASSERT(thr->valstack_bottom > thr->valstack); /* consequence of above */
DUK_ASSERT(thr->valstack_bottom - 1 >= thr->valstack); /* 'this' binding exists */
return thr->valstack_bottom - 1;
}
-DUK_EXTERNAL void duk_push_current_function(duk_context *ctx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_push_current_function(duk_hthread *thr) {
duk_activation *act;
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_ASSERT(thr != NULL);
- DUK_ASSERT_DISABLE(thr->callstack_top >= 0);
- DUK_ASSERT(thr->callstack_top <= thr->callstack_size);
+ DUK_ASSERT_API_ENTRY(thr);
act = thr->callstack_curr;
if (act != NULL) {
- duk_push_tval(ctx, &act->tv_func);
+ duk_push_tval(thr, &act->tv_func);
} else {
- duk_push_undefined(ctx);
+ duk_push_undefined(thr);
}
}
-DUK_EXTERNAL void duk_push_current_thread(duk_context *ctx) {
- duk_hthread *thr = (duk_hthread *) ctx;
-
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_ASSERT(thr != NULL);
+DUK_EXTERNAL void duk_push_current_thread(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
if (thr->heap->curr_thread) {
- duk_push_hobject(ctx, (duk_hobject *) thr->heap->curr_thread);
+ duk_push_hobject(thr, (duk_hobject *) thr->heap->curr_thread);
} else {
- duk_push_undefined(ctx);
+ duk_push_undefined(thr);
}
}
-DUK_EXTERNAL void duk_push_global_object(duk_context *ctx) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL void duk_push_global_object(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
- duk_push_hobject_bidx(ctx, DUK_BIDX_GLOBAL);
+ duk_push_hobject_bidx(thr, DUK_BIDX_GLOBAL);
}
/* XXX: size optimize */
-DUK_LOCAL void duk__push_stash(duk_context *ctx) {
- DUK_ASSERT_CTX_VALID(ctx);
- if (!duk_get_prop_stridx_short(ctx, -1, DUK_STRIDX_INT_VALUE)) {
+DUK_LOCAL void duk__push_stash(duk_hthread *thr) {
+ if (!duk_get_prop_stridx_short(thr, -1, DUK_STRIDX_INT_VALUE)) {
DUK_DDD(DUK_DDDPRINT("creating heap/global/thread stash on first use"));
- duk_pop(ctx);
- duk_push_bare_object(ctx);
- duk_dup_top(ctx);
- duk_xdef_prop_stridx_short(ctx, -3, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_C); /* [ ... parent stash stash ] -> [ ... parent stash ] */
+ duk_pop_unsafe(thr);
+ duk_push_bare_object(thr);
+ duk_dup_top(thr);
+ duk_xdef_prop_stridx_short(thr, -3, DUK_STRIDX_INT_VALUE, DUK_PROPDESC_FLAGS_C); /* [ ... parent stash stash ] -> [ ... parent stash ] */
}
- duk_remove_m2(ctx);
+ duk_remove_m2(thr);
}
-DUK_EXTERNAL void duk_push_heap_stash(duk_context *ctx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void duk_push_heap_stash(duk_hthread *thr) {
duk_heap *heap;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
heap = thr->heap;
DUK_ASSERT(heap->heap_object != NULL);
- duk_push_hobject(ctx, heap->heap_object);
- duk__push_stash(ctx);
+ duk_push_hobject(thr, heap->heap_object);
+ duk__push_stash(thr);
}
-DUK_EXTERNAL void duk_push_global_stash(duk_context *ctx) {
- DUK_ASSERT_CTX_VALID(ctx);
- duk_push_global_object(ctx);
- duk__push_stash(ctx);
+DUK_EXTERNAL void duk_push_global_stash(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ duk_push_global_object(thr);
+ duk__push_stash(thr);
}
-DUK_EXTERNAL void duk_push_thread_stash(duk_context *ctx, duk_context *target_ctx) {
- duk_hthread *thr = (duk_hthread *) ctx;
- DUK_ASSERT_CTX_VALID(ctx);
- if (DUK_UNLIKELY(target_ctx == NULL)) {
+DUK_EXTERNAL void duk_push_thread_stash(duk_hthread *thr, duk_hthread *target_thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ if (DUK_UNLIKELY(target_thr == NULL)) {
DUK_ERROR_TYPE_INVALID_ARGS(thr);
return; /* not reached */
}
- duk_push_hobject(ctx, (duk_hobject *) target_ctx);
- duk__push_stash(ctx);
+ duk_push_hobject(thr, (duk_hobject *) target_thr);
+ duk__push_stash(thr);
}
/* XXX: duk_ssize_t would be useful here */
-DUK_LOCAL duk_int_t duk__try_push_vsprintf(duk_context *ctx, void *buf, duk_size_t sz, const char *fmt, va_list ap) {
+DUK_LOCAL duk_int_t duk__try_push_vsprintf(duk_hthread *thr, void *buf, duk_size_t sz, const char *fmt, va_list ap) {
duk_int_t len;
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_UNREF(ctx);
+ DUK_ASSERT_CTX_VALID(thr);
+ DUK_UNREF(thr);
/* NUL terminator handling doesn't matter here */
len = DUK_VSNPRINTF((char *) buf, sz, fmt, ap);
@@ -20890,8 +21589,7 @@ DUK_LOCAL duk_int_t duk__try_push_vsprintf(duk_context *ctx, void *buf, duk_size
return -1;
}
-DUK_EXTERNAL const char *duk_push_vsprintf(duk_context *ctx, const char *fmt, va_list ap) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL const char *duk_push_vsprintf(duk_hthread *thr, const char *fmt, va_list ap) {
duk_uint8_t stack_buf[DUK_PUSH_SPRINTF_INITIAL_SIZE];
duk_size_t sz = DUK_PUSH_SPRINTF_INITIAL_SIZE;
duk_bool_t pushed_buf = 0;
@@ -20899,13 +21597,13 @@ DUK_EXTERNAL const char *duk_push_vsprintf(duk_context *ctx, const char *fmt, va
duk_int_t len; /* XXX: duk_ssize_t */
const char *res;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
/* special handling of fmt==NULL */
if (!fmt) {
duk_hstring *h_str;
- duk_push_hstring_empty(ctx);
- h_str = duk_known_hstring(ctx, -1);
+ duk_push_hstring_empty(thr);
+ h_str = duk_known_hstring(thr, -1);
return (const char *) DUK_HSTRING_GET_DATA(h_str);
}
@@ -20926,14 +21624,14 @@ DUK_EXTERNAL const char *duk_push_vsprintf(duk_context *ctx, const char *fmt, va
buf = stack_buf;
} else if (!pushed_buf) {
pushed_buf = 1;
- buf = duk_push_dynamic_buffer(ctx, sz);
+ buf = duk_push_dynamic_buffer(thr, sz);
} else {
- buf = duk_resize_buffer(ctx, -1, sz);
+ buf = duk_resize_buffer(thr, -1, sz);
}
DUK_ASSERT(buf != NULL);
DUK_VA_COPY(ap_copy, ap);
- len = duk__try_push_vsprintf(ctx, buf, sz, fmt, ap_copy);
+ len = duk__try_push_vsprintf(thr, buf, sz, fmt, ap_copy);
va_end(ap_copy);
if (len >= 0) {
break;
@@ -20949,33 +21647,32 @@ DUK_EXTERNAL const char *duk_push_vsprintf(duk_context *ctx, const char *fmt, va
/* Cannot use duk_buffer_to_string() on the buffer because it is
* usually larger than 'len'; 'buf' is also usually a stack buffer.
*/
- res = duk_push_lstring(ctx, (const char *) buf, (duk_size_t) len); /* [ buf? res ] */
+ res = duk_push_lstring(thr, (const char *) buf, (duk_size_t) len); /* [ buf? res ] */
if (pushed_buf) {
- duk_remove_m2(ctx);
+ duk_remove_m2(thr);
}
return res;
}
-DUK_EXTERNAL const char *duk_push_sprintf(duk_context *ctx, const char *fmt, ...) {
+DUK_EXTERNAL const char *duk_push_sprintf(duk_hthread *thr, const char *fmt, ...) {
va_list ap;
const char *ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
/* allow fmt==NULL */
va_start(ap, fmt);
- ret = duk_push_vsprintf(ctx, fmt, ap);
+ ret = duk_push_vsprintf(thr, fmt, ap);
va_end(ap);
return ret;
}
-DUK_INTERNAL duk_hobject *duk_push_object_helper(duk_context *ctx, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_INTERNAL duk_hobject *duk_push_object_helper(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx) {
duk_tval *tv_slot;
duk_hobject *h;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(prototype_bidx == -1 ||
(prototype_bidx >= 0 && prototype_bidx < DUK_NUM_BUILTINS));
@@ -20994,7 +21691,7 @@ DUK_INTERNAL duk_hobject *duk_push_object_helper(duk_context *ctx, duk_uint_t ho
/* object is now reachable */
if (prototype_bidx >= 0) {
- DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, h, thr->builtins[prototype_bidx]);
+ DUK_HOBJECT_SET_PROTOTYPE_INIT_INCREF(thr, h, thr->builtins[prototype_bidx]);
} else {
DUK_ASSERT(prototype_bidx == -1);
DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h) == NULL);
@@ -21003,38 +21700,35 @@ DUK_INTERNAL duk_hobject *duk_push_object_helper(duk_context *ctx, duk_uint_t ho
return h;
}
-DUK_INTERNAL duk_hobject *duk_push_object_helper_proto(duk_context *ctx, duk_uint_t hobject_flags_and_class, duk_hobject *proto) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_INTERNAL duk_hobject *duk_push_object_helper_proto(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_hobject *proto) {
duk_hobject *h;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
- h = duk_push_object_helper(ctx, hobject_flags_and_class, -1);
+ h = duk_push_object_helper(thr, hobject_flags_and_class, -1);
DUK_ASSERT(h != NULL);
- DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h) == NULL);
- DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, h, proto);
+ DUK_HOBJECT_SET_PROTOTYPE_INIT_INCREF(thr, h, proto);
return h;
}
-DUK_EXTERNAL duk_idx_t duk_push_object(duk_context *ctx) {
- DUK_ASSERT_CTX_VALID(ctx);
+DUK_EXTERNAL duk_idx_t duk_push_object(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
- (void) duk_push_object_helper(ctx,
+ (void) duk_push_object_helper(thr,
DUK_HOBJECT_FLAG_EXTENSIBLE |
DUK_HOBJECT_FLAG_FASTREFS |
DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT),
DUK_BIDX_OBJECT_PROTOTYPE);
- return duk_get_top_index_unsafe(ctx);
+ return duk_get_top_index_unsafe(thr);
}
-DUK_EXTERNAL duk_idx_t duk_push_array(duk_context *ctx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_idx_t duk_push_array(duk_hthread *thr) {
duk_uint_t flags;
duk_harray *obj;
duk_idx_t ret;
duk_tval *tv_slot;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
flags = DUK_HOBJECT_FLAG_EXTENSIBLE |
DUK_HOBJECT_FLAG_FASTREFS |
@@ -21045,8 +21739,7 @@ DUK_EXTERNAL duk_idx_t duk_push_array(duk_context *ctx) {
obj = duk_harray_alloc(thr, flags);
DUK_ASSERT(obj != NULL);
- /* XXX: since prototype is NULL, could save a check */
- DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, (duk_hobject *) obj, thr->builtins[DUK_BIDX_ARRAY_PROTOTYPE]);
+ DUK_HOBJECT_SET_PROTOTYPE_INIT_INCREF(thr, (duk_hobject *) obj, thr->builtins[DUK_BIDX_ARRAY_PROTOTYPE]);
tv_slot = thr->valstack_top;
DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) obj);
@@ -21058,13 +21751,13 @@ DUK_EXTERNAL duk_idx_t duk_push_array(duk_context *ctx) {
return ret;
}
-DUK_INTERNAL duk_harray *duk_push_harray(duk_context *ctx) {
+DUK_INTERNAL duk_harray *duk_push_harray(duk_hthread *thr) {
/* XXX: API call could do this directly, cast to void in API macro. */
- duk_hthread *thr;
duk_harray *a;
- thr = (duk_hthread *) ctx;
- (void) duk_push_array(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
+
+ (void) duk_push_array(thr);
DUK_ASSERT(DUK_TVAL_IS_OBJECT(thr->valstack_top - 1));
a = (duk_harray *) DUK_TVAL_GET_OBJECT(thr->valstack_top - 1);
DUK_ASSERT(a != NULL);
@@ -21074,12 +21767,14 @@ DUK_INTERNAL duk_harray *duk_push_harray(duk_context *ctx) {
/* Push a duk_harray with preallocated size (.length also set to match size).
* Caller may then populate array part of the duk_harray directly.
*/
-DUK_INTERNAL duk_harray *duk_push_harray_with_size(duk_context *ctx, duk_uint32_t size) {
+DUK_INTERNAL duk_harray *duk_push_harray_with_size(duk_hthread *thr, duk_uint32_t size) {
duk_harray *a;
- a = duk_push_harray(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
+
+ a = duk_push_harray(thr);
- duk_hobject_realloc_props((duk_hthread *) ctx,
+ duk_hobject_realloc_props(thr,
(duk_hobject *) a,
0,
size,
@@ -21089,13 +21784,22 @@ DUK_INTERNAL duk_harray *duk_push_harray_with_size(duk_context *ctx, duk_uint32_
return a;
}
-DUK_EXTERNAL duk_idx_t duk_push_thread_raw(duk_context *ctx, duk_uint_t flags) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_INTERNAL duk_tval *duk_push_harray_with_size_outptr(duk_hthread *thr, duk_uint32_t size) {
+ duk_harray *a;
+
+ DUK_ASSERT_API_ENTRY(thr);
+
+ a = duk_push_harray_with_size(thr, size);
+ DUK_ASSERT(a != NULL);
+ return DUK_HOBJECT_A_GET_BASE(thr->heap, (duk_hobject *) a);
+}
+
+DUK_EXTERNAL duk_idx_t duk_push_thread_raw(duk_hthread *thr, duk_uint_t flags) {
duk_hthread *obj;
duk_idx_t ret;
duk_tval *tv_slot;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK__CHECK_SPACE();
@@ -21134,11 +21838,10 @@ DUK_EXTERNAL duk_idx_t duk_push_thread_raw(duk_context *ctx, duk_uint_t flags) {
duk_hthread_copy_builtin_objects(thr, obj);
}
- /* default prototype (Note: 'obj' must be reachable) */
- /* XXX: since prototype is NULL, could save a check */
- DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, (duk_hobject *) obj, obj->builtins[DUK_BIDX_THREAD_PROTOTYPE]);
+ /* default prototype */
+ DUK_HOBJECT_SET_PROTOTYPE_INIT_INCREF(thr, (duk_hobject *) obj, obj->builtins[DUK_BIDX_THREAD_PROTOTYPE]);
- /* Initial stack size satisfies the stack spare constraints so there
+ /* Initial stack size satisfies the stack slack constraints so there
* is no need to require stack here.
*/
DUK_ASSERT(DUK_VALSTACK_INITIAL_SIZE >=
@@ -21147,12 +21850,11 @@ DUK_EXTERNAL duk_idx_t duk_push_thread_raw(duk_context *ctx, duk_uint_t flags) {
return ret;
}
-DUK_INTERNAL duk_hcompfunc *duk_push_hcompfunc(duk_context *ctx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_INTERNAL duk_hcompfunc *duk_push_hcompfunc(duk_hthread *thr) {
duk_hcompfunc *obj;
duk_tval *tv_slot;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK__CHECK_SPACE();
@@ -21163,6 +21865,7 @@ DUK_INTERNAL duk_hcompfunc *duk_push_hcompfunc(duk_context *ctx) {
obj = duk_hcompfunc_alloc(thr,
DUK_HOBJECT_FLAG_EXTENSIBLE |
+ DUK_HOBJECT_FLAG_CALLABLE |
DUK_HOBJECT_FLAG_COMPFUNC |
DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION));
if (DUK_UNLIKELY(obj == NULL)) {
@@ -21176,19 +21879,49 @@ DUK_INTERNAL duk_hcompfunc *duk_push_hcompfunc(duk_context *ctx) {
DUK_HOBJECT_INCREF(thr, obj);
thr->valstack_top++;
- DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, (duk_hobject *) obj, thr->builtins[DUK_BIDX_FUNCTION_PROTOTYPE]);
+ /* default prototype */
+ DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) obj) == NULL);
+ DUK_HOBJECT_SET_PROTOTYPE_INIT_INCREF(thr, (duk_hobject *) obj, thr->builtins[DUK_BIDX_FUNCTION_PROTOTYPE]);
return obj;
}
-DUK_LOCAL duk_idx_t duk__push_c_function_raw(duk_context *ctx, duk_c_function func, duk_idx_t nargs, duk_uint_t flags) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_INTERNAL duk_hboundfunc *duk_push_hboundfunc(duk_hthread *thr) {
+ duk_hboundfunc *obj;
+ duk_tval *tv_slot;
+
+ DUK_ASSERT_API_ENTRY(thr);
+
+ DUK__CHECK_SPACE();
+ obj = duk_hboundfunc_alloc(thr->heap,
+ DUK_HOBJECT_FLAG_EXTENSIBLE |
+ DUK_HOBJECT_FLAG_BOUNDFUNC |
+ DUK_HOBJECT_FLAG_CONSTRUCTABLE |
+ DUK_HOBJECT_FLAG_CALLABLE |
+ DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION));
+ if (!obj) {
+ DUK_ERROR_ALLOC_FAILED(thr);
+ }
+
+ tv_slot = thr->valstack_top++;
+ DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) obj);
+ DUK_HOBJECT_INCREF(thr, obj);
+
+ /* Prototype is left as NULL because the caller always sets it (and
+ * it depends on the target function).
+ */
+ DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) obj) == NULL);
+
+ return obj;
+}
+
+DUK_LOCAL duk_idx_t duk__push_c_function_raw(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_uint_t flags, duk_small_uint_t proto_bidx) {
duk_hnatfunc *obj;
duk_idx_t ret;
duk_tval *tv_slot;
duk_int16_t func_nargs;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_CTX_VALID(thr);
DUK__CHECK_SPACE();
@@ -21218,9 +21951,8 @@ DUK_LOCAL duk_idx_t duk__push_c_function_raw(duk_context *ctx, duk_c_function fu
ret = (duk_idx_t) (thr->valstack_top - thr->valstack_bottom);
thr->valstack_top++;
- /* default prototype (Note: 'obj' must be reachable) */
- DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, (duk_hobject *) obj, thr->builtins[DUK_BIDX_FUNCTION_PROTOTYPE]);
-
+ DUK_ASSERT_BIDX_VALID(proto_bidx);
+ DUK_HOBJECT_SET_PROTOTYPE_INIT_INCREF(thr, (duk_hobject *) obj, thr->builtins[proto_bidx]);
return ret;
api_error:
@@ -21228,31 +21960,35 @@ DUK_LOCAL duk_idx_t duk__push_c_function_raw(duk_context *ctx, duk_c_function fu
return 0; /* not reached */
}
-DUK_EXTERNAL duk_idx_t duk_push_c_function(duk_context *ctx, duk_c_function func, duk_int_t nargs) {
+DUK_EXTERNAL duk_idx_t duk_push_c_function(duk_hthread *thr, duk_c_function func, duk_int_t nargs) {
duk_uint_t flags;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
flags = DUK_HOBJECT_FLAG_EXTENSIBLE |
DUK_HOBJECT_FLAG_CONSTRUCTABLE |
+ DUK_HOBJECT_FLAG_CALLABLE |
DUK_HOBJECT_FLAG_FASTREFS |
DUK_HOBJECT_FLAG_NATFUNC |
DUK_HOBJECT_FLAG_NEWENV |
DUK_HOBJECT_FLAG_STRICT |
DUK_HOBJECT_FLAG_NOTAIL |
- DUK_HOBJECT_FLAG_EXOTIC_DUKFUNC |
DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION);
- return duk__push_c_function_raw(ctx, func, nargs, flags);
+ /* Default prototype is a Duktape specific %NativeFunctionPrototype%
+ * which provides .length and .name getters.
+ */
+ return duk__push_c_function_raw(thr, func, nargs, flags, DUK_BIDX_NATIVE_FUNCTION_PROTOTYPE);
}
-DUK_INTERNAL void duk_push_c_function_noexotic(duk_context *ctx, duk_c_function func, duk_int_t nargs) {
+DUK_INTERNAL void duk_push_c_function_builtin(duk_hthread *thr, duk_c_function func, duk_int_t nargs) {
duk_uint_t flags;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
flags = DUK_HOBJECT_FLAG_EXTENSIBLE |
DUK_HOBJECT_FLAG_CONSTRUCTABLE |
+ DUK_HOBJECT_FLAG_CALLABLE |
DUK_HOBJECT_FLAG_FASTREFS |
DUK_HOBJECT_FLAG_NATFUNC |
DUK_HOBJECT_FLAG_NEWENV |
@@ -21260,15 +21996,17 @@ DUK_INTERNAL void duk_push_c_function_noexotic(duk_context *ctx, duk_c_function
DUK_HOBJECT_FLAG_NOTAIL |
DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION);
- (void) duk__push_c_function_raw(ctx, func, nargs, flags);
+ /* Must use Function.prototype for standard built-in functions. */
+ (void) duk__push_c_function_raw(thr, func, nargs, flags, DUK_BIDX_FUNCTION_PROTOTYPE);
}
-DUK_INTERNAL void duk_push_c_function_noconstruct_noexotic(duk_context *ctx, duk_c_function func, duk_int_t nargs) {
+DUK_INTERNAL void duk_push_c_function_builtin_noconstruct(duk_hthread *thr, duk_c_function func, duk_int_t nargs) {
duk_uint_t flags;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
flags = DUK_HOBJECT_FLAG_EXTENSIBLE |
+ DUK_HOBJECT_FLAG_CALLABLE |
DUK_HOBJECT_FLAG_FASTREFS |
DUK_HOBJECT_FLAG_NATFUNC |
DUK_HOBJECT_FLAG_NEWENV |
@@ -21276,15 +22014,15 @@ DUK_INTERNAL void duk_push_c_function_noconstruct_noexotic(duk_context *ctx, duk
DUK_HOBJECT_FLAG_NOTAIL |
DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION);
- (void) duk__push_c_function_raw(ctx, func, nargs, flags);
+ /* Must use Function.prototype for standard built-in functions. */
+ (void) duk__push_c_function_raw(thr, func, nargs, flags, DUK_BIDX_FUNCTION_PROTOTYPE);
}
-DUK_EXTERNAL duk_idx_t duk_push_c_lightfunc(duk_context *ctx, duk_c_function func, duk_idx_t nargs, duk_idx_t length, duk_int_t magic) {
- duk_hthread *thr = (duk_hthread *) ctx;
- duk_tval tv_tmp;
+DUK_EXTERNAL duk_idx_t duk_push_c_lightfunc(duk_hthread *thr, duk_c_function func, duk_idx_t nargs, duk_idx_t length, duk_int_t magic) {
duk_small_uint_t lf_flags;
+ duk_tval *tv_slot;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK__CHECK_SPACE();
@@ -21302,11 +22040,12 @@ DUK_EXTERNAL duk_idx_t duk_push_c_lightfunc(duk_context *ctx, duk_c_function fun
goto api_error;
}
- lf_flags = DUK_LFUNC_FLAGS_PACK(magic, length, nargs);
- DUK_TVAL_SET_LIGHTFUNC(&tv_tmp, func, lf_flags);
- duk_push_tval(ctx, &tv_tmp); /* XXX: direct valstack write */
- DUK_ASSERT(thr->valstack_top != thr->valstack_bottom);
- return ((duk_idx_t) (thr->valstack_top - thr->valstack_bottom)) - 1;
+ lf_flags = DUK_LFUNC_FLAGS_PACK((duk_small_int_t) magic, (duk_small_uint_t) length, (duk_small_uint_t) nargs);
+ tv_slot = thr->valstack_top++;
+ DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(tv_slot));
+ DUK_TVAL_SET_LIGHTFUNC(tv_slot, func, lf_flags);
+ DUK_ASSERT(tv_slot >= thr->valstack_bottom);
+ return (duk_idx_t) (tv_slot - thr->valstack_bottom);
api_error:
DUK_ERROR_TYPE_INVALID_ARGS(thr);
@@ -21314,12 +22053,11 @@ DUK_EXTERNAL duk_idx_t duk_push_c_lightfunc(duk_context *ctx, duk_c_function fun
}
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
-DUK_INTERNAL duk_hbufobj *duk_push_bufobj_raw(duk_context *ctx, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_INTERNAL duk_hbufobj *duk_push_bufobj_raw(duk_hthread *thr, duk_uint_t hobject_flags_and_class, duk_small_int_t prototype_bidx) {
duk_hbufobj *obj;
duk_tval *tv_slot;
- DUK_ASSERT(ctx != NULL);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(prototype_bidx >= 0);
DUK__CHECK_SPACE();
@@ -21327,7 +22065,7 @@ DUK_INTERNAL duk_hbufobj *duk_push_bufobj_raw(duk_context *ctx, duk_uint_t hobje
obj = duk_hbufobj_alloc(thr, hobject_flags_and_class);
DUK_ASSERT(obj != NULL);
- DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, (duk_hobject *) obj, thr->builtins[prototype_bidx]);
+ DUK_HOBJECT_SET_PROTOTYPE_INIT_INCREF(thr, (duk_hobject *) obj, thr->builtins[prototype_bidx]);
DUK_ASSERT_HBUFOBJ_VALID(obj);
tv_slot = thr->valstack_top;
@@ -21364,23 +22102,20 @@ static const duk_uint32_t duk__bufobj_flags_lookup[] = {
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
-DUK_EXTERNAL void duk_push_buffer_object(duk_context *ctx, duk_idx_t idx_buffer, duk_size_t byte_offset, duk_size_t byte_length, duk_uint_t flags) {
- duk_hthread *thr;
+DUK_EXTERNAL void duk_push_buffer_object(duk_hthread *thr, duk_idx_t idx_buffer, duk_size_t byte_offset, duk_size_t byte_length, duk_uint_t flags) {
duk_hbufobj *h_bufobj;
duk_hbuffer *h_val;
+ duk_hobject *h_arraybuf;
duk_uint32_t tmp;
duk_uint_t classnum;
duk_uint_t protobidx;
duk_uint_t lookupidx;
duk_uint_t uint_offset, uint_length, uint_added;
- DUK_ASSERT_CTX_VALID(ctx);
- thr = (duk_hthread *) ctx;
- DUK_UNREF(thr);
+ DUK_ASSERT_API_ENTRY(thr);
/* The underlying types for offset/length in duk_hbufobj is
- * duk_uint_t; make sure argument values fit and that
- * offset + length does not wrap.
+ * duk_uint_t; make sure argument values fit.
*/
uint_offset = (duk_uint_t) byte_offset;
uint_length = (duk_uint_t) byte_length;
@@ -21389,11 +22124,6 @@ DUK_EXTERNAL void duk_push_buffer_object(duk_context *ctx, duk_idx_t idx_buffer,
goto range_error;
}
}
- uint_added = uint_offset + uint_length;
- if (DUK_UNLIKELY(uint_added < uint_offset)) {
- goto range_error;
- }
- DUK_ASSERT(uint_added >= uint_offset && uint_added >= uint_length);
DUK_ASSERT_DISABLE(flags >= 0); /* flags is unsigned */
lookupidx = flags;
@@ -21404,18 +22134,56 @@ DUK_EXTERNAL void duk_push_buffer_object(duk_context *ctx, duk_idx_t idx_buffer,
classnum = tmp >> 24;
protobidx = (tmp >> 16) & 0xff;
- h_val = duk_require_hbuffer(ctx, idx_buffer);
+ h_arraybuf = duk_get_hobject(thr, idx_buffer);
+ if (h_arraybuf != NULL && /* argument is an object */
+ flags != DUK_BUFOBJ_ARRAYBUFFER && /* creating a view */
+ DUK_HOBJECT_GET_CLASS_NUMBER(h_arraybuf) == DUK_HOBJECT_CLASS_ARRAYBUFFER /* argument is ArrayBuffer */) {
+ duk_uint_t tmp_offset;
+
+ DUK_ASSERT_HBUFOBJ_VALID((duk_hbufobj *) h_arraybuf);
+ h_val = ((duk_hbufobj *) h_arraybuf)->buf;
+ if (DUK_UNLIKELY(h_val == NULL)) {
+ goto arg_error;
+ }
+
+ tmp_offset = uint_offset + ((duk_hbufobj *) h_arraybuf)->offset;
+ if (DUK_UNLIKELY(tmp_offset < uint_offset)) {
+ goto range_error;
+ }
+ uint_offset = tmp_offset;
+
+ /* Note intentional difference to new TypedArray(): we allow
+ * caller to create an uncovered typed array (which is memory
+ * safe); new TypedArray() rejects it.
+ */
+ } else {
+ /* Handle unexpected object arguments here too, for nice error
+ * messages.
+ */
+ h_arraybuf = NULL;
+ h_val = duk_require_hbuffer(thr, idx_buffer);
+ }
+
+ /* Wrap check for offset+length. */
+ uint_added = uint_offset + uint_length;
+ if (DUK_UNLIKELY(uint_added < uint_offset)) {
+ goto range_error;
+ }
+ DUK_ASSERT(uint_added >= uint_offset && uint_added >= uint_length);
+
DUK_ASSERT(h_val != NULL);
- h_bufobj = duk_push_bufobj_raw(ctx,
+ h_bufobj = duk_push_bufobj_raw(thr,
DUK_HOBJECT_FLAG_EXTENSIBLE |
DUK_HOBJECT_FLAG_BUFOBJ |
DUK_HOBJECT_CLASS_AS_FLAGS(classnum),
- protobidx);
+ (duk_small_int_t) protobidx);
DUK_ASSERT(h_bufobj != NULL);
h_bufobj->buf = h_val;
DUK_HBUFFER_INCREF(thr, h_val);
+ h_bufobj->buf_prop = h_arraybuf;
+ DUK_HOBJECT_INCREF_ALLOWNULL(thr, h_arraybuf);
h_bufobj->offset = uint_offset;
h_bufobj->length = uint_length;
h_bufobj->shift = (tmp >> 4) & 0x0f;
@@ -21427,7 +22195,7 @@ DUK_EXTERNAL void duk_push_buffer_object(duk_context *ctx, duk_idx_t idx_buffer,
* provided as .buffer property of the view. The ArrayBuffer is
* referenced via duk_hbufobj->buf_prop and an inherited .buffer
* accessor returns it. The ArrayBuffer is created lazily on first
- * access so we don't need to do anything more here.
+ * access if necessary so we don't need to do anything more here.
*/
return;
@@ -21440,36 +22208,39 @@ DUK_EXTERNAL void duk_push_buffer_object(duk_context *ctx, duk_idx_t idx_buffer,
return; /* not reached */
}
#else /* DUK_USE_BUFFEROBJECT_SUPPORT */
-DUK_EXTERNAL void duk_push_buffer_object(duk_context *ctx, duk_idx_t idx_buffer, duk_size_t byte_offset, duk_size_t byte_length, duk_uint_t flags) {
+DUK_EXTERNAL void duk_push_buffer_object(duk_hthread *thr, duk_idx_t idx_buffer, duk_size_t byte_offset, duk_size_t byte_length, duk_uint_t flags) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_UNREF(idx_buffer);
DUK_UNREF(byte_offset);
DUK_UNREF(byte_length);
DUK_UNREF(flags);
- DUK_ERROR_UNSUPPORTED((duk_hthread *) ctx);
+ DUK_ERROR_UNSUPPORTED(thr);
}
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
-DUK_EXTERNAL duk_idx_t duk_push_error_object_va_raw(duk_context *ctx, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, va_list ap) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_idx_t duk_push_error_object_va_raw(duk_hthread *thr, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, va_list ap) {
duk_hobject *proto;
#if defined(DUK_USE_AUGMENT_ERROR_CREATE)
- duk_bool_t noblame_fileline;
+ duk_small_uint_t augment_flags;
#endif
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(thr != NULL);
DUK_UNREF(filename);
DUK_UNREF(line);
/* Error code also packs a tracedata related flag. */
#if defined(DUK_USE_AUGMENT_ERROR_CREATE)
- noblame_fileline = err_code & DUK_ERRCODE_FLAG_NOBLAME_FILELINE;
+ augment_flags = 0;
+ if (err_code & DUK_ERRCODE_FLAG_NOBLAME_FILELINE) {
+ augment_flags = DUK_AUGMENT_FLAG_NOBLAME_FILELINE;
+ }
#endif
err_code = err_code & (~DUK_ERRCODE_FLAG_NOBLAME_FILELINE);
/* error gets its 'name' from the prototype */
proto = duk_error_prototype_from_code(thr, err_code);
- (void) duk_push_object_helper_proto(ctx,
+ (void) duk_push_object_helper_proto(thr,
DUK_HOBJECT_FLAG_EXTENSIBLE |
DUK_HOBJECT_FLAG_FASTREFS |
DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_ERROR),
@@ -21477,8 +22248,8 @@ DUK_EXTERNAL duk_idx_t duk_push_error_object_va_raw(duk_context *ctx, duk_errcod
/* ... and its 'message' from an instance property */
if (fmt) {
- duk_push_vsprintf(ctx, fmt, ap);
- duk_xdef_prop_stridx_short(ctx, -2, DUK_STRIDX_MESSAGE, DUK_PROPDESC_FLAGS_WC);
+ duk_push_vsprintf(thr, fmt, ap);
+ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_MESSAGE, DUK_PROPDESC_FLAGS_WC);
} else {
/* If no explicit message given, put error code into message field
* (as a number). This is not fully in keeping with the Ecmascript
@@ -21486,8 +22257,8 @@ DUK_EXTERNAL duk_idx_t duk_push_error_object_va_raw(duk_context *ctx, duk_errcod
* constructors use ToString() on their argument). However, it's
* probably more useful than having a separate 'code' property.
*/
- duk_push_int(ctx, err_code);
- duk_xdef_prop_stridx_short(ctx, -2, DUK_STRIDX_MESSAGE, DUK_PROPDESC_FLAGS_WC);
+ duk_push_int(thr, err_code);
+ duk_xdef_prop_stridx_short(thr, -2, DUK_STRIDX_MESSAGE, DUK_PROPDESC_FLAGS_WC);
}
/* XXX: .code = err_code disabled, not sure if useful */
@@ -21495,49 +22266,48 @@ DUK_EXTERNAL duk_idx_t duk_push_error_object_va_raw(duk_context *ctx, duk_errcod
/* Creation time error augmentation */
#if defined(DUK_USE_AUGMENT_ERROR_CREATE)
/* filename may be NULL in which case file/line is not recorded */
- duk_err_augment_error_create(thr, thr, filename, line, noblame_fileline); /* may throw an error */
+ duk_err_augment_error_create(thr, thr, filename, line, augment_flags); /* may throw an error */
#endif
- return duk_get_top_index_unsafe(ctx);
+ return duk_get_top_index_unsafe(thr);
}
-DUK_EXTERNAL duk_idx_t duk_push_error_object_raw(duk_context *ctx, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, ...) {
+DUK_EXTERNAL duk_idx_t duk_push_error_object_raw(duk_hthread *thr, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *fmt, ...) {
va_list ap;
duk_idx_t ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
va_start(ap, fmt);
- ret = duk_push_error_object_va_raw(ctx, err_code, filename, line, fmt, ap);
+ ret = duk_push_error_object_va_raw(thr, err_code, filename, line, fmt, ap);
va_end(ap);
return ret;
}
#if !defined(DUK_USE_VARIADIC_MACROS)
-DUK_EXTERNAL duk_idx_t duk_push_error_object_stash(duk_context *ctx, duk_errcode_t err_code, const char *fmt, ...) {
+DUK_EXTERNAL duk_idx_t duk_push_error_object_stash(duk_hthread *thr, duk_errcode_t err_code, const char *fmt, ...) {
const char *filename = duk_api_global_filename;
duk_int_t line = duk_api_global_line;
va_list ap;
duk_idx_t ret;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
duk_api_global_filename = NULL;
duk_api_global_line = 0;
va_start(ap, fmt);
- ret = duk_push_error_object_va_raw(ctx, err_code, filename, line, fmt, ap);
+ ret = duk_push_error_object_va_raw(thr, err_code, filename, line, fmt, ap);
va_end(ap);
return ret;
}
#endif /* DUK_USE_VARIADIC_MACROS */
-DUK_EXTERNAL void *duk_push_buffer_raw(duk_context *ctx, duk_size_t size, duk_small_uint_t flags) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL void *duk_push_buffer_raw(duk_hthread *thr, duk_size_t size, duk_small_uint_t flags) {
duk_tval *tv_slot;
duk_hbuffer *h;
void *buf_data;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK__CHECK_SPACE();
@@ -21559,13 +22329,17 @@ DUK_EXTERNAL void *duk_push_buffer_raw(duk_context *ctx, duk_size_t size, duk_sm
return (void *) buf_data;
}
-DUK_INTERNAL void *duk_push_fixed_buffer_nozero(duk_context *ctx, duk_size_t len) {
- return duk_push_buffer_raw(ctx, len, DUK_BUF_FLAG_NOZERO);
+DUK_INTERNAL void *duk_push_fixed_buffer_nozero(duk_hthread *thr, duk_size_t len) {
+ DUK_ASSERT_API_ENTRY(thr);
+ return duk_push_buffer_raw(thr, len, DUK_BUF_FLAG_NOZERO);
}
-DUK_INTERNAL void *duk_push_fixed_buffer_zero(duk_context *ctx, duk_size_t len) {
+DUK_INTERNAL void *duk_push_fixed_buffer_zero(duk_hthread *thr, duk_size_t len) {
void *ptr;
- ptr = duk_push_buffer_raw(ctx, len, 0);
+
+ DUK_ASSERT_API_ENTRY(thr);
+
+ ptr = duk_push_buffer_raw(thr, len, 0);
#if !defined(DUK_USE_ZERO_BUFFER_DATA)
/* ES2015 requires zeroing even when DUK_USE_ZERO_BUFFER_DATA
* is not set.
@@ -21575,14 +22349,113 @@ DUK_INTERNAL void *duk_push_fixed_buffer_zero(duk_context *ctx, duk_size_t len)
return ptr;
}
+#if defined(DUK_USE_ES6_PROXY)
+DUK_EXTERNAL duk_idx_t duk_push_proxy(duk_hthread *thr, duk_uint_t proxy_flags) {
+ duk_hobject *h_target;
+ duk_hobject *h_handler;
+ duk_hproxy *h_proxy;
+ duk_tval *tv_slot;
+ duk_uint_t flags;
+
+ DUK_ASSERT_API_ENTRY(thr);
+ DUK_UNREF(proxy_flags);
+
+ /* DUK__CHECK_SPACE() unnecessary because the Proxy is written to
+ * value stack in-place.
+ */
+#if 0
+ DUK__CHECK_SPACE();
+#endif
+
+ /* Reject a proxy object as the target because it would need
+ * special handling in property lookups. (ES2015 has no such
+ * restriction.)
+ */
+ h_target = duk_require_hobject_promote_mask(thr, -2, DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER);
+ DUK_ASSERT(h_target != NULL);
+ if (DUK_HOBJECT_IS_PROXY(h_target)) {
+ goto fail_args;
+ }
+
+ /* Reject a proxy object as the handler because it would cause
+ * potentially unbounded recursion. (ES2015 has no such
+ * restriction.)
+ *
+ * There's little practical reason to use a lightfunc or a plain
+ * buffer as the handler table: one could only provide traps via
+ * their prototype objects (Function.prototype and ArrayBuffer.prototype).
+ * Even so, as lightfuncs and plain buffers mimic their object
+ * counterparts, they're promoted and accepted here.
+ */
+ h_handler = duk_require_hobject_promote_mask(thr, -1, DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER);
+ DUK_ASSERT(h_handler != NULL);
+ if (DUK_HOBJECT_IS_PROXY(h_handler)) {
+ goto fail_args;
+ }
+
+ /* XXX: Proxy object currently has no prototype, so ToPrimitive()
+ * coercion fails which is a bit confusing.
+ */
+
+ /* CALLABLE and CONSTRUCTABLE flags are copied from the (initial)
+ * target, see ES2015 Sections 9.5.15 and 9.5.13.
+ */
+ flags = DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) h_target) &
+ (DUK_HOBJECT_FLAG_CALLABLE | DUK_HOBJECT_FLAG_CONSTRUCTABLE);
+ flags |= DUK_HOBJECT_FLAG_EXTENSIBLE |
+ DUK_HOBJECT_FLAG_EXOTIC_PROXYOBJ;
+ if (flags & DUK_HOBJECT_FLAG_CALLABLE) {
+ flags |= DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_FUNCTION) |
+ DUK_HOBJECT_FLAG_SPECIAL_CALL;
+ } else {
+ flags |= DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT);
+ }
+
+ h_proxy = duk_hproxy_alloc(thr, flags);
+ DUK_ASSERT(h_proxy != NULL);
+ DUK_ASSERT(DUK_HOBJECT_GET_PROTOTYPE(thr->heap, (duk_hobject *) h_proxy) == NULL);
+
+ /* Initialize Proxy target and handler references; avoid INCREF
+ * by stealing the value stack refcounts via direct value stack
+ * manipulation. INCREF is needed for the Proxy itself however.
+ */
+ DUK_ASSERT(h_target != NULL);
+ h_proxy->target = h_target;
+ DUK_ASSERT(h_handler != NULL);
+ h_proxy->handler = h_handler;
+ DUK_ASSERT_HPROXY_VALID(h_proxy);
+
+ DUK_ASSERT(duk_get_hobject(thr, -2) == h_target);
+ DUK_ASSERT(duk_get_hobject(thr, -1) == h_handler);
+ tv_slot = thr->valstack_top - 2;
+ DUK_ASSERT(tv_slot >= thr->valstack_bottom);
+ DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) h_proxy);
+ DUK_HOBJECT_INCREF(thr, (duk_hobject *) h_proxy);
+ tv_slot++;
+ DUK_TVAL_SET_UNDEFINED(tv_slot); /* [ ... target handler ] -> [ ... proxy undefined ] */
+ thr->valstack_top = tv_slot; /* -> [ ... proxy ] */
+
+ DUK_DD(DUK_DDPRINT("created Proxy: %!iT", duk_get_tval(thr, -1)));
+
+ return (duk_idx_t) (thr->valstack_top - thr->valstack_bottom - 1);
+
+ fail_args:
+ DUK_ERROR_TYPE_INVALID_ARGS(thr);
+}
+#else /* DUK_USE_ES6_PROXY */
+DUK_EXTERNAL duk_idx_t duk_push_proxy(duk_hthread *thr, duk_uint_t proxy_flags) {
+ DUK_ASSERT_API_ENTRY(thr);
+ DUK_UNREF(proxy_flags);
+ DUK_ERROR_UNSUPPORTED(thr);
+}
+#endif /* DUK_USE_ES6_PROXY */
+
#if defined(DUK_USE_ASSERTIONS)
-DUK_LOCAL void duk__validate_push_heapptr(duk_context *ctx, void *ptr) {
+DUK_LOCAL void duk__validate_push_heapptr(duk_hthread *thr, void *ptr) {
duk_heaphdr *h;
duk_heaphdr *curr;
- duk_hthread *thr;
duk_bool_t found = 0;
- thr = (duk_hthread *) ctx;
h = (duk_heaphdr *) ptr;
if (h == NULL) {
/* Allowed. */
@@ -21675,12 +22548,11 @@ DUK_LOCAL void duk__validate_push_heapptr(duk_context *ctx, void *ptr) {
}
#endif /* DUK_USE_ASSERTIONS */
-DUK_EXTERNAL duk_idx_t duk_push_heapptr(duk_context *ctx, void *ptr) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_EXTERNAL duk_idx_t duk_push_heapptr(duk_hthread *thr, void *ptr) {
duk_idx_t ret;
duk_tval *tv;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
/* Reviving an object using a heap pointer is a dangerous API
* operation: if the application doesn't guarantee that the
@@ -21690,7 +22562,7 @@ DUK_EXTERNAL duk_idx_t duk_push_heapptr(duk_context *ctx, void *ptr) {
*/
#if defined(DUK_USE_ASSERTIONS)
- duk__validate_push_heapptr(ctx, ptr);
+ duk__validate_push_heapptr(thr, ptr);
#endif
DUK__CHECK_SPACE();
@@ -21768,83 +22640,79 @@ DUK_EXTERNAL duk_idx_t duk_push_heapptr(duk_context *ctx, void *ptr) {
}
/* Push object with no prototype, i.e. a "bare" object. */
-DUK_EXTERNAL duk_idx_t duk_push_bare_object(duk_context *ctx) {
- (void) duk_push_object_helper(ctx,
+DUK_EXTERNAL duk_idx_t duk_push_bare_object(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+
+ (void) duk_push_object_helper(thr,
DUK_HOBJECT_FLAG_EXTENSIBLE |
DUK_HOBJECT_FLAG_FASTREFS |
DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT),
-1); /* no prototype */
- return duk_get_top_index_unsafe(ctx);
+ return duk_get_top_index_unsafe(thr);
}
-DUK_INTERNAL void duk_push_hstring(duk_context *ctx, duk_hstring *h) {
+DUK_INTERNAL void duk_push_hstring(duk_hthread *thr, duk_hstring *h) {
duk_tval tv;
- DUK_ASSERT_CTX_VALID(ctx);
+
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(h != NULL);
+
DUK_TVAL_SET_STRING(&tv, h);
- duk_push_tval(ctx, &tv);
+ duk_push_tval(thr, &tv);
}
-DUK_INTERNAL void duk_push_hstring_stridx(duk_context *ctx, duk_small_uint_t stridx) {
- duk_hthread *thr = (duk_hthread *) ctx;
- DUK_UNREF(thr);
+DUK_INTERNAL void duk_push_hstring_stridx(duk_hthread *thr, duk_small_uint_t stridx) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT_STRIDX_VALID(stridx);
- duk_push_hstring(ctx, DUK_HTHREAD_GET_STRING(thr, stridx));
+ duk_push_hstring(thr, DUK_HTHREAD_GET_STRING(thr, stridx));
}
-DUK_INTERNAL void duk_push_hstring_empty(duk_context *ctx) {
- duk_hthread *thr = (duk_hthread *) ctx;
- DUK_UNREF(thr);
- duk_push_hstring(ctx, DUK_HTHREAD_GET_STRING(thr, DUK_STRIDX_EMPTY_STRING));
+DUK_INTERNAL void duk_push_hstring_empty(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ duk_push_hstring(thr, DUK_HTHREAD_GET_STRING(thr, DUK_STRIDX_EMPTY_STRING));
}
-DUK_INTERNAL void duk_push_hobject(duk_context *ctx, duk_hobject *h) {
+DUK_INTERNAL void duk_push_hobject(duk_hthread *thr, duk_hobject *h) {
duk_tval tv;
- DUK_ASSERT_CTX_VALID(ctx);
+
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(h != NULL);
+
DUK_TVAL_SET_OBJECT(&tv, h);
- duk_push_tval(ctx, &tv);
+ duk_push_tval(thr, &tv);
}
-DUK_INTERNAL void duk_push_hbuffer(duk_context *ctx, duk_hbuffer *h) {
+DUK_INTERNAL void duk_push_hbuffer(duk_hthread *thr, duk_hbuffer *h) {
duk_tval tv;
- DUK_ASSERT_CTX_VALID(ctx);
+
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(h != NULL);
+
DUK_TVAL_SET_BUFFER(&tv, h);
- duk_push_tval(ctx, &tv);
+ duk_push_tval(thr, &tv);
}
-DUK_INTERNAL void duk_push_hobject_bidx(duk_context *ctx, duk_small_int_t builtin_idx) {
- duk_hthread *thr = (duk_hthread *) ctx;
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_ASSERT(thr != NULL);
+DUK_INTERNAL void duk_push_hobject_bidx(duk_hthread *thr, duk_small_int_t builtin_idx) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(builtin_idx >= 0 && builtin_idx < DUK_NUM_BUILTINS);
DUK_ASSERT(thr->builtins[builtin_idx] != NULL);
- duk_push_hobject(ctx, thr->builtins[builtin_idx]);
+
+ duk_push_hobject(thr, thr->builtins[builtin_idx]);
}
/*
* Poppers
*/
-DUK_EXTERNAL void duk_pop_n(duk_context *ctx, duk_idx_t count) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_LOCAL DUK_ALWAYS_INLINE void duk__pop_n_unsafe_raw(duk_hthread *thr, duk_idx_t count) {
duk_tval *tv;
#if defined(DUK_USE_REFERENCE_COUNTING)
duk_tval *tv_end;
#endif
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
-
- if (DUK_UNLIKELY(count < 0)) {
- DUK_ERROR_RANGE_INVALID_COUNT(thr);
- return;
- }
-
- if (DUK_UNLIKELY((duk_size_t) (thr->valstack_top - thr->valstack_bottom) < (duk_size_t) count)) {
- DUK_ERROR_RANGE_INVALID_COUNT(thr);
- }
+ DUK_ASSERT_CTX_VALID(thr);
+ DUK_ASSERT(count >= 0);
+ DUK_ASSERT((duk_size_t) (thr->valstack_top - thr->valstack_bottom) >= (duk_size_t) count);
#if defined(DUK_USE_REFERENCE_COUNTING)
tv = thr->valstack_top;
@@ -21870,49 +22738,37 @@ DUK_EXTERNAL void duk_pop_n(duk_context *ctx, duk_idx_t count) {
DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
}
-DUK_INTERNAL void duk_pop_n_unsafe(duk_context *ctx, duk_idx_t count) {
- duk_hthread *thr = (duk_hthread *) ctx;
- duk_tval *tv;
-#if defined(DUK_USE_REFERENCE_COUNTING)
- duk_tval *tv_end;
-#endif
-
- DUK_ASSERT_CTX_VALID(ctx);
- DUK_ASSERT(count >= 0);
+DUK_EXTERNAL void duk_pop_n(duk_hthread *thr, duk_idx_t count) {
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
- DUK_ASSERT((duk_size_t) (thr->valstack_top - thr->valstack_bottom) >= (duk_size_t) count);
-#if defined(DUK_USE_REFERENCE_COUNTING)
- tv = thr->valstack_top;
- tv_end = tv - count;
- while (tv != tv_end) {
- tv--;
- DUK_ASSERT(tv >= thr->valstack_bottom);
- DUK_TVAL_SET_UNDEFINED_UPDREF_NORZ(thr, tv);
- }
- thr->valstack_top = tv;
- DUK_REFZERO_CHECK_FAST(thr);
-#else
- tv = thr->valstack_top;
- while (count > 0) {
- count--;
- tv--;
- DUK_ASSERT(tv >= thr->valstack_bottom);
- DUK_TVAL_SET_UNDEFINED(tv);
+ if (DUK_UNLIKELY((duk_uidx_t) (thr->valstack_top - thr->valstack_bottom) < (duk_uidx_t) count)) {
+ DUK_ERROR_RANGE_INVALID_COUNT(thr);
+ return;
}
- thr->valstack_top = tv;
-#endif
+ DUK_ASSERT(count >= 0);
- DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
+ duk__pop_n_unsafe_raw(thr, count);
}
-/* Pop N elements without DECREF (in effect "stealing" the refcounts). */
+#if defined(DUK_USE_PREFER_SIZE)
+DUK_INTERNAL void duk_pop_n_unsafe(duk_hthread *thr, duk_idx_t count) {
+ DUK_ASSERT_API_ENTRY(thr);
+ duk_pop_n(thr, count);
+}
+#else /* DUK_USE_PREFER_SIZE */
+DUK_INTERNAL void duk_pop_n_unsafe(duk_hthread *thr, duk_idx_t count) {
+ DUK_ASSERT_API_ENTRY(thr);
+ duk__pop_n_unsafe_raw(thr, count);
+}
+#endif /* DUK_USE_PREFER_SIZE */
+
+/* Pop N elements without DECREF (in effect "stealing" any actual refcounts). */
#if defined(DUK_USE_REFERENCE_COUNTING)
-DUK_INTERNAL void duk_pop_n_nodecref_unsafe(duk_context *ctx, duk_idx_t count) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_INTERNAL void duk_pop_n_nodecref_unsafe(duk_hthread *thr, duk_idx_t count) {
duk_tval *tv;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_API_ENTRY(thr);
DUK_ASSERT(count >= 0);
DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
DUK_ASSERT((duk_size_t) (thr->valstack_top - thr->valstack_bottom) >= (duk_size_t) count);
@@ -21929,8 +22785,9 @@ DUK_INTERNAL void duk_pop_n_nodecref_unsafe(duk_context *ctx, duk_idx_t count) {
DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
}
#else /* DUK_USE_REFERENCE_COUNTING */
-DUK_INTERNAL void duk_pop_n_nodecref_unsafe(duk_context *ctx, duk_idx_t count) {
- duk_pop_n_unsafe(ctx, count);
+DUK_INTERNAL void duk_pop_n_nodecref_unsafe(duk_hthread *thr, duk_idx_t count) {
+ DUK_ASSERT_API_ENTRY(thr);
+ duk_pop_n_unsafe(thr, count);
}
#endif /* DUK_USE_REFERENCE_COUNTING */
@@ -21938,51 +22795,116 @@ DUK_INTERNAL void duk_pop_n_nodecref_unsafe(duk_context *ctx, duk_idx_t count) {
* compile a specialized function for it.
*/
#if defined(DUK_USE_PREFER_SIZE)
-DUK_EXTERNAL void duk_pop(duk_context *ctx) {
- DUK_ASSERT_CTX_VALID(ctx);
- duk_pop_n(ctx, 1);
+DUK_EXTERNAL void duk_pop(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ duk_pop_n(thr, 1);
}
-#else
-DUK_EXTERNAL void duk_pop(duk_context *ctx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_INTERNAL void duk_pop_unsafe(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ duk_pop_n_unsafe(thr, 1);
+}
+DUK_INTERNAL void duk_pop_nodecref_unsafe(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ duk_pop_n_nodecref_unsafe(thr, 1);
+}
+#else /* DUK_USE_PREFER_SIZE */
+DUK_LOCAL DUK_ALWAYS_INLINE void duk__pop_unsafe_raw(duk_hthread *thr) {
duk_tval *tv;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_CTX_VALID(thr);
+ DUK_ASSERT(thr->valstack_top != thr->valstack_bottom);
DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
- if (DUK_UNLIKELY(thr->valstack_top == thr->valstack_bottom)) {
- DUK_ERROR_RANGE_INVALID_COUNT(thr);
- }
+ DUK_ASSERT((duk_size_t) (thr->valstack_top - thr->valstack_bottom) >= (duk_size_t) 1);
- tv = --thr->valstack_top; /* tv points to element just below prev top */
+ tv = --thr->valstack_top;
DUK_ASSERT(tv >= thr->valstack_bottom);
#if defined(DUK_USE_REFERENCE_COUNTING)
DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */
#else
DUK_TVAL_SET_UNDEFINED(tv);
#endif
+
+ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
+}
+DUK_EXTERNAL void duk_pop(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+
+ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
+ if (DUK_UNLIKELY(thr->valstack_top == thr->valstack_bottom)) {
+ DUK_ERROR_RANGE_INVALID_COUNT(thr);
+ }
+
+ duk__pop_unsafe_raw(thr);
+}
+DUK_INTERNAL void duk_pop_unsafe(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ duk__pop_unsafe_raw(thr);
+}
+DUK_INTERNAL void duk_pop_nodecref_unsafe(duk_hthread *thr) {
+ duk_tval *tv;
+
+ DUK_ASSERT_API_ENTRY(thr);
+ DUK_ASSERT(thr->valstack_top != thr->valstack_bottom);
+ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
+ DUK_ASSERT((duk_size_t) (thr->valstack_top - thr->valstack_bottom) >= (duk_size_t) 1);
+
+ tv = --thr->valstack_top;
+ DUK_ASSERT(tv >= thr->valstack_bottom);
+ DUK_TVAL_SET_UNDEFINED(tv);
+
DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
}
#endif /* !DUK_USE_PREFER_SIZE */
-/* Unsafe internal variant which assumes there are enough values on the value
- * stack so that a top check can be skipped safely.
- */
#if defined(DUK_USE_PREFER_SIZE)
-DUK_INTERNAL void duk_pop_unsafe(duk_context *ctx) {
- DUK_ASSERT_CTX_VALID(ctx);
- duk_pop_n_unsafe(ctx, 1);
+DUK_INTERNAL void duk_pop_undefined(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ duk_pop_nodecref_unsafe(thr);
+}
+#else /* DUK_USE_PREFER_SIZE */
+DUK_INTERNAL void duk_pop_undefined(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ DUK_ASSERT(thr->valstack_top != thr->valstack_bottom);
+ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
+ DUK_ASSERT((duk_size_t) (thr->valstack_top - thr->valstack_bottom) >= (duk_size_t) 1);
+
+ DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top - 1));
+ thr->valstack_top--;
+
+ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
+}
+#endif /* !DUK_USE_PREFER_SIZE */
+
+#if defined(DUK_USE_PREFER_SIZE)
+DUK_EXTERNAL void duk_pop_2(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ duk_pop_n(thr, 2);
+}
+DUK_INTERNAL void duk_pop_2_unsafe(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ duk_pop_n_unsafe(thr, 2);
+}
+DUK_INTERNAL void duk_pop_2_nodecref_unsafe(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ duk_pop_n_nodecref_unsafe(thr, 2);
}
#else
-DUK_INTERNAL void duk_pop_unsafe(duk_context *ctx) {
- duk_hthread *thr = (duk_hthread *) ctx;
+DUK_LOCAL DUK_ALWAYS_INLINE void duk__pop_2_unsafe_raw(duk_hthread *thr) {
duk_tval *tv;
- DUK_ASSERT_CTX_VALID(ctx);
+ DUK_ASSERT_CTX_VALID(thr);
DUK_ASSERT(thr->valstack_top != thr->valstack_bottom);
DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
- DUK_ASSERT((duk_size_t) (thr->valstack_top - thr->valstack_bottom) >= (duk_size_t) 1);
+ DUK_ASSERT((duk_size_t) (thr->valstack_top - thr->valstack_bottom) >= (duk_size_t) 2);
- tv = --thr->valstack_top; /* tv points to element just below prev top */
+ tv = --thr->valstack_top;
+ DUK_ASSERT(tv >= thr->valstack_bottom);
+#if defined(DUK_USE_REFERENCE_COUNTING)
+ DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */
+#else
+ DUK_TVAL_SET_UNDEFINED(tv);
+#endif
+ tv = --thr->valstack_top;
DUK_ASSERT(tv >= thr->valstack_bottom);
#if defined(DUK_USE_REFERENCE_COUNTING)
DUK_TVAL_SET_UNDEFINED_UPDREF(thr, tv); /* side effects */
@@ -21992,16 +22914,47 @@ DUK_INTERNAL void duk_pop_unsafe(duk_context *ctx) {
DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
}
+DUK_EXTERNAL void duk_pop_2(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+
+ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
+ if (DUK_UNLIKELY(thr->valstack_top - 2 < thr->valstack_bottom)) {
+ DUK_ERROR_RANGE_INVALID_COUNT(thr);
+ }
+
+ duk__pop_2_unsafe_raw(thr);
+}
+DUK_INTERNAL void duk_pop_2_unsafe(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ duk__pop_2_unsafe_raw(thr);
+}
+DUK_INTERNAL void duk_pop_2_nodecref_unsafe(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ DUK_ASSERT(thr->valstack_top != thr->valstack_bottom);
+ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
+ DUK_ASSERT((duk_size_t) (thr->valstack_top - thr->valstack_bottom) >= (duk_size_t) 2);
+
+ DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top - 1));
+ DUK_ASSERT(DUK_TVAL_IS_UNDEFINED(thr->valstack_top - 2));
+ thr->valstack_top -= 2;
+
+ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
+}
#endif /* !DUK_USE_PREFER_SIZE */
-DUK_EXTERNAL void duk_pop_2(duk_context *ctx) {
- DUK_ASSERT_CTX_VALID(ctx);
- duk_pop_n(ctx, 2);
+DUK_EXTERNAL void duk_pop_3(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ duk_pop_n(thr, 3);
}
-DUK_EXTERNAL void duk_pop_3(duk_context *ctx) {
- DUK_ASSERT_CTX_VALID(ctx);
- duk_pop_n(ctx, 3);
+DUK_INTERNAL void duk_pop_3_unsafe(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ duk_pop_n_unsafe(thr, 3);
+}
+
+DUK_INTERNAL void duk_pop_3_nodecref_unsafe(duk_hthread *thr) {
+ DUK_ASSERT_API_ENTRY(thr);
+ duk_pop_n_nodecref_unsafe(thr, 3);
}
/*
@@ -22009,43 +22962,40 @@ DUK_EXTERNAL void duk_pop_3(duk_context *ctx) {
*/
/* XXX: pack index range? array index offset? */
-DUK_INTERNAL void duk_pack(duk_context *ctx, duk_idx_t count) {
- duk_hthread *thr;
- duk_harray *a;
+DUK_INTERNAL void duk_pack(duk_hthread *thr, duk_idx_t count) {
duk_tval *tv_src;
duk_tval *tv_dst;
duk_tval *tv_curr;
duk_tval *tv_limit;
duk_idx_t top;
- DUK_ASSERT_CTX_VALID(ctx);
- thr = (duk_hthread *) ctx;
+ DUK_ASSERT_API_ENTRY(thr);
+ DUK_ASSERT(thr->valstack_top >= thr->valstack_bottom);
top = (duk_idx_t) (thr->valstack_top - thr->valstack_bottom);
- if (DUK_UNLIKELY(count < 0 || count > top)) {
+ DUK_ASSERT(top >= 0);
+ if (DUK_UNLIKELY((duk_uidx_t) count > (duk_uidx_t) top)) {
+ /* Also handles negative count. */
DUK_ERROR_RANGE_INVALID_COUNT(thr);
return;
}
+ DUK_ASSERT(count >= 0);
/* Wrapping is controlled by the check above: value stack top can be
- * at most thr->valstack_max which is low enough so that multiplying
- * with sizeof(duk_tval) won't wrap.
+ * at most DUK_USE_VALSTACK_LIMIT which is low enough so that
+ * multiplying with sizeof(duk_tval) won't wrap.
*/
- DUK_ASSERT(count >= 0 && count <= (duk_idx_t) thr->valstack_max);
+ DUK_ASSERT(count >= 0 && count <= (duk_idx_t) DUK_USE_VALSTACK_LIMIT);
DUK_ASSERT((duk_size_t) count <= DUK_SIZE_MAX / sizeof(duk_tval)); /* no wrapping */
- a = duk_push_harray_with_size(ctx, (duk_uint32_t) count); /* XXX: uninitialized would be OK */
- DUK_ASSERT(a != NULL);
- DUK_ASSERT(DUK_HOBJECT_GET_ASIZE((duk_hobject *) a) == (duk_uint32_t) count);
- DUK_ASSERT(count == 0 || DUK_HOBJECT_A_GET_BASE(thr->heap, (duk_hobject *) a) != NULL);
- DUK_ASSERT((duk_idx_t) a->length == count);
+ tv_dst = duk_push_harray_with_size_outptr(thr, (duk_uint32_t) count); /* XXX: uninitialized would be OK */
+ DUK_ASSERT(count == 0 || tv_dst != NULL);
/* Copy value stack values directly to the array part without
* any refcount updates: net refcount changes are zero.
*/
tv_src = thr->valstack_top - count - 1;
- tv_dst = DUK_HOBJECT_A_GET_BASE(thr->heap, (duk_hobject *) a);
DUK_MEMCPY((void *) tv_dst, (const void *) tv_src, (size_t) count * sizeof(duk_tval));
/* Overwrite result array to final value stack location and wipe
@@ -22067,26 +23017,118 @@ DUK_INTERNAL void duk_pack(duk_context *ctx, duk_idx_t count) {
thr->valstack_top = tv_dst + 1;
}
-#if 0
-/* XXX: unpack to position? */
-DUK_INTERNAL void duk_unpack(duk_context *ctx) {
- /* - dense with length <= a_part
- * - dense with length > a_part
- * - sparse
- * - array-like but not actually an array?
- * - how to deal with 'unused' values (gaps); inherit or ignore?
- */
+DUK_INTERNAL duk_idx_t duk_unpac