From 5258785c81959109138ebeca613f12c277188abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Thu, 21 Dec 2017 13:56:11 +0200 Subject: cmd, core, eth/tracers: support fancier js tracing (#15516) * cmd, core, eth/tracers: support fancier js tracing * eth, internal/web3ext: rework trace API, concurrency, chain tracing * eth/tracers: add three more JavaScript tracers * eth/tracers, vendor: swap ottovm to duktape for tracing * core, eth, internal: finalize call tracer and needed extras * eth, tests: prestate tracer, call test suite, rewinding * vendor: fix windows builds for tracer js engine * vendor: temporary duktape fix * eth/tracers: fix up 4byte and evmdis tracer * vendor: pull in latest duktape with my upstream fixes * eth: fix some review comments * eth: rename rewind to reexec to make it more obvious * core/vm: terminate tracing using defers --- vendor/gopkg.in/olebedev/go-duktape.v3/Gopkg.lock | 21 + vendor/gopkg.in/olebedev/go-duktape.v3/Gopkg.toml | 3 + vendor/gopkg.in/olebedev/go-duktape.v3/LICENSE.md | 21 + vendor/gopkg.in/olebedev/go-duktape.v3/README.md | 124 + vendor/gopkg.in/olebedev/go-duktape.v3/api.go | 1616 + .../gopkg.in/olebedev/go-duktape.v3/appveyor.yml | 34 + vendor/gopkg.in/olebedev/go-duktape.v3/conts.go | 121 + .../olebedev/go-duktape.v3/duk_alloc_pool.c | 612 + .../olebedev/go-duktape.v3/duk_alloc_pool.h | 223 + .../gopkg.in/olebedev/go-duktape.v3/duk_config.h | 3672 + .../gopkg.in/olebedev/go-duktape.v3/duk_console.c | 163 + .../gopkg.in/olebedev/go-duktape.v3/duk_console.h | 14 + .../gopkg.in/olebedev/go-duktape.v3/duk_logging.c | 380 + .../gopkg.in/olebedev/go-duktape.v3/duk_logging.h | 20 + .../olebedev/go-duktape.v3/duk_minimal_printf.c | 312 + .../olebedev/go-duktape.v3/duk_minimal_printf.h | 12 + .../olebedev/go-duktape.v3/duk_module_duktape.c | 471 + .../olebedev/go-duktape.v3/duk_module_duktape.h | 14 + .../olebedev/go-duktape.v3/duk_module_node.c | 333 + .../olebedev/go-duktape.v3/duk_module_node.h | 9 + .../olebedev/go-duktape.v3/duk_print_alert.c | 127 + .../olebedev/go-duktape.v3/duk_print_alert.h | 10 + .../olebedev/go-duktape.v3/duk_v1_compat.c | 131 + .../olebedev/go-duktape.v3/duk_v1_compat.h | 28 + vendor/gopkg.in/olebedev/go-duktape.v3/duktape.c | 95118 +++++++++++++++++++ vendor/gopkg.in/olebedev/go-duktape.v3/duktape.go | 356 + vendor/gopkg.in/olebedev/go-duktape.v3/duktape.h | 1349 + vendor/gopkg.in/olebedev/go-duktape.v3/timers.go | 136 + vendor/gopkg.in/olebedev/go-duktape.v3/utils.go | 10 + vendor/gopkg.in/olebedev/go-duktape.v3/wercker.yml | 14 + 30 files changed, 105454 insertions(+) create mode 100644 vendor/gopkg.in/olebedev/go-duktape.v3/Gopkg.lock create mode 100644 vendor/gopkg.in/olebedev/go-duktape.v3/Gopkg.toml create mode 100644 vendor/gopkg.in/olebedev/go-duktape.v3/LICENSE.md create mode 100644 vendor/gopkg.in/olebedev/go-duktape.v3/README.md create mode 100644 vendor/gopkg.in/olebedev/go-duktape.v3/api.go create mode 100644 vendor/gopkg.in/olebedev/go-duktape.v3/appveyor.yml create mode 100644 vendor/gopkg.in/olebedev/go-duktape.v3/conts.go create mode 100755 vendor/gopkg.in/olebedev/go-duktape.v3/duk_alloc_pool.c create mode 100755 vendor/gopkg.in/olebedev/go-duktape.v3/duk_alloc_pool.h create mode 100755 vendor/gopkg.in/olebedev/go-duktape.v3/duk_config.h create mode 100755 vendor/gopkg.in/olebedev/go-duktape.v3/duk_console.c create mode 100755 vendor/gopkg.in/olebedev/go-duktape.v3/duk_console.h create mode 100755 vendor/gopkg.in/olebedev/go-duktape.v3/duk_logging.c create mode 100755 vendor/gopkg.in/olebedev/go-duktape.v3/duk_logging.h create mode 100755 vendor/gopkg.in/olebedev/go-duktape.v3/duk_minimal_printf.c create mode 100755 vendor/gopkg.in/olebedev/go-duktape.v3/duk_minimal_printf.h create mode 100755 vendor/gopkg.in/olebedev/go-duktape.v3/duk_module_duktape.c create mode 100755 vendor/gopkg.in/olebedev/go-duktape.v3/duk_module_duktape.h create mode 100755 vendor/gopkg.in/olebedev/go-duktape.v3/duk_module_node.c create mode 100755 vendor/gopkg.in/olebedev/go-duktape.v3/duk_module_node.h create mode 100755 vendor/gopkg.in/olebedev/go-duktape.v3/duk_print_alert.c create mode 100755 vendor/gopkg.in/olebedev/go-duktape.v3/duk_print_alert.h create mode 100755 vendor/gopkg.in/olebedev/go-duktape.v3/duk_v1_compat.c create mode 100755 vendor/gopkg.in/olebedev/go-duktape.v3/duk_v1_compat.h create mode 100755 vendor/gopkg.in/olebedev/go-duktape.v3/duktape.c create mode 100644 vendor/gopkg.in/olebedev/go-duktape.v3/duktape.go create mode 100755 vendor/gopkg.in/olebedev/go-duktape.v3/duktape.h create mode 100644 vendor/gopkg.in/olebedev/go-duktape.v3/timers.go create mode 100644 vendor/gopkg.in/olebedev/go-duktape.v3/utils.go create mode 100644 vendor/gopkg.in/olebedev/go-duktape.v3/wercker.yml (limited to 'vendor/gopkg.in/olebedev/go-duktape.v3') diff --git a/vendor/gopkg.in/olebedev/go-duktape.v3/Gopkg.lock b/vendor/gopkg.in/olebedev/go-duktape.v3/Gopkg.lock new file mode 100644 index 000000000..c1b0e0a3f --- /dev/null +++ b/vendor/gopkg.in/olebedev/go-duktape.v3/Gopkg.lock @@ -0,0 +1,21 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + branch = "v1" + name = "gopkg.in/check.v1" + packages = ["."] + revision = "20d25e2804050c1cd24a7eea1e7a6447dd0e74ec" + +[[projects]] + branch = "v3" + name = "gopkg.in/olebedev/go-duktape.v3" + packages = ["."] + revision = "391c1c40178e77a6003d889b96e0e41129aeb894" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + inputs-digest = "043f802c0b40e2622bf784443d3e3959f0d01e9a795e3bfe30a72060dec10c63" + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/vendor/gopkg.in/olebedev/go-duktape.v3/Gopkg.toml b/vendor/gopkg.in/olebedev/go-duktape.v3/Gopkg.toml new file mode 100644 index 000000000..ea8dc6de3 --- /dev/null +++ b/vendor/gopkg.in/olebedev/go-duktape.v3/Gopkg.toml @@ -0,0 +1,3 @@ +[[constraint]] + branch = "v1" + name = "gopkg.in/check.v1" \ No newline at end of file diff --git a/vendor/gopkg.in/olebedev/go-duktape.v3/LICENSE.md b/vendor/gopkg.in/olebedev/go-duktape.v3/LICENSE.md new file mode 100644 index 000000000..785c85309 --- /dev/null +++ b/vendor/gopkg.in/olebedev/go-duktape.v3/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015 Oleg Lebedev + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/gopkg.in/olebedev/go-duktape.v3/README.md b/vendor/gopkg.in/olebedev/go-duktape.v3/README.md new file mode 100644 index 000000000..2ddaad5e1 --- /dev/null +++ b/vendor/gopkg.in/olebedev/go-duktape.v3/README.md @@ -0,0 +1,124 @@ +# Duktape bindings for Go(Golang) + +[![wercker status](https://app.wercker.com/status/3a5bb2e639a4b4efaf4c8bf7cab7442d/s "wercker status")](https://app.wercker.com/project/bykey/3a5bb2e639a4b4efaf4c8bf7cab7442d) +[![Travis status](https://travis-ci.org/olebedev/go-duktape.svg?branch=v3)](https://travis-ci.org/olebedev/go-duktape) +[![Appveyor status](https://ci.appveyor.com/api/projects/status/github/olebedev/go-duktape?branch=v3&svg=true)](https://ci.appveyor.com/project/olebedev/go-duktape/branch/v3) +[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/olebedev/go-duktape?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) + +[Duktape](http://duktape.org/index.html) is a thin, embeddable javascript engine. +Most of the [api](http://duktape.org/api.html) is implemented. +The exceptions are listed [here](https://github.com/olebedev/go-duktape/blob/master/api.go#L1566). + +### Usage + +The package is fully go-getable, no need to install any external C libraries. +So, just type `go get gopkg.in/olebedev/go-duktape.v3` to install. + + +```go +package main + +import "fmt" +import "gopkg.in/olebedev/go-duktape.v3" + +func main() { + ctx := duktape.New() + ctx.PevalString(`2 + 3`) + result := ctx.GetNumber(-1) + ctx.Pop() + fmt.Println("result is:", result) + // To prevent memory leaks, don't forget to clean up after + // yourself when you're done using a context. + ctx.DestroyHeap() +} +``` + +### Go specific notes + +Bindings between Go and Javascript contexts are not fully functional. +However, binding a Go function to the Javascript context is available: +```go +package main + +import "fmt" +import "gopkg.in/olebedev/go-duktape.v3" + +func main() { + ctx := duktape.New() + ctx.PushGlobalGoFunction("log", func(c *duktape.Context) int { + fmt.Println(c.SafeToString(-1)) + return 0 + }) + ctx.PevalString(`log('Go lang Go!')`) +} +``` +then run it. +```bash +$ go run *.go +Go lang Go! +$ +``` + +### Timers + +There is a method to inject timers to the global scope: +```go +package main + +import "fmt" +import "gopkg.in/olebedev/go-duktape.v3" + +func main() { + ctx := duktape.New() + + // Let's inject `setTimeout`, `setInterval`, `clearTimeout`, + // `clearInterval` into global scope. + ctx.PushTimers() + + ch := make(chan string) + ctx.PushGlobalGoFunction("second", func(_ *Context) int { + ch <- "second step" + return 0 + }) + ctx.PevalString(` + setTimeout(second, 0); + print('first step'); + `) + fmt.Println(<-ch) +} +``` +then run it +```bash +$ go run *.go +first step +second step +$ +``` + +Also you can `FlushTimers()`. + +### Command line tool + +Install `go get gopkg.in/olebedev/go-duktape.v3/...`. +Execute file.js: `$GOPATH/bin/go-duk file.js`. + +### Benchmarks +| prog | time | +| ------------|-------| +|[otto](https://github.com/robertkrimen/otto)|200.13s| +|[anko](https://github.com/mattn/anko)|231.19s| +|[agora](https://github.com/PuerkitoBio/agora/)|149.33s| +|[GopherLua](https://github.com/yuin/gopher-lua/)|8.39s| +|**go-duktape**|**9.80s**| + +More details are [here](https://github.com/olebedev/go-duktape/wiki/Benchmarks). + +### Status + +The package is not fully tested, so be careful. + + +### Contribution + +Pull requests are welcome! Also, if you want to discuss something send a pull request with proposal and changes. +__Convention:__ fork the repository and make changes on your fork in a feature branch. diff --git a/vendor/gopkg.in/olebedev/go-duktape.v3/api.go b/vendor/gopkg.in/olebedev/go-duktape.v3/api.go new file mode 100644 index 000000000..6617ec23d --- /dev/null +++ b/vendor/gopkg.in/olebedev/go-duktape.v3/api.go @@ -0,0 +1,1616 @@ +package duktape + +/* +#cgo !windows CFLAGS: -std=c99 -O3 -Wall -fomit-frame-pointer -fstrict-aliasing +#cgo windows CFLAGS: -O3 -Wall -fomit-frame-pointer -fstrict-aliasing + +#include "duktape.h" +#include "duk_logging.h" +#include "duk_v1_compat.h" +#include "duk_print_alert.h" +static void _duk_eval_string(duk_context *ctx, const char *str) { + duk_eval_string(ctx, str); +} +static void _duk_compile(duk_context *ctx, duk_uint_t flags) { + duk_compile(ctx, flags); +} +static void _duk_compile_file(duk_context *ctx, duk_uint_t flags, const char *path) { + duk_compile_file(ctx, flags, path); +} +static void _duk_compile_lstring(duk_context *ctx, duk_uint_t flags, const char *src, duk_size_t len) { + duk_compile_lstring(ctx, flags, src, len); +} +static void _duk_compile_lstring_filename(duk_context *ctx, duk_uint_t flags, const char *src, duk_size_t len) { + duk_compile_lstring_filename(ctx, flags, src, len); +} +static void _duk_compile_string(duk_context *ctx, duk_uint_t flags, const char *src) { + duk_compile_string(ctx, flags, src); +} +static void _duk_compile_string_filename(duk_context *ctx, duk_uint_t flags, const char *src) { + duk_compile_string_filename(ctx, flags, src); +} +static void _duk_dump_context_stderr(duk_context *ctx) { + duk_dump_context_stderr(ctx); +} +static void _duk_dump_context_stdout(duk_context *ctx) { + duk_dump_context_stdout(ctx); +} +static void _duk_eval(duk_context *ctx) { + duk_eval(ctx); +} +static void _duk_eval_file(duk_context *ctx, const char *path) { + duk_eval_file(ctx, path); +} +static void _duk_eval_file_noresult(duk_context *ctx, const char *path) { + duk_eval_file_noresult(ctx, path); +} +static void _duk_eval_lstring(duk_context *ctx, const char *src, duk_size_t len) { + duk_eval_lstring(ctx, src, len); +} +static void _duk_eval_lstring_noresult(duk_context *ctx, const char *src, duk_size_t len) { + duk_eval_lstring_noresult(ctx, src, len); +} +static void _duk_eval_noresult(duk_context *ctx) { + duk_eval_noresult(ctx); +} +static void _duk_eval_string_noresult(duk_context *ctx, const char *src) { + duk_eval_string_noresult(ctx, src); +} +static duk_bool_t _duk_is_error(duk_context *ctx, duk_idx_t index) { + return duk_is_error(ctx, index); +} +static duk_bool_t _duk_is_object_coercible(duk_context *ctx, duk_idx_t index) { + return duk_is_object_coercible(ctx, index); +} +static duk_int_t _duk_pcompile(duk_context *ctx, duk_uint_t flags) { + return duk_pcompile(ctx, flags); +} +static duk_int_t _duk_pcompile_file(duk_context *ctx, duk_uint_t flags, const char *path) { + return duk_pcompile_file(ctx, flags, path); +} +static duk_int_t _duk_pcompile_lstring(duk_context *ctx, duk_uint_t flags, const char *src, duk_size_t len) { + return duk_pcompile_lstring(ctx, flags, src, len); +} +static duk_int_t _duk_pcompile_lstring_filename(duk_context *ctx, duk_uint_t flags, const char *src, duk_size_t len) { + return duk_pcompile_lstring_filename(ctx, flags, src, len); +} +static duk_int_t _duk_pcompile_string(duk_context *ctx, duk_uint_t flags, const char *src) { + return duk_pcompile_string(ctx, flags, src); +} +static duk_int_t _duk_pcompile_string_filename(duk_context *ctx, duk_uint_t flags, const char *src) { + return duk_pcompile_string_filename(ctx, flags, src); +} +static duk_int_t _duk_peval(duk_context *ctx) { + return duk_peval(ctx); +} +static duk_int_t _duk_peval_file(duk_context *ctx, const char *path) { + return duk_peval_file(ctx, path); +} +static duk_int_t _duk_peval_file_noresult(duk_context *ctx, const char *path) { + return duk_peval_file_noresult(ctx, path); +} +static duk_int_t _duk_peval_lstring(duk_context *ctx, const char *src, duk_size_t len) { + return duk_peval_lstring(ctx, src, len); +} +static duk_int_t _duk_peval_lstring_noresult(duk_context *ctx, const char *src, duk_size_t len) { + return duk_peval_lstring_noresult(ctx, src, len); +} +static duk_int_t _duk_peval_noresult(duk_context *ctx) { + return duk_peval_noresult(ctx); +} +static duk_int_t _duk_peval_string(duk_context *ctx, const char *src) { + return duk_peval_string(ctx, src); +} +static duk_int_t _duk_peval_string_noresult(duk_context *ctx, const char *src) { + return duk_peval_string_noresult(ctx, src); +} +static const char *_duk_push_string_file(duk_context *ctx, const char *path) { + return duk_push_string_file(ctx, path); +} +static duk_idx_t _duk_push_thread(duk_context *ctx) { + return duk_push_thread(ctx); +} +static duk_idx_t _duk_push_thread_new_globalenv(duk_context *ctx) { + return duk_push_thread_new_globalenv(ctx); +} +static void _duk_require_object_coercible(duk_context *ctx, duk_idx_t index) { + duk_require_object_coercible(ctx, index); +} +static void _duk_require_type_mask(duk_context *ctx, duk_idx_t index, duk_uint_t mask) { + duk_require_type_mask(ctx, index, mask); +} +static const char *_duk_safe_to_string(duk_context *ctx, duk_idx_t index) { + return duk_safe_to_string(ctx, index); +} +static void _duk_xcopy_top(duk_context *to_ctx, duk_context *from_ctx, duk_idx_t count) { + duk_xcopy_top(to_ctx, from_ctx, count); +} +static void _duk_xmove_top(duk_context *to_ctx, duk_context *from_ctx, duk_idx_t count) { + duk_xmove_top(to_ctx, from_ctx, count); +} +static void *_duk_to_buffer(duk_context *ctx, duk_idx_t index, duk_size_t *out_size) { + return duk_to_buffer(ctx, index, out_size); +} +static void *_duk_to_dynamic_buffer(duk_context *ctx, duk_idx_t index, duk_size_t *out_size) { + return duk_to_dynamic_buffer(ctx, index, out_size); +} +static void *_duk_to_fixed_buffer(duk_context *ctx, duk_idx_t index, duk_size_t *out_size) { + return duk_to_fixed_buffer(ctx, index, out_size); +} +static duk_int_t _duk_is_primitive(duk_context *ctx, duk_idx_t index) { + return duk_is_primitive(ctx, index); +} +static void *_duk_push_buffer(duk_context *ctx, duk_size_t size, duk_bool_t dynamic) { + return duk_push_buffer(ctx, size, dynamic); +} +static void *_duk_push_fixed_buffer(duk_context *ctx, duk_size_t size) { + return duk_push_fixed_buffer(ctx, size); +} +static void *_duk_push_dynamic_buffer(duk_context *ctx, duk_size_t size) { + return duk_push_dynamic_buffer(ctx, size); +} +static void _duk_error(duk_context *ctx, duk_errcode_t err_code, const char *str) { + duk_error(ctx, err_code, "%s", str); +} +static void _duk_push_error_object(duk_context *ctx, duk_errcode_t err_code, const char *str) { + duk_push_error_object(ctx, err_code, "%s", str); +} +static void _duk_error_raw(duk_context *ctx, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *text) { + duk_error_raw(ctx, err_code, filename, line, text); +} +static void _duk_log(duk_context *ctx, duk_int_t level, const char *str) { + duk_log(ctx, level, "%s", str); +} +static void _duk_push_external_buffer(duk_context *ctx) { + duk_push_external_buffer(ctx); +} +*/ +import "C" +import ( + "fmt" + "unsafe" +) + +// See: http://duktape.org/api.html#duk_alloc +func (d *Context) Alloc(size int) unsafe.Pointer { + return C.duk_alloc(d.duk_context, C.duk_size_t(size)) +} + +// See: http://duktape.org/api.html#duk_alloc_raw +func (d *Context) AllocRaw(size int) unsafe.Pointer { + return C.duk_alloc_raw(d.duk_context, C.duk_size_t(size)) +} + +// See: http://duktape.org/api.html#duk_base64_decode +func (d *Context) Base64Decode(index int) { + C.duk_base64_decode(d.duk_context, C.duk_idx_t(index)) +} + +// See: http://duktape.org/api.html#duk_base64_encode +func (d *Context) Base64Encode(index int) string { + if s := C.duk_base64_encode(d.duk_context, C.duk_idx_t(index)); s != nil { + return C.GoString(s) + } + return "" +} + +// See: http://duktape.org/api.html#duk_call +func (d *Context) Call(nargs int) { + C.duk_call(d.duk_context, C.duk_idx_t(nargs)) +} + +// See: http://duktape.org/api.html#duk_call_method +func (d *Context) CallMethod(nargs int) { + C.duk_call_method(d.duk_context, C.duk_idx_t(nargs)) +} + +// See: http://duktape.org/api.html#duk_call_prop +func (d *Context) CallProp(objIndex int, nargs int) { + C.duk_call_prop(d.duk_context, C.duk_idx_t(objIndex), C.duk_idx_t(nargs)) +} + +// See: http://duktape.org/api.html#duk_check_stack +func (d *Context) CheckStack(extra int) bool { + return int(C.duk_check_stack(d.duk_context, C.duk_idx_t(extra))) == 1 +} + +// See: http://duktape.org/api.html#duk_check_stack_top +func (d *Context) CheckStackTop(top int) bool { + return int(C.duk_check_stack_top(d.duk_context, C.duk_idx_t(top))) == 1 +} + +// See: http://duktape.org/api.html#duk_check_type +func (d *Context) CheckType(index int, typ int) bool { + return int(C.duk_check_type(d.duk_context, C.duk_idx_t(index), C.duk_int_t(typ))) == 1 +} + +// See: http://duktape.org/api.html#duk_check_type_mask +func (d *Context) CheckTypeMask(index int, mask uint) bool { + return int(C.duk_check_type_mask(d.duk_context, C.duk_idx_t(index), C.duk_uint_t(mask))) == 1 +} + +// See: http://duktape.org/api.html#duk_compact +func (d *Context) Compact(objIndex int) { + C.duk_compact(d.duk_context, C.duk_idx_t(objIndex)) +} + +// See: http://duktape.org/api.html#duk_compile +func (d *Context) Compile(flags uint) { + C._duk_compile(d.duk_context, C.duk_uint_t(flags)) +} + +// See: http://duktape.org/api.html#duk_compile_file +func (d *Context) CompileFile(flags uint, path string) { + __path__ := C.CString(path) + C._duk_compile_file(d.duk_context, C.duk_uint_t(flags), __path__) + C.free(unsafe.Pointer(__path__)) +} + +// See: http://duktape.org/api.html#duk_compile_lstring +func (d *Context) CompileLstring(flags uint, src string, len int) { + __src__ := C.CString(src) + C._duk_compile_lstring(d.duk_context, C.duk_uint_t(flags), __src__, C.duk_size_t(len)) + C.free(unsafe.Pointer(__src__)) +} + +// See: http://duktape.org/api.html#duk_compile_lstring_filename +func (d *Context) CompileLstringFilename(flags uint, src string, len int) { + __src__ := C.CString(src) + C._duk_compile_lstring_filename(d.duk_context, C.duk_uint_t(flags), __src__, C.duk_size_t(len)) + C.free(unsafe.Pointer(__src__)) +} + +// See: http://duktape.org/api.html#duk_compile_string +func (d *Context) CompileString(flags uint, src string) { + __src__ := C.CString(src) + C._duk_compile_string(d.duk_context, C.duk_uint_t(flags), __src__) + C.free(unsafe.Pointer(__src__)) +} + +// See: http://duktape.org/api.html#duk_compile_string_filename +func (d *Context) CompileStringFilename(flags uint, src string) { + __src__ := C.CString(src) + C._duk_compile_string_filename(d.duk_context, C.duk_uint_t(flags), __src__) + C.free(unsafe.Pointer(__src__)) +} + +// See: http://duktape.org/api.html#duk_concat +func (d *Context) Concat(count int) { + C.duk_concat(d.duk_context, C.duk_idx_t(count)) +} + +// See: http://duktape.org/api.html#duk_copy +func (d *Context) Copy(fromIndex int, toIndex int) { + C.duk_copy(d.duk_context, C.duk_idx_t(fromIndex), C.duk_idx_t(toIndex)) +} + +// See: http://duktape.org/api.html#duk_del_prop +func (d *Context) DelProp(objIndex int) bool { + return int(C.duk_del_prop(d.duk_context, C.duk_idx_t(objIndex))) == 1 +} + +// See: http://duktape.org/api.html#duk_del_prop_index +func (d *Context) DelPropIndex(objIndex int, arrIndex uint) bool { + return int(C.duk_del_prop_index(d.duk_context, C.duk_idx_t(objIndex), C.duk_uarridx_t(arrIndex))) == 1 +} + +// See: http://duktape.org/api.html#duk_del_prop_string +func (d *Context) DelPropString(objIndex int, key string) bool { + __key__ := C.CString(key) + result := int(C.duk_del_prop_string(d.duk_context, C.duk_idx_t(objIndex), __key__)) == 1 + C.free(unsafe.Pointer(__key__)) + return result +} + +// See: http://duktape.org/api.html#duk_def_prop +func (d *Context) DefProp(objIndex int, flags uint) { + C.duk_def_prop(d.duk_context, C.duk_idx_t(objIndex), C.duk_uint_t(flags)) +} + +// See: http://duktape.org/api.html#duk_destroy_heap +func (d *Context) DestroyHeap() { + d.Gc(0) + C.duk_destroy_heap(d.duk_context) + d.duk_context = nil +} + +// See: http://duktape.org/api.html#duk_dump_context_stderr +func (d *Context) DumpContextStderr() { + C._duk_dump_context_stderr(d.duk_context) +} + +// See: http://duktape.org/api.html#duk_dump_context_stdout +func (d *Context) DumpContextStdout() { + C._duk_dump_context_stdout(d.duk_context) +} + +// See: http://duktape.org/api.html#duk_dup +func (d *Context) Dup(fromIndex int) { + C.duk_dup(d.duk_context, C.duk_idx_t(fromIndex)) +} + +// See: http://duktape.org/api.html#duk_dup_top +func (d *Context) DupTop() { + C.duk_dup_top(d.duk_context) +} + +// See: http://duktape.org/api.html#duk_enum +func (d *Context) Enum(objIndex int, enumFlags uint) { + C.duk_enum(d.duk_context, C.duk_idx_t(objIndex), C.duk_uint_t(enumFlags)) +} + +// See: http://duktape.org/api.html#duk_equals +func (d *Context) Equals(index1 int, index2 int) bool { + return int(C.duk_equals(d.duk_context, C.duk_idx_t(index1), C.duk_idx_t(index2))) == 1 +} + +// Error pushes a new Error object to the stack and throws it. This will call +// fmt.Sprint, forwarding arguments after the error code, to produce the +// Error's message. +// +// See: http://duktape.org/api.html#duk_error +func (d *Context) Error(errCode int, str string) { + __str__ := C.CString(str) + C._duk_error(d.duk_context, C.duk_errcode_t(errCode), __str__) + C.free(unsafe.Pointer(__str__)) +} + +func (d *Context) ErrorRaw(errCode int, filename string, line int, errMsg string) { + __filename__ := C.CString(filename) + __errMsg__ := C.CString(errMsg) + C._duk_error_raw(d.duk_context, C.duk_errcode_t(errCode), __filename__, C.duk_int_t(line), __errMsg__) + C.free(unsafe.Pointer(__filename__)) + C.free(unsafe.Pointer(__errMsg__)) +} + +// Errorf pushes a new Error object to the stack and throws it. This will call +// fmt.Sprintf, forwarding the format string and additional arguments, to +// produce the Error's message. +// +// See: http://duktape.org/api.html#duk_error +func (d *Context) Errorf(errCode int, format string, a ...interface{}) { + str := fmt.Sprintf(format, a...) + __str__ := C.CString(str) + C._duk_error(d.duk_context, C.duk_errcode_t(errCode), __str__) + C.free(unsafe.Pointer(__str__)) +} + +// See: http://duktape.org/api.html#duk_eval +func (d *Context) Eval() { + C._duk_eval(d.duk_context) +} + +// See: http://duktape.org/api.html#duk_eval_file +func (d *Context) EvalFile(path string) { + __path__ := C.CString(path) + C._duk_eval_file(d.duk_context, __path__) + C.free(unsafe.Pointer(__path__)) +} + +// See: http://duktape.org/api.html#duk_eval_file_noresult +func (d *Context) EvalFileNoresult(path string) { + __path__ := C.CString(path) + C._duk_eval_file_noresult(d.duk_context, __path__) + C.free(unsafe.Pointer(__path__)) +} + +// See: http://duktape.org/api.html#duk_eval_lstring +func (d *Context) EvalLstring(src string, len int) { + __src__ := C.CString(src) + C._duk_eval_lstring(d.duk_context, __src__, C.duk_size_t(len)) + C.free(unsafe.Pointer(__src__)) +} + +// See: http://duktape.org/api.html#duk_eval_lstring_noresult +func (d *Context) EvalLstringNoresult(src string, len int) { + __src__ := C.CString(src) + C._duk_eval_lstring_noresult(d.duk_context, __src__, C.duk_size_t(len)) + C.free(unsafe.Pointer(__src__)) +} + +// See: http://duktape.org/api.html#duk_eval_noresult +func (d *Context) EvalNoresult() { + C._duk_eval_noresult(d.duk_context) +} + +// See: http://duktape.org/api.html#duk_eval_string +func (d *Context) EvalString(src string) { + __src__ := C.CString(src) + C._duk_eval_string(d.duk_context, __src__) + C.free(unsafe.Pointer(__src__)) +} + +// See: http://duktape.org/api.html#duk_eval_string_noresult +func (d *Context) EvalStringNoresult(src string) { + __src__ := C.CString(src) + C._duk_eval_string_noresult(d.duk_context, __src__) + C.free(unsafe.Pointer(__src__)) +} + +// See: http://duktape.org/api.html#duk_fatal +func (d *Context) Fatal(errCode int, errMsg string) { + __errMsg__ := C.CString(errMsg) + defer C.free(unsafe.Pointer(__errMsg__)) + C.duk_fatal_raw(d.duk_context, __errMsg__) +} + +// See: http://duktape.org/api.html#duk_gc +func (d *Context) Gc(flags uint) { + C.duk_gc(d.duk_context, C.duk_uint_t(flags)) +} + +// See: http://duktape.org/api.html#duk_get_boolean +func (d *Context) GetBoolean(index int) bool { + return int(C.duk_get_boolean(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_get_buffer +func (d *Context) GetBuffer(index int) (rawPtr unsafe.Pointer, outSize uint) { + rawPtr = C.duk_get_buffer(d.duk_context, C.duk_idx_t(index), (*C.duk_size_t)(unsafe.Pointer(&outSize))) + return rawPtr, outSize +} + +// See: http://duktape.org/api.html#duk_get_context +func (d *Context) GetContext(index int) *Context { + return contextFromPointer(C.duk_get_context(d.duk_context, C.duk_idx_t(index))) +} + +// See: http://duktape.org/api.html#duk_get_current_magic +func (d *Context) GetCurrentMagic() int { + return int(C.duk_get_current_magic(d.duk_context)) +} + +// See: http://duktape.org/api.html#duk_get_error_code +func (d *Context) GetErrorCode(index int) int { + code := int(C.duk_get_error_code(d.duk_context, C.duk_idx_t(index))) + return code +} + +// See: http://duktape.org/api.html#duk_get_finalizer +func (d *Context) GetFinalizer(index int) { + C.duk_get_finalizer(d.duk_context, C.duk_idx_t(index)) +} + +// See: http://duktape.org/api.html#duk_get_global_string +func (d *Context) GetGlobalString(key string) bool { + __key__ := C.CString(key) + result := int(C.duk_get_global_string(d.duk_context, __key__)) == 1 + C.free(unsafe.Pointer(__key__)) + return result +} + +// See: http://duktape.org/api.html#duk_get_heapptr +func (d *Context) GetHeapptr(index int) unsafe.Pointer { + return unsafe.Pointer(C.duk_get_heapptr(d.duk_context, C.duk_idx_t(index))) +} + +// See: http://duktape.org/api.html#duk_get_int +func (d *Context) GetInt(index int) int { + return int(C.duk_get_int(d.duk_context, C.duk_idx_t(index))) +} + +// See: http://duktape.org/api.html#duk_get_length +func (d *Context) GetLength(index int) int { + return int(C.duk_get_length(d.duk_context, C.duk_idx_t(index))) +} + +// See: http://duktape.org/api.html#duk_get_lstring +func (d *Context) GetLstring(index int) string { + if s := C.duk_get_lstring(d.duk_context, C.duk_idx_t(index), nil); s != nil { + return C.GoString(s) + } + return "" +} + +// See: http://duktape.org/api.html#duk_get_magic +func (d *Context) GetMagic(index int) int { + return int(C.duk_get_magic(d.duk_context, C.duk_idx_t(index))) +} + +// See: http://duktape.org/api.html#duk_get_number +func (d *Context) GetNumber(index int) float64 { + return float64(C.duk_get_number(d.duk_context, C.duk_idx_t(index))) +} + +// See: http://duktape.org/api.html#duk_get_pointer +func (d *Context) GetPointer(index int) unsafe.Pointer { + return C.duk_get_pointer(d.duk_context, C.duk_idx_t(index)) +} + +// See: http://duktape.org/api.html#duk_get_prop +func (d *Context) GetProp(objIndex int) bool { + return int(C.duk_get_prop(d.duk_context, C.duk_idx_t(objIndex))) == 1 +} + +// See: http://duktape.org/api.html#duk_get_prop_index +func (d *Context) GetPropIndex(objIndex int, arrIndex uint) bool { + return int(C.duk_get_prop_index(d.duk_context, C.duk_idx_t(objIndex), C.duk_uarridx_t(arrIndex))) == 1 +} + +// See: http://duktape.org/api.html#duk_get_prop_string +func (d *Context) GetPropString(objIndex int, key string) bool { + __key__ := C.CString(key) + result := int(C.duk_get_prop_string(d.duk_context, C.duk_idx_t(objIndex), __key__)) == 1 + C.free(unsafe.Pointer(__key__)) + return result +} + +// See: http://duktape.org/api.html#duk_get_prototype +func (d *Context) GetPrototype(index int) { + C.duk_get_prototype(d.duk_context, C.duk_idx_t(index)) +} + +// See: http://duktape.org/api.html#duk_get_string +func (d *Context) GetString(i int) string { + if s := C.duk_get_string(d.duk_context, C.duk_idx_t(i)); s != nil { + return C.GoString(s) + } + return "" +} + +// See: http://duktape.org/api.html#duk_get_top +func (d *Context) GetTop() int { + return int(C.duk_get_top(d.duk_context)) +} + +// See: http://duktape.org/api.html#duk_get_top_index +func (d *Context) GetTopIndex() int { + return int(C.duk_get_top_index(d.duk_context)) +} + +// See: http://duktape.org/api.html#duk_get_type +func (d *Context) GetType(index int) Type { + return Type(C.duk_get_type(d.duk_context, C.duk_idx_t(index))) +} + +// See: http://duktape.org/api.html#duk_get_type_mask +func (d *Context) GetTypeMask(index int) uint { + return uint(C.duk_get_type_mask(d.duk_context, C.duk_idx_t(index))) +} + +// See: http://duktape.org/api.html#duk_get_uint +func (d *Context) GetUint(index int) uint { + return uint(C.duk_get_uint(d.duk_context, C.duk_idx_t(index))) +} + +// See: http://duktape.org/api.html#duk_has_prop +func (d *Context) HasProp(objIndex int) bool { + return int(C.duk_has_prop(d.duk_context, C.duk_idx_t(objIndex))) == 1 +} + +// See: http://duktape.org/api.html#duk_has_prop_index +func (d *Context) HasPropIndex(objIndex int, arrIndex uint) bool { + return int(C.duk_has_prop_index(d.duk_context, C.duk_idx_t(objIndex), C.duk_uarridx_t(arrIndex))) == 1 +} + +// See: http://duktape.org/api.html#duk_has_prop_string +func (d *Context) HasPropString(objIndex int, key string) bool { + __key__ := C.CString(key) + result := int(C.duk_has_prop_string(d.duk_context, C.duk_idx_t(objIndex), __key__)) == 1 + C.free(unsafe.Pointer(__key__)) + return result +} + +// See: http://duktape.org/api.html#duk_hex_decode +func (d *Context) HexDecode(index int) { + C.duk_hex_decode(d.duk_context, C.duk_idx_t(index)) +} + +// See: http://duktape.org/api.html#duk_hex_encode +func (d *Context) HexEncode(index int) string { + if s := C.duk_hex_encode(d.duk_context, C.duk_idx_t(index)); s != nil { + return C.GoString(s) + } + return "" +} + +// See: http://duktape.org/api.html#duk_insert +func (d *Context) Insert(toIndex int) { + C.duk_insert(d.duk_context, C.duk_idx_t(toIndex)) +} + +// See: http://duktape.org/api.html#duk_is_array +func (d *Context) IsArray(index int) bool { + return int(C.duk_is_array(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_is_boolean +func (d *Context) IsBoolean(index int) bool { + return int(C.duk_is_boolean(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_is_bound_function +func (d *Context) IsBoundFunction(index int) bool { + return int(C.duk_is_bound_function(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_is_buffer +func (d *Context) IsBuffer(index int) bool { + return int(C.duk_is_buffer(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_is_c_function +func (d *Context) IsCFunction(index int) bool { + return int(C.duk_is_c_function(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_is_callable +func (d *Context) IsCallable(index int) bool { + return int(C.duk_is_function(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_is_constructor_call +func (d *Context) IsConstructorCall() bool { + return int(C.duk_is_constructor_call(d.duk_context)) == 1 +} + +// See: http://duktape.org/api.html#duk_is_dynamic_buffer +func (d *Context) IsDynamicBuffer(index int) bool { + return int(C.duk_is_dynamic_buffer(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_is_ecmascript_function +func (d *Context) IsEcmascriptFunction(index int) bool { + return int(C.duk_is_ecmascript_function(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_is_fixed_buffer +func (d *Context) IsFixedBuffer(index int) bool { + return int(C.duk_is_fixed_buffer(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_is_function +func (d *Context) IsFunction(index int) bool { + return int(C.duk_is_function(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_is_nan +func (d *Context) IsNan(index int) bool { + return int(C.duk_is_nan(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_is_null +func (d *Context) IsNull(index int) bool { + return int(C.duk_is_null(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_is_null_or_undefined +func (d *Context) IsNullOrUndefined(index int) bool { + return d.IsNull(index) || d.IsUndefined(index) +} + +// See: http://duktape.org/api.html#duk_is_number +func (d *Context) IsNumber(index int) bool { + return int(C.duk_is_number(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_is_object +func (d *Context) IsObject(index int) bool { + return int(C.duk_is_object(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_is_error +func (d *Context) IsError(index int) bool { + return int(C._duk_is_error(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_is_object_coercible +func (d *Context) IsObjectCoercible(index int) bool { + return int(C._duk_is_object_coercible(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_is_pointer +func (d *Context) IsPointer(index int) bool { + return int(C.duk_is_pointer(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_is_primitive +func (d *Context) IsPrimitive(index int) bool { + return int(C._duk_is_primitive(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_is_strict_call +func (d *Context) IsStrictCall() bool { + return int(C.duk_is_strict_call(d.duk_context)) == 1 +} + +// See: http://duktape.org/api.html#duk_is_string +func (d *Context) IsString(index int) bool { + return int(C.duk_is_string(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_is_thread +func (d *Context) IsThread(index int) bool { + return int(C.duk_is_thread(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_is_undefined +func (d *Context) IsUndefined(index int) bool { + return int(C.duk_is_undefined(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_is_valid_index +func (d *Context) IsValidIndex(index int) bool { + return int(C.duk_is_valid_index(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_join +func (d *Context) Join(count int) { + C.duk_join(d.duk_context, C.duk_idx_t(count)) +} + +// See: http://duktape.org/api.html#duk_json_decode +func (d *Context) JsonDecode(index int) { + C.duk_json_decode(d.duk_context, C.duk_idx_t(index)) +} + +// See: http://duktape.org/api.html#duk_json_encode +func (d *Context) JsonEncode(index int) string { + if s := C.duk_json_encode(d.duk_context, C.duk_idx_t(index)); s != nil { + return C.GoString(s) + } + return "" +} + +// See: http://duktape.org/api.html#duk_new +func (d *Context) New(nargs int) { + C.duk_new(d.duk_context, C.duk_idx_t(nargs)) +} + +// See: http://duktape.org/api.html#duk_next +func (d *Context) Next(enumIndex int, getValue bool) bool { + var __getValue__ int + if getValue { + __getValue__ = 1 + } + return int(C.duk_next(d.duk_context, C.duk_idx_t(enumIndex), C.duk_bool_t(__getValue__))) == 1 +} + +// See: http://duktape.org/api.html#duk_normalize_index +func (d *Context) NormalizeIndex(index int) int { + return int(C.duk_normalize_index(d.duk_context, C.duk_idx_t(index))) +} + +// See: http://duktape.org/api.html#duk_pcall +func (d *Context) Pcall(nargs int) int { + return int(C.duk_pcall(d.duk_context, C.duk_idx_t(nargs))) +} + +// See: http://duktape.org/api.html#duk_pcall_method +func (d *Context) PcallMethod(nargs int) int { + return int(C.duk_pcall_method(d.duk_context, C.duk_idx_t(nargs))) +} + +// See: http://duktape.org/api.html#duk_pcall_prop +func (d *Context) PcallProp(objIndex int, nargs int) int { + return int(C.duk_pcall_prop(d.duk_context, C.duk_idx_t(objIndex), C.duk_idx_t(nargs))) +} + +// See: http://duktape.org/api.html#duk_pcompile +func (d *Context) Pcompile(flags uint) error { + result := int(C._duk_pcompile(d.duk_context, C.duk_uint_t(flags))) + return d.castStringToError(result) +} + +// See: http://duktape.org/api.html#duk_pcompile_file +func (d *Context) PcompileFile(flags uint, path string) error { + __path__ := C.CString(path) + result := int(C._duk_pcompile_file(d.duk_context, C.duk_uint_t(flags), __path__)) + C.free(unsafe.Pointer(__path__)) + return d.castStringToError(result) +} + +// See: http://duktape.org/api.html#duk_pcompile_lstring +func (d *Context) PcompileLstring(flags uint, src string, len int) error { + __src__ := C.CString(src) + result := int(C._duk_pcompile_lstring(d.duk_context, C.duk_uint_t(flags), __src__, C.duk_size_t(len))) + C.free(unsafe.Pointer(__src__)) + return d.castStringToError(result) +} + +// See: http://duktape.org/api.html#duk_pcompile_lstring_filename +func (d *Context) PcompileLstringFilename(flags uint, src string, len int) error { + __src__ := C.CString(src) + result := int(C._duk_pcompile_lstring_filename(d.duk_context, C.duk_uint_t(flags), __src__, C.duk_size_t(len))) + C.free(unsafe.Pointer(__src__)) + return d.castStringToError(result) +} + +// See: http://duktape.org/api.html#duk_pcompile_string +func (d *Context) PcompileString(flags uint, src string) error { + __src__ := C.CString(src) + result := int(C._duk_pcompile_string(d.duk_context, C.duk_uint_t(flags), __src__)) + C.free(unsafe.Pointer(__src__)) + fmt.Println("result herhehreh", result) + return nil //d.castStringToError(result) +} + +// See: http://duktape.org/api.html#duk_pcompile_string_filename +func (d *Context) PcompileStringFilename(flags uint, src string) error { + __src__ := C.CString(src) + result := int(C._duk_pcompile_string_filename(d.duk_context, C.duk_uint_t(flags), __src__)) + C.free(unsafe.Pointer(__src__)) + return d.castStringToError(result) +} + +// See: http://duktape.org/api.html#duk_peval +func (d *Context) Peval() error { + result := int(C._duk_peval(d.duk_context)) + return d.castStringToError(result) +} + +// See: http://duktape.org/api.html#duk_peval_file +func (d *Context) PevalFile(path string) error { + __path__ := C.CString(path) + result := int(C._duk_peval_file(d.duk_context, __path__)) + C.free(unsafe.Pointer(__path__)) + return d.castStringToError(result) +} + +// See: http://duktape.org/api.html#duk_peval_file_noresult +func (d *Context) PevalFileNoresult(path string) int { + __path__ := C.CString(path) + result := int(C._duk_peval_file_noresult(d.duk_context, __path__)) + C.free(unsafe.Pointer(__path__)) + return result +} + +// See: http://duktape.org/api.html#duk_peval_lstring +func (d *Context) PevalLstring(src string, len int) error { + __src__ := C.CString(src) + result := int(C._duk_peval_lstring(d.duk_context, __src__, C.duk_size_t(len))) + C.free(unsafe.Pointer(__src__)) + return d.castStringToError(result) + +} + +// See: http://duktape.org/api.html#duk_peval_lstring_noresult +func (d *Context) PevalLstringNoresult(src string, len int) int { + __src__ := C.CString(src) + result := int(C._duk_peval_lstring_noresult(d.duk_context, __src__, C.duk_size_t(len))) + C.free(unsafe.Pointer(__src__)) + return result +} + +// See: http://duktape.org/api.html#duk_peval_noresult +func (d *Context) PevalNoresult() int { + return int(C._duk_peval_noresult(d.duk_context)) +} + +// See: http://duktape.org/api.html#duk_peval_string +func (d *Context) PevalString(src string) error { + __src__ := C.CString(src) + result := int(C._duk_peval_string(d.duk_context, __src__)) + C.free(unsafe.Pointer(__src__)) + return d.castStringToError(result) +} + +// See: http://duktape.org/api.html#duk_peval_string_noresult +func (d *Context) PevalStringNoresult(src string) int { + __src__ := C.CString(src) + result := int(C._duk_peval_string_noresult(d.duk_context, __src__)) + C.free(unsafe.Pointer(__src__)) + return result +} + +func (d *Context) castStringToError(result int) error { + if result == 0 { + return nil + } + + err := &Error{} + for _, key := range []string{"name", "message", "fileName", "lineNumber", "stack"} { + d.GetPropString(-1, key) + + switch key { + case "name": + err.Type = d.SafeToString(-1) + case "message": + err.Message = d.SafeToString(-1) + case "fileName": + err.FileName = d.SafeToString(-1) + case "lineNumber": + if d.IsNumber(-1) { + err.LineNumber = d.GetInt(-1) + } + case "stack": + err.Stack = d.SafeToString(-1) + } + + d.Pop() + } + + return err +} + +// See: http://duktape.org/api.html#duk_pop +func (d *Context) Pop() { + if d.GetTop() == 0 { + return + } + C.duk_pop(d.duk_context) +} + +// See: http://duktape.org/api.html#duk_pop_2 +func (d *Context) Pop2() { + d.PopN(2) +} + +// See: http://duktape.org/api.html#duk_pop_3 +func (d *Context) Pop3() { + d.PopN(3) +} + +// See: http://duktape.org/api.html#duk_pop_n +func (d *Context) PopN(count int) { + if d.GetTop() < count || count < 1 { + return + } + C.duk_pop_n(d.duk_context, C.duk_idx_t(count)) +} + +// See: http://duktape.org/api.html#duk_push_array +func (d *Context) PushArray() int { + return int(C.duk_push_array(d.duk_context)) +} + +// See: http://duktape.org/api.html#duk_push_boolean +func (d *Context) PushBoolean(val bool) { + var __val__ int + if val { + __val__ = 1 + } + C.duk_push_boolean(d.duk_context, C.duk_bool_t(__val__)) +} + +// See: http://duktape.org/api.html#duk_push_buffer +func (d *Context) PushBuffer(size int, dynamic bool) unsafe.Pointer { + var __dynamic__ int + if dynamic { + __dynamic__ = 1 + } + return C._duk_push_buffer(d.duk_context, C.duk_size_t(size), C.duk_bool_t(__dynamic__)) +} + +// See: http://duktape.org/api.html#duk_push_c_function +func (d *Context) PushCFunction(fn *[0]byte, nargs int64) int { + return int(C.duk_push_c_function(d.duk_context, fn, C.duk_idx_t(nargs))) +} + +// See: http://duktape.org/api.html#duk_push_context_dump +func (d *Context) PushContextDump() { + C.duk_push_context_dump(d.duk_context) +} + +// See: http://duktape.org/api.html#duk_push_current_function +func (d *Context) PushCurrentFunction() { + C.duk_push_current_function(d.duk_context) +} + +// See: http://duktape.org/api.html#duk_push_current_thread +func (d *Context) PushCurrentThread() { + C.duk_push_current_thread(d.duk_context) +} + +// See: http://duktape.org/api.html#duk_push_dynamic_buffer +func (d *Context) PushDynamicBuffer(size int) unsafe.Pointer { + return C._duk_push_dynamic_buffer(d.duk_context, C.duk_size_t(size)) +} + +// See: http://duktape.org/api.html#duk_push_error_object +func (d *Context) PushErrorObject(errCode int, format string, value interface{}) { + __str__ := C.CString(fmt.Sprintf(format, value)) + C._duk_push_error_object(d.duk_context, C.duk_errcode_t(errCode), __str__) + C.free(unsafe.Pointer(__str__)) +} + +// See: http://duktape.org/api.html#duk_push_false +func (d *Context) PushFalse() { + C.duk_push_false(d.duk_context) +} + +// See: http://duktape.org/api.html#duk_push_fixed_buffer +func (d *Context) PushFixedBuffer(size int) unsafe.Pointer { + return C._duk_push_fixed_buffer(d.duk_context, C.duk_size_t(size)) +} + +// See: http://duktape.org/api.html#duk_push_global_object +func (d *Context) PushGlobalObject() { + C.duk_push_global_object(d.duk_context) +} + +// See: http://duktape.org/api.html#duk_push_global_stash +func (d *Context) PushGlobalStash() { + C.duk_push_global_stash(d.duk_context) +} + +// See: http://duktape.org/api.html#duk_push_heapptr +func (d *Context) PushHeapptr(ptr unsafe.Pointer) { + C.duk_push_heapptr(d.duk_context, ptr) +} + +// See: http://duktape.org/api.html#duk_push_heap_stash +func (d *Context) PushHeapStash() { + C.duk_push_heap_stash(d.duk_context) +} + +// See: http://duktape.org/api.html#duk_push_int +func (d *Context) PushInt(val int) { + C.duk_push_int(d.duk_context, C.duk_int_t(val)) +} + +// See: http://duktape.org/api.html#duk_push_lstring +func (d *Context) PushLstring(str string, len int) string { + __str__ := C.CString(str) + var result string + if s := C.duk_push_lstring(d.duk_context, __str__, C.duk_size_t(len)); s != nil { + result = C.GoString(s) + } + C.free(unsafe.Pointer(__str__)) + return result +} + +// See: http://duktape.org/api.html#duk_push_nan +func (d *Context) PushNan() { + C.duk_push_nan(d.duk_context) +} + +// See: http://duktape.org/api.html#duk_push_null +func (d *Context) PushNull() { + C.duk_push_null(d.duk_context) +} + +// See: http://duktape.org/api.html#duk_push_number +func (d *Context) PushNumber(val float64) { + C.duk_push_number(d.duk_context, C.duk_double_t(val)) +} + +// See: http://duktape.org/api.html#duk_push_object +func (d *Context) PushObject() int { + return int(C.duk_push_object(d.duk_context)) +} + +// See: http://duktape.org/api.html#duk_push_string +func (d *Context) PushString(str string) string { + __str__ := C.CString(str) + var result string + if s := C.duk_push_string(d.duk_context, __str__); s != nil { + result = C.GoString(s) + } + C.free(unsafe.Pointer(__str__)) + return result +} + +// See: http://duktape.org/api.html#duk_push_string_file +func (d *Context) PushStringFile(path string) string { + __path__ := C.CString(path) + var result string + if s := C._duk_push_string_file(d.duk_context, __path__); s != nil { + result = C.GoString(s) + } + C.free(unsafe.Pointer(__path__)) + return result +} + +// See: http://duktape.org/api.html#duk_push_this +func (d *Context) PushThis() { + C.duk_push_this(d.duk_context) +} + +// See: http://duktape.org/api.html#duk_push_thread +func (d *Context) PushThread() int { + return int(C._duk_push_thread(d.duk_context)) +} + +// See: http://duktape.org/api.html#duk_push_thread_new_globalenv +func (d *Context) PushThreadNewGlobalenv() int { + return int(C._duk_push_thread_new_globalenv(d.duk_context)) +} + +// See: http://duktape.org/api.html#duk_push_thread_stash +func (d *Context) PushThreadStash(targetCtx *Context) { + C.duk_push_thread_stash(d.duk_context, targetCtx.duk_context) +} + +// See: http://duktape.org/api.html#duk_push_true +func (d *Context) PushTrue() { + C.duk_push_true(d.duk_context) +} + +// See: http://duktape.org/api.html#duk_push_uint +func (d *Context) PushUint(val uint) { + C.duk_push_uint(d.duk_context, C.duk_uint_t(val)) +} + +// See: http://duktape.org/api.html#duk_push_undefined +func (d *Context) PushUndefined() { + C.duk_push_undefined(d.duk_context) +} + +// See: http://duktape.org/api.html#duk_put_global_string +func (d *Context) PutGlobalString(key string) bool { + __key__ := C.CString(key) + result := int(C.duk_put_global_string(d.duk_context, __key__)) == 1 + C.free(unsafe.Pointer(__key__)) + return result +} + +// See: http://duktape.org/api.html#duk_put_prop +func (d *Context) PutProp(objIndex int) bool { + return int(C.duk_put_prop(d.duk_context, C.duk_idx_t(objIndex))) == 1 +} + +// See: http://duktape.org/api.html#duk_put_prop_index +func (d *Context) PutPropIndex(objIndex int, arrIndex uint) bool { + return int(C.duk_put_prop_index(d.duk_context, C.duk_idx_t(objIndex), C.duk_uarridx_t(arrIndex))) == 1 +} + +// See: http://duktape.org/api.html#duk_put_prop_string +func (d *Context) PutPropString(objIndex int, key string) bool { + __key__ := C.CString(key) + result := int(C.duk_put_prop_string(d.duk_context, C.duk_idx_t(objIndex), __key__)) == 1 + C.free(unsafe.Pointer(__key__)) + return result +} + +// See: http://duktape.org/api.html#duk_remove +func (d *Context) Remove(index int) { + C.duk_remove(d.duk_context, C.duk_idx_t(index)) +} + +// See: http://duktape.org/api.html#duk_replace +func (d *Context) Replace(toIndex int) { + C.duk_replace(d.duk_context, C.duk_idx_t(toIndex)) +} + +// See: http://duktape.org/api.html#duk_require_boolean +func (d *Context) RequireBoolean(index int) bool { + return int(C.duk_require_boolean(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_require_buffer +func (d *Context) RequireBuffer(index int) (rawPtr unsafe.Pointer, outSize uint) { + rawPtr = C.duk_require_buffer(d.duk_context, C.duk_idx_t(index), (*C.duk_size_t)(unsafe.Pointer(&outSize))) + return rawPtr, outSize +} + +// See: http://duktape.org/api.html#duk_require_callable +func (d *Context) RequireCallable(index int) { + // At present, duk_require_callable is a macro that just calls duk_require_function. + // cgo does not support such macros we have to call it directly. + C.duk_require_function(d.duk_context, C.duk_idx_t(index)) +} + +// See: http://duktape.org/api.html#duk_require_context +func (d *Context) RequireContext(index int) *Context { + return contextFromPointer(C.duk_require_context(d.duk_context, C.duk_idx_t(index))) +} + +// See: http://duktape.org/api.html#duk_require_function +func (d *Context) RequireFunction(index int) { + C.duk_require_function(d.duk_context, C.duk_idx_t(index)) +} + +// See: http://duktape.org/api.html#duk_require_heapptr +func (d *Context) RequireHeapptr(index int) unsafe.Pointer { + return unsafe.Pointer(C.duk_require_heapptr(d.duk_context, C.duk_idx_t(index))) +} + +// See: http://duktape.org/api.html#duk_require_int +func (d *Context) RequireInt(index int) int { + return int(C.duk_require_int(d.duk_context, C.duk_idx_t(index))) +} + +// See: http://duktape.org/api.html#duk_require_lstring +func (d *Context) RequireLstring(index int) string { + if s := C.duk_require_lstring(d.duk_context, C.duk_idx_t(index), nil); s != nil { + return C.GoString(s) + } + return "" +} + +// See: http://duktape.org/api.html#duk_require_normalize_index +func (d *Context) RequireNormalizeIndex(index int) int { + return int(C.duk_require_normalize_index(d.duk_context, C.duk_idx_t(index))) +} + +// See: http://duktape.org/api.html#duk_require_null +func (d *Context) RequireNull(index int) { + C.duk_require_null(d.duk_context, C.duk_idx_t(index)) +} + +// See: http://duktape.org/api.html#duk_require_number +func (d *Context) RequireNumber(index int) float64 { + return float64(C.duk_require_number(d.duk_context, C.duk_idx_t(index))) +} + +// See: http://duktape.org/api.html#duk_require_object_coercible +func (d *Context) RequireObjectCoercible(index int) { + C._duk_require_object_coercible(d.duk_context, C.duk_idx_t(index)) +} + +// See: http://duktape.org/api.html#duk_require_pointer +func (d *Context) RequirePointer(index int) unsafe.Pointer { + return C.duk_require_pointer(d.duk_context, C.duk_idx_t(index)) +} + +// See: http://duktape.org/api.html#duk_require_stack +func (d *Context) RequireStack(extra int) { + C.duk_require_stack(d.duk_context, C.duk_idx_t(extra)) +} + +// See: http://duktape.org/api.html#duk_require_stack_top +func (d *Context) RequireStackTop(top int) { + C.duk_require_stack_top(d.duk_context, C.duk_idx_t(top)) +} + +// See: http://duktape.org/api.html#duk_require_string +func (d *Context) RequireString(index int) string { + if s := C.duk_require_string(d.duk_context, C.duk_idx_t(index)); s != nil { + return C.GoString(s) + } + return "" +} + +// See: http://duktape.org/api.html#duk_require_top_index +func (d *Context) RequireTopIndex() int { + return int(C.duk_require_top_index(d.duk_context)) +} + +// See: http://duktape.org/api.html#duk_require_type_mask +func (d *Context) RequireTypeMask(index int, mask uint) { + C._duk_require_type_mask(d.duk_context, C.duk_idx_t(index), C.duk_uint_t(mask)) +} + +// See: http://duktape.org/api.html#duk_require_uint +func (d *Context) RequireUint(index int) uint { + return uint(C.duk_require_uint(d.duk_context, C.duk_idx_t(index))) +} + +// See: http://duktape.org/api.html#duk_require_undefined +func (d *Context) RequireUndefined(index int) { + C.duk_require_undefined(d.duk_context, C.duk_idx_t(index)) +} + +// See: http://duktape.org/api.html#duk_require_valid_index +func (d *Context) RequireValidIndex(index int) { + C.duk_require_valid_index(d.duk_context, C.duk_idx_t(index)) +} + +// See: http://duktape.org/api.html#duk_resize_buffer +func (d *Context) ResizeBuffer(index int, newSize int) unsafe.Pointer { + return C.duk_resize_buffer(d.duk_context, C.duk_idx_t(index), C.duk_size_t(newSize)) +} + +// See: http://duktape.org/api.html#duk_safe_call +func (d *Context) SafeCall(fn, args *[0]byte, nargs, nrets int) int { + return int(C.duk_safe_call( + d.duk_context, + fn, + unsafe.Pointer(&args), + C.duk_idx_t(nargs), + C.duk_idx_t(nrets), + )) +} + +// See: http://duktape.org/api.html#duk_safe_to_lstring +func (d *Context) SafeToLstring(index int) string { + if s := C.duk_safe_to_lstring(d.duk_context, C.duk_idx_t(index), nil); s != nil { + return C.GoString(s) + } + return "" +} + +// See: http://duktape.org/api.html#duk_safe_to_string +func (d *Context) SafeToString(index int) string { + if s := C._duk_safe_to_string(d.duk_context, C.duk_idx_t(index)); s != nil { + return C.GoString(s) + } + return "" +} + +// See: http://duktape.org/api.html#duk_set_finalizer +func (d *Context) SetFinalizer(index int) { + C.duk_set_finalizer(d.duk_context, C.duk_idx_t(index)) +} + +// See: http://duktape.org/api.html#duk_set_global_object +func (d *Context) SetGlobalObject() { + C.duk_set_global_object(d.duk_context) +} + +// See: http://duktape.org/api.html#duk_set_magic +func (d *Context) SetMagic(index int, magic int) { + C.duk_set_magic(d.duk_context, C.duk_idx_t(index), C.duk_int_t(magic)) +} + +// See: http://duktape.org/api.html#duk_set_prototype +func (d *Context) SetPrototype(index int) { + C.duk_set_prototype(d.duk_context, C.duk_idx_t(index)) +} + +// See: http://duktape.org/api.html#duk_set_top +func (d *Context) SetTop(index int) { + C.duk_set_top(d.duk_context, C.duk_idx_t(index)) +} + +func (d *Context) StrictEquals(index1 int, index2 int) bool { + return int(C.duk_strict_equals(d.duk_context, C.duk_idx_t(index1), C.duk_idx_t(index2))) == 1 +} + +// See: http://duktape.org/api.html#duk_substring +func (d *Context) Substring(index int, startCharOffset int, endCharOffset int) { + C.duk_substring(d.duk_context, C.duk_idx_t(index), C.duk_size_t(startCharOffset), C.duk_size_t(endCharOffset)) +} + +// See: http://duktape.org/api.html#duk_swap +func (d *Context) Swap(index1 int, index2 int) { + C.duk_swap(d.duk_context, C.duk_idx_t(index1), C.duk_idx_t(index2)) +} + +// See: http://duktape.org/api.html#duk_swap_top +func (d *Context) SwapTop(index int) { + C.duk_swap_top(d.duk_context, C.duk_idx_t(index)) +} + +// See: http://duktape.org/api.html#duk_throw +func (d *Context) Throw() { + C.duk_throw_raw(d.duk_context) +} + +// See: http://duktape.org/api.html#duk_to_boolean +func (d *Context) ToBoolean(index int) bool { + return int(C.duk_to_boolean(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_to_buffer +func (d *Context) ToBuffer(index int) (rawPtr unsafe.Pointer, outSize uint) { + rawPtr = C._duk_to_buffer(d.duk_context, C.duk_idx_t(index), (*C.duk_size_t)(unsafe.Pointer(&outSize))) + return rawPtr, outSize +} + +// See: http://duktape.org/api.html#duk_to_defaultvalue +func (d *Context) ToDefaultvalue(index int, hint int) { + C.duk_to_defaultvalue(d.duk_context, C.duk_idx_t(index), C.duk_int_t(hint)) +} + +// See: http://duktape.org/api.html#duk_to_dynamic_buffer +func (d *Context) ToDynamicBuffer(index int) (rawPtr unsafe.Pointer, outSize uint) { + rawPtr = C._duk_to_dynamic_buffer(d.duk_context, C.duk_idx_t(index), (*C.duk_size_t)(unsafe.Pointer(&outSize))) + return rawPtr, outSize +} + +// See: http://duktape.org/api.html#duk_to_fixed_buffer +func (d *Context) ToFixedBuffer(index int) (rawPtr unsafe.Pointer, outSize uint) { + rawPtr = C._duk_to_fixed_buffer(d.duk_context, C.duk_idx_t(index), (*C.duk_size_t)(unsafe.Pointer(&outSize))) + return rawPtr, outSize +} + +// See: http://duktape.org/api.html#duk_to_int +func (d *Context) ToInt(index int) int { + return int(C.duk_to_int(d.duk_context, C.duk_idx_t(index))) +} + +// See: http://duktape.org/api.html#duk_to_int32 +func (d *Context) ToInt32(index int) int32 { + return int32(C.duk_to_int32(d.duk_context, C.duk_idx_t(index))) +} + +// See: http://duktape.org/api.html#duk_to_lstring +func (d *Context) ToLstring(index int) string { + if s := C.duk_to_lstring(d.duk_context, C.duk_idx_t(index), nil); s != nil { + return C.GoString(s) + } + return "" +} + +// See: http://duktape.org/api.html#duk_to_null +func (d *Context) ToNull(index int) { + C.duk_to_null(d.duk_context, C.duk_idx_t(index)) +} + +// See: http://duktape.org/api.html#duk_to_number +func (d *Context) ToNumber(index int) float64 { + return float64(C.duk_to_number(d.duk_context, C.duk_idx_t(index))) +} + +// See: http://duktape.org/api.html#duk_to_object +func (d *Context) ToObject(index int) { + C.duk_to_object(d.duk_context, C.duk_idx_t(index)) +} + +// See: http://duktape.org/api.html#duk_to_pointer +func (d *Context) ToPointer(index int) unsafe.Pointer { + return C.duk_to_pointer(d.duk_context, C.duk_idx_t(index)) +} + +// See: http://duktape.org/api.html#duk_to_primitive +func (d *Context) ToPrimitive(index int, hint int) { + C.duk_to_primitive(d.duk_context, C.duk_idx_t(index), C.duk_int_t(hint)) +} + +// See: http://duktape.org/api.html#duk_to_string +func (d *Context) ToString(index int) string { + if s := C.duk_to_string(d.duk_context, C.duk_idx_t(index)); s != nil { + return C.GoString(s) + } + return "" +} + +// See: http://duktape.org/api.html#duk_to_uint +func (d *Context) ToUint(index int) uint { + return uint(C.duk_to_uint(d.duk_context, C.duk_idx_t(index))) +} + +// See: http://duktape.org/api.html#duk_to_uint16 +func (d *Context) ToUint16(index int) uint16 { + return uint16(C.duk_to_uint16(d.duk_context, C.duk_idx_t(index))) +} + +// See: http://duktape.org/api.html#duk_to_uint32 +func (d *Context) ToUint32(index int) uint32 { + return uint32(C.duk_to_uint32(d.duk_context, C.duk_idx_t(index))) +} + +// See: http://duktape.org/api.html#duk_to_undefined +func (d *Context) ToUndefined(index int) { + C.duk_to_undefined(d.duk_context, C.duk_idx_t(index)) +} + +// See: http://duktape.org/api.html#duk_trim +func (d *Context) Trim(index int) { + C.duk_trim(d.duk_context, C.duk_idx_t(index)) +} + +// See: http://duktape.org/api.html#duk_xcopy_top +func (d *Context) XcopyTop(fromCtx *Context, count int) { + C._duk_xcopy_top(d.duk_context, fromCtx.duk_context, C.duk_idx_t(count)) +} + +// See: http://duktape.org/api.html#duk_xmove_top +func (d *Context) XmoveTop(fromCtx *Context, count int) { + C._duk_xmove_top(d.duk_context, fromCtx.duk_context, C.duk_idx_t(count)) +} + +// See: http://duktape.org/api.html#duk_push_pointer +func (d *Context) PushPointer(p unsafe.Pointer) { + C.duk_push_pointer(d.duk_context, p) +} + +//---[ Duktape 1.3 API ]--- // +// See: http://duktape.org/api.html#duk_debugger_attach +func (d *Context) DebuggerAttach( + readFn, + writeFn, + peekFn, + readFlushFn, + writeFlushFn, + detachedFn *[0]byte, + uData unsafe.Pointer) { + C.duk_debugger_attach( + d.duk_context, + readFn, + writeFn, + peekFn, + readFlushFn, + writeFlushFn, + nil, + detachedFn, + uData, + ) +} + +// See: http://duktape.org/api.html#duk_debugger_cooperate +func (d *Context) DebuggerCooperate() { + C.duk_debugger_cooperate(d.duk_context) +} + +// See: http://duktape.org/api.html#duk_debugger_detach +func (d *Context) DebuggerDetach() { + C.duk_debugger_detach(d.duk_context) +} + +// See: http://duktape.org/api.html#duk_dump_function +func (d *Context) DumpFunction() { + C.duk_dump_function(d.duk_context) +} + +// See: http://duktape.org/api.html#duk_error_va +func (d *Context) ErrorVa(errCode int, a ...interface{}) { + str := fmt.Sprint(a...) + d.Error(errCode, str) +} + +// See: http://duktape.org/api.html#duk_instanceof +func (d *Context) Instanceof(idx1, idx2 int) bool { + return int(C.duk_instanceof(d.duk_context, C.duk_idx_t(idx1), C.duk_idx_t(idx2))) == 1 +} + +// See: http://duktape.org/api.html#duk_is_lightfunc +func (d *Context) IsLightfunc(index int) bool { + return int(C.duk_is_lightfunc(d.duk_context, C.duk_idx_t(index))) == 1 +} + +// See: http://duktape.org/api.html#duk_load_function +func (d *Context) LoadFunction() { + C.duk_load_function(d.duk_context) +} + +// See: http://duktape.org/api.html#duk_log +func (d *Context) Log(loglevel int, format string, value interface{}) { + __str__ := C.CString(fmt.Sprintf(format, value)) + C._duk_log(d.duk_context, C.duk_int_t(loglevel), __str__) + C.free(unsafe.Pointer(__str__)) +} + +// See: http://duktape.org/api.html#duk_log_va +func (d *Context) LogVa(logLevel int, format string, values ...interface{}) { + __str__ := C.CString(fmt.Sprintf(format, values...)) + C._duk_log(d.duk_context, C.duk_int_t(logLevel), __str__) + C.free(unsafe.Pointer(__str__)) +} + +// See: http://duktape.org/api.html#duk_pnew +func (d *Context) Pnew(nargs int) error { + result := int(C.duk_pnew(d.duk_context, C.duk_idx_t(nargs))) + return d.castStringToError(result) +} + +// See: http://duktape.org/api.html#duk_push_buffer_object +func (d *Context) PushBufferObject(bufferIdx, size, length int, flags uint) { + C.duk_push_buffer_object( + d.duk_context, + C.duk_idx_t(bufferIdx), + C.duk_size_t(size), + C.duk_size_t(length), + C.duk_uint_t(flags), + ) +} + +// See: http://duktape.org/api.html#duk_push_c_lightfunc +func (d *Context) PushCLightfunc(fn *[0]byte, nargs, length, magic int) int { + return int(C.duk_push_c_lightfunc( + d.duk_context, + fn, + C.duk_idx_t(nargs), + C.duk_idx_t(length), + C.duk_int_t(magic), + )) +} + +// See: http://duktape.org/api.html#duk_push_error_object_va +func (d *Context) PushErrorObjectVa(errCode int, format string, values ...interface{}) { + __str__ := C.CString(fmt.Sprintf(format, values...)) + C._duk_push_error_object(d.duk_context, C.duk_errcode_t(errCode), __str__) + C.free(unsafe.Pointer(__str__)) +} + +// See: http://duktape.org/api.html#duk_push_external_buffer +func (d *Context) PushExternalBuffer() { + C._duk_push_external_buffer(d.duk_context) +} + +/** + * Unimplemented. + * + * CharCodeAt see: http://duktape.org/api.html#duk_char_code_at + * CreateHeap see: http://duktape.org/api.html#duk_create_heap + * DecodeString see: http://duktape.org/api.html#duk_decode_string + * Free see: http://duktape.org/api.html#duk_free + * FreeRaw see: http://duktape.org/api.html#duk_free_raw + * GetCFunction see: http://duktape.org/api.html#duk_get_c_function + * GetMemoryFunctions see: http://duktape.org/api.html#duk_get_memory_functions + * MapString see: http://duktape.org/api.html#duk_map_string + * PushSprintf see: http://duktape.org/api.html#duk_push_sprintf + * PushVsprintf see: http://duktape.org/api.html#duk_push_vsprintf + * PutFunctionList see: http://duktape.org/api.html#duk_put_function_list + * PutNumberList see: http://duktape.org/api.html#duk_put_number_list + * Realloc see: http://duktape.org/api.html#duk_realloc + * ReallocRaw see: http://duktape.org/api.html#duk_realloc_raw + * RequireCFunction see: http://duktape.org/api.html#duk_require_c_function + * ConfigBuffer see: http://duktape.org/api.html#duk_config_buffer + * GetBufferData see: http://duktape.org/api.html#duk_get_buffer_data + * StealBuffer see: http://duktape.org/api.html#duk_steal_buffer + * RequireBufferData see: http://duktape.org/api.html#duk_require_buffer_data + * IsEvalError see: http://duktape.org/api.html#duk_is_eval_error + */ diff --git a/vendor/gopkg.in/olebedev/go-duktape.v3/appveyor.yml b/vendor/gopkg.in/olebedev/go-duktape.v3/appveyor.yml new file mode 100644 index 000000000..7d38d58b1 --- /dev/null +++ b/vendor/gopkg.in/olebedev/go-duktape.v3/appveyor.yml @@ -0,0 +1,34 @@ +os: Visual Studio 2015 + +clone_folder: C:\gopath\src\gopkg.in/olebedev/go-duktape.v3 +clone_depth: 5 +version: "{branch}.{build}" +environment: + global: + GOPATH: C:\gopath + CC: gcc.exe + matrix: + - DUKTAPE_ARCH: amd64 + MSYS2_ARCH: x86_64 + MSYS2_BITS: 64 + MSYSTEM: MINGW64 + PATH: C:\msys64\mingw64\bin\;C:\Program Files (x86)\NSIS\;%PATH% + - DUKTAPE_ARCH: 386 + MSYS2_ARCH: i686 + MSYS2_BITS: 32 + MSYSTEM: MINGW32 + PATH: C:\msys64\mingw32\bin\;C:\Program Files (x86)\NSIS\;%PATH% + +install: + - rmdir C:\go /s /q + - appveyor DownloadFile https://storage.googleapis.com/golang/go1.9.2.windows-%DUKTAPE_ARCH%.zip + - 7z x go1.9.2.windows-%DUKTAPE_ARCH%.zip -y -oC:\ > NUL + - go version + - gcc --version + +build_script: + - go get -t + - go install ./... + +test_script: + - go test ./... diff --git a/vendor/gopkg.in/olebedev/go-duktape.v3/conts.go b/vendor/gopkg.in/olebedev/go-duktape.v3/conts.go new file mode 100644 index 000000000..f3dbd8bc8 --- /dev/null +++ b/vendor/gopkg.in/olebedev/go-duktape.v3/conts.go @@ -0,0 +1,121 @@ +package duktape + +const ( + CompileEval uint = 1 << iota + CompileFunction + CompileStrict + CompileSafe + CompileNoResult + CompileNoSource + CompileStrlen +) + +const ( + TypeNone Type = iota + TypeUndefined + TypeNull + TypeBoolean + TypeNumber + TypeString + TypeObject + TypeBuffer + TypePointer + TypeLightFunc +) + +const ( + TypeMaskNone uint = 1 << iota + TypeMaskUndefined + TypeMaskNull + TypeMaskBoolean + TypeMaskNumber + TypeMaskString + TypeMaskObject + TypeMaskBuffer + TypeMaskPointer + TypeMaskLightFunc +) + +const ( + EnumIncludeNonenumerable uint = 1 << iota + EnumIncludeInternal + EnumOwnPropertiesOnly + EnumArrayIndicesOnly + EnumSortArrayIndices + NoProxyBehavior +) + +const ( + ErrNone int = 0 + + // Internal to Duktape + ErrUnimplemented int = 50 + iota + ErrUnsupported + ErrInternal + ErrAlloc + ErrAssertion + ErrAPI + ErrUncaughtError +) + +const ( + // Common prototypes + ErrError int = 1 + iota + ErrEval + ErrRange + ErrReference + ErrSyntax + ErrType + ErrURI +) + +const ( + // Returned error values + ErrRetUnimplemented int = -(ErrUnimplemented + iota) + ErrRetUnsupported + ErrRetInternal + ErrRetAlloc + ErrRetAssertion + ErrRetAPI + ErrRetUncaughtError +) + +const ( + ErrRetError int = -(ErrError + iota) + ErrRetEval + ErrRetRange + ErrRetReference + ErrRetSyntax + ErrRetType + ErrRetURI +) + +const ( + ExecSuccess = iota + ExecError +) + +const ( + LogTrace int = iota + LogDebug + LogInfo + LogWarn + LogError + LogFatal +) + +const ( + BufobjDuktapeAuffer = 0 + BufobjNodejsAuffer = 1 + BufobjArraybuffer = 2 + BufobjDataview = 3 + BufobjInt8array = 4 + BufobjUint8array = 5 + BufobjUint8clampedarray = 6 + BufobjInt16array = 7 + BufobjUint16array = 8 + BufobjInt32array = 9 + BufobjUint32array = 10 + BufobjFloat32array = 11 + BufobjFloat64array = 12 +) diff --git a/vendor/gopkg.in/olebedev/go-duktape.v3/duk_alloc_pool.c b/vendor/gopkg.in/olebedev/go-duktape.v3/duk_alloc_pool.c new file mode 100755 index 000000000..750fa71df --- /dev/null +++ b/vendor/gopkg.in/olebedev/go-duktape.v3/duk_alloc_pool.c @@ -0,0 +1,612 @@ +/* + * Pool allocator for low memory targets. + */ + +#include +#include +#include +#include +#include +#include "duktape.h" +#include "duk_alloc_pool.h" + +/* Define to enable some debug printfs. */ +/* #define DUK_ALLOC_POOL_DEBUG */ + +/* Define to enable approximate waste tracking. */ +/* #define DUK_ALLOC_POOL_TRACK_WASTE */ + +/* Define to track global highwater for used and waste bytes. VERY SLOW, only + * useful for manual testing. + */ +/* #define DUK_ALLOC_POOL_TRACK_HIGHWATER */ + +#if defined(DUK_ALLOC_POOL_ROMPTR_COMPRESSION) +#if 0 /* This extern declaration is provided by duktape.h, array provided by duktape.c. */ +extern const void * const duk_rom_compressed_pointers[]; +#endif +const void *duk_alloc_pool_romptr_low = NULL; +const void *duk_alloc_pool_romptr_high = NULL; +static void duk__alloc_pool_romptr_init(void); +#endif + +#if defined(DUK_USE_HEAPPTR16) +void *duk_alloc_pool_ptrcomp_base = NULL; +#endif + +#if defined(DUK_ALLOC_POOL_DEBUG) +static void duk__alloc_pool_dprintf(const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); +} +#endif + +/* + * Pool initialization + */ + +void *duk_alloc_pool_init(char *buffer, + size_t size, + const duk_pool_config *configs, + duk_pool_state *states, + int num_pools, + duk_pool_global *global) { + double t_min, t_max, t_curr, x; + int step, i, j, n; + size_t total; + char *p; + + /* XXX: check that 'size' is not too large when using pointer + * compression. + */ + + /* To optimize pool counts first come up with a 't' which still allows + * total pool size to fit within user provided region. After that + * sprinkle any remaining bytes to the counts. Binary search with a + * fixed step count; last round uses 't_min' as 't_curr' to ensure it + * succeeds. + */ + + t_min = 0.0; /* Unless config is insane, this should always be "good". */ + t_max = 1e6; + + for (step = 0; ; step++) { + if (step >= 100) { + /* Force "known good", rerun config, and break out. + * Deals with rounding corner cases where t_curr is + * persistently "bad" even though t_min is a valid + * solution. + */ + t_curr = t_min; + } else { + t_curr = (t_min + t_max) / 2.0; + } + + for (i = 0, total = 0; i < num_pools; i++) { + states[i].size = configs[i].size; + + /* Target bytes = A*t + B ==> target count = (A*t + B) / block_size. + * Rely on A and B being small enough so that 'x' won't wrap. + */ + x = ((double) configs[i].a * t_curr + (double) configs[i].b) / (double) configs[i].size; + + states[i].count = (unsigned int) x; + total += (size_t) states[i].size * (size_t) states[i].count; + if (total > size) { + goto bad; + } + } + + /* t_curr is good. */ +#if defined(DUK_ALLOC_POOL_DEBUG) + duk__alloc_pool_dprintf("duk_alloc_pool_init: step=%d, t=[%lf %lf %lf] -> total %ld/%ld (good)\n", + step, t_min, t_curr, t_max, (long) total, (long) size); +#endif + if (step >= 100) { + /* Keep state[] initialization state. The state was + * created using the highest 't_min'. + */ + break; + } + t_min = t_curr; + continue; + + bad: + /* t_curr is bad. */ +#if defined(DUK_ALLOC_POOL_DEBUG) + duk__alloc_pool_dprintf("duk_alloc_pool_init: step=%d, t=[%lf %lf %lf] -> total %ld/%ld (bad)\n", + step, t_min, t_curr, t_max, (long) total, (long) size); +#endif + + if (step >= 1000) { + /* Cannot find any good solution; shouldn't happen + * unless config is bad or 'size' is so small that + * even a baseline allocation won't fit. + */ + return NULL; + } + t_max = t_curr; + /* continue */ + } + + /* The base configuration is now good; sprinkle any leftovers to + * pools in descending order. Note that for good t_curr, 'total' + * indicates allocated bytes so far and 'size - total' indicates + * leftovers. + */ + for (i = num_pools - 1; i >= 0; i--) { + while (size - total >= states[i].size) { + /* Ignore potential wrapping of states[i].count as the count + * is 32 bits and shouldn't wrap in practice. + */ + states[i].count++; + total += states[i].size; +#if defined(DUK_ALLOC_POOL_DEBUG) + duk__alloc_pool_dprintf("duk_alloc_pool_init: sprinkle %ld bytes (%ld left after) to pool index %ld, new count %ld\n", + (long) states[i].size, (long) (size - total), (long) i, (long) states[i].count); +#endif + } + } + + /* Pool counts are final. Allocate the user supplied region based + * on the final counts, initialize free lists for each block size, + * and otherwise finalize 'state' for use. + */ + p = buffer; + global->num_pools = num_pools; + global->states = states; +#if defined(DUK_ALLOC_POOL_TRACK_HIGHWATER) +#if defined(DUK_ALLOC_POOL_DEBUG) + duk__alloc_pool_dprintf("duk_alloc_pool_init: global highwater mark tracking enabled, THIS IS VERY SLOW!\n"); +#endif + global->hwm_used_bytes = 0U; + global->hwm_waste_bytes = 0U; +#endif +#if defined(DUK_ALLOC_POOL_TRACK_WASTE) +#if defined(DUK_ALLOC_POOL_DEBUG) + duk__alloc_pool_dprintf("duk_alloc_pool_init: approximate waste tracking enabled\n"); +#endif +#endif + +#if defined(DUK_USE_HEAPPTR16) + /* Register global base value for pointer compression, assumes + * a single active pool -4 allows a single subtract to be used and + * still ensures no non-NULL pointer encodes to zero. + */ + duk_alloc_pool_ptrcomp_base = (void *) (p - 4); +#endif + + for (i = 0; i < num_pools; i++) { + n = (int) states[i].count; + if (n > 0) { + states[i].first = (duk_pool_free *) p; + for (j = 0; j < n; j++) { + char *p_next = p + states[i].size; + ((duk_pool_free *) p)->next = + (j == n - 1) ? (duk_pool_free *) NULL : (duk_pool_free *) p_next; + p = p_next; + } + } else { + states[i].first = (duk_pool_free *) NULL; + } + states[i].alloc_end = p; +#if defined(DUK_ALLOC_POOL_TRACK_HIGHWATER) + states[i].hwm_used_count = 0; +#endif + /* All members of 'state' now initialized. */ + +#if defined(DUK_ALLOC_POOL_DEBUG) + duk__alloc_pool_dprintf("duk_alloc_pool_init: block size %5ld, count %5ld, %8ld total bytes, " + "end %p\n", + (long) states[i].size, (long) states[i].count, + (long) states[i].size * (long) states[i].count, + (void *) states[i].alloc_end); +#endif + } + +#if defined(DUK_ALLOC_POOL_ROMPTR_COMPRESSION) + /* ROM pointer compression precomputation. Assumes a single active + * pool. + */ + duk__alloc_pool_romptr_init(); +#endif + + /* Use 'global' as udata. */ + return (void *) global; +} + +/* + * Misc helpers + */ + +#if defined(DUK_ALLOC_POOL_TRACK_WASTE) +static void duk__alloc_pool_set_waste_marker(void *ptr, size_t used, size_t size) { + /* Rely on the base pointer and size being divisible by 4 and thus + * aligned. Use 32-bit markers: a 4-byte resolution is good enough, + * and comparing 32 bits at a time makes false waste estimates less + * likely than when comparing as bytes. + */ + duk_uint32_t *p, *p_start, *p_end; + size_t used_round; + + used_round = (used + 3U) & ~0x03U; /* round up to 4 */ + p_end = (duk_uint32_t *) ((duk_uint8_t *) ptr + size); + p_start = (duk_uint32_t *) ((duk_uint8_t *) ptr + used_round); + p = (duk_uint32_t *) p_start; + while (p != p_end) { + *p++ = DUK_ALLOC_POOL_WASTE_MARKER; + } +} +#else /* DUK_ALLOC_POOL_TRACK_WASTE */ +static void duk__alloc_pool_set_waste_marker(void *ptr, size_t used, size_t size) { + (void) ptr; (void) used; (void) size; +} +#endif /* DUK_ALLOC_POOL_TRACK_WASTE */ + +#if defined(DUK_ALLOC_POOL_TRACK_WASTE) +static size_t duk__alloc_pool_get_waste_estimate(void *ptr, size_t size) { + duk_uint32_t *p, *p_end, *p_start; + + /* Assumes size is >= 4. */ + p_start = (duk_uint32_t *) ptr; + p_end = (duk_uint32_t *) ((duk_uint8_t *) ptr + size); + p = p_end; + + /* This scan may cause harmless valgrind complaints: there may be + * uninitialized bytes within the legitimate allocation or between + * the start of the waste marker and the end of the allocation. + */ + do { + p--; + if (*p == DUK_ALLOC_POOL_WASTE_MARKER) { + ; + } else { + return (size_t) (p_end - p - 1) * 4U; + } + } while (p != p_start); + + return size; +} +#else /* DUK_ALLOC_POOL_TRACK_WASTE */ +static size_t duk__alloc_pool_get_waste_estimate(void *ptr, size_t size) { + (void) ptr; (void) size; + return 0; +} +#endif /* DUK_ALLOC_POOL_TRACK_WASTE */ + +static int duk__alloc_pool_ptr_in_freelist(duk_pool_state *s, void *ptr) { + duk_pool_free *curr; + + for (curr = s->first; curr != NULL; curr = curr->next) { + if ((void *) curr == ptr) { + return 1; + } + } + return 0; +} + +void duk_alloc_pool_get_pool_stats(duk_pool_state *s, duk_pool_stats *res) { + void *curr; + size_t free_count; + size_t used_count; + size_t waste_bytes; + + curr = s->alloc_end - (s->size * s->count); + free_count = 0U; + waste_bytes = 0U; + while (curr != s->alloc_end) { + if (duk__alloc_pool_ptr_in_freelist(s, curr)) { + free_count++; + } else { + waste_bytes += duk__alloc_pool_get_waste_estimate(curr, s->size); + } + curr = curr + s->size; + } + used_count = (size_t) (s->count - free_count); + + res->used_count = used_count; + res->used_bytes = (size_t) (used_count * s->size); + res->free_count = free_count; + res->free_bytes = (size_t) (free_count * s->size); + res->waste_bytes = waste_bytes; +#if defined(DUK_ALLOC_POOL_TRACK_HIGHWATER) + res->hwm_used_count = s->hwm_used_count; +#else + res->hwm_used_count = 0U; +#endif +} + +void duk_alloc_pool_get_global_stats(duk_pool_global *g, duk_pool_global_stats *res) { + int i; + size_t total_used = 0U; + size_t total_free = 0U; + size_t total_waste = 0U; + + for (i = 0; i < g->num_pools; i++) { + duk_pool_state *s = &g->states[i]; + duk_pool_stats stats; + + duk_alloc_pool_get_pool_stats(s, &stats); + + total_used += stats.used_bytes; + total_free += stats.free_bytes; + total_waste += stats.waste_bytes; + } + + res->used_bytes = total_used; + res->free_bytes = total_free; + res->waste_bytes = total_waste; +#if defined(DUK_ALLOC_POOL_TRACK_HIGHWATER) + res->hwm_used_bytes = g->hwm_used_bytes; + res->hwm_waste_bytes = g->hwm_waste_bytes; +#else + res->hwm_used_bytes = 0U; + res->hwm_waste_bytes = 0U; +#endif +} + +#if defined(DUK_ALLOC_POOL_TRACK_HIGHWATER) +static void duk__alloc_pool_update_highwater(duk_pool_global *g) { + int i; + size_t total_used = 0U; + size_t total_free = 0U; + size_t total_waste = 0U; + + /* Per pool highwater used count, useful to checking if a pool is + * too small. + */ + for (i = 0; i < g->num_pools; i++) { + duk_pool_state *s = &g->states[i]; + duk_pool_stats stats; + + duk_alloc_pool_get_pool_stats(s, &stats); + if (stats.used_count > s->hwm_used_count) { +#if defined(DUK_ALLOC_POOL_DEBUG) + duk__alloc_pool_dprintf("duk__alloc_pool_update_highwater: pool %ld (%ld bytes) highwater updated: count %ld -> %ld\n", + (long) i, (long) s->size, + (long) s->hwm_used_count, (long) stats.used_count); +#endif + s->hwm_used_count = stats.used_count; + } + + total_used += stats.used_bytes; + total_free += stats.free_bytes; + total_waste += stats.waste_bytes; + } + + /* Global highwater mark for used and waste bytes. Both fields are + * updated from the same snapshot based on highest used count. + * This is VERY, VERY slow and only useful for development. + * (Note that updating HWM states for pools individually and then + * summing them won't create a consistent global snapshot. There + * are still easy ways to make this much, much faster.) + */ + if (total_used > g->hwm_used_bytes) { +#if defined(DUK_ALLOC_POOL_DEBUG) + duk__alloc_pool_dprintf("duk__alloc_pool_update_highwater: global highwater updated: used=%ld, bytes=%ld -> " + "used=%ld, bytes=%ld\n", + (long) g->hwm_used_bytes, (long) g->hwm_waste_bytes, + (long) total_used, (long) total_waste); +#endif + g->hwm_used_bytes = total_used; + g->hwm_waste_bytes = total_waste; + } +} +#else /* DUK_ALLOC_POOL_TRACK_HIGHWATER */ +static void duk__alloc_pool_update_highwater(duk_pool_global *g) { + (void) g; +} +#endif /* DUK_ALLOC_POOL_TRACK_HIGHWATER */ + +/* + * Allocation providers + */ + +void *duk_alloc_pool(void *udata, duk_size_t size) { + duk_pool_global *g = (duk_pool_global *) udata; + int i, n; + +#if defined(DUK_ALLOC_POOL_DEBUG) + duk__alloc_pool_dprintf("duk_alloc_pool: %p %ld\n", udata, (long) size); +#endif + + if (size == 0) { + return NULL; + } + + for (i = 0, n = g->num_pools; i < n; i++) { + duk_pool_state *st = g->states + i; + + if (size <= st->size) { + duk_pool_free *res = st->first; + if (res != NULL) { + st->first = res->next; + duk__alloc_pool_set_waste_marker((void *) res, size, st->size); + duk__alloc_pool_update_highwater(g); + return (void *) res; + } + } + + /* Allocation doesn't fit or no free entries, try to borrow + * from the next block size. There's no support for preventing + * a borrow at present. + */ + } + + return NULL; +} + +void *duk_realloc_pool(void *udata, void *ptr, duk_size_t size) { + duk_pool_global *g = (duk_pool_global *) udata; + int i, j, n; + +#if defined(DUK_ALLOC_POOL_DEBUG) + duk__alloc_pool_dprintf("duk_realloc_pool: %p %p %ld\n", udata, ptr, (long) size); +#endif + + if (ptr == NULL) { + return duk_alloc_pool(udata, size); + } + if (size == 0) { + duk_free_pool(udata, ptr); + return NULL; + } + + /* Non-NULL pointers are necessarily from the pool so we should + * always be able to find the allocation. + */ + + for (i = 0, n = g->num_pools; i < n; i++) { + duk_pool_state *st = g->states + i; + char *new_ptr; + + /* Because 'ptr' is assumed to be in the pool and pools are + * allocated in sequence, it suffices to check for end pointer + * only. + */ + if ((char *) ptr >= st->alloc_end) { + continue; + } + + if (size <= st->size) { + /* Allocation still fits existing allocation. Check if + * we can shrink the allocation to a smaller block size + * (smallest possible). + */ + for (j = 0; j < i; j++) { + duk_pool_state *st2 = g->states + j; + + if (size <= st2->size) { + new_ptr = (char *) st2->first; + if (new_ptr != NULL) { +#if defined(DUK_ALLOC_POOL_DEBUG) + duk__alloc_pool_dprintf("duk_realloc_pool: shrink, block size %ld -> %ld\n", + (long) st->size, (long) st2->size); +#endif + st2->first = ((duk_pool_free *) new_ptr)->next; + memcpy((void *) new_ptr, (const void *) ptr, (size_t) size); + ((duk_pool_free *) ptr)->next = st->first; + st->first = (duk_pool_free *) ptr; + duk__alloc_pool_set_waste_marker((void *) new_ptr, size, st2->size); + duk__alloc_pool_update_highwater(g); + return (void *) new_ptr; + } + } + } + + /* Failed to shrink; return existing pointer. */ + duk__alloc_pool_set_waste_marker((void *) ptr, size, st->size); + return ptr; + } + + /* Find first free larger block. */ + for (j = i + 1; j < n; j++) { + duk_pool_state *st2 = g->states + j; + + if (size <= st2->size) { + new_ptr = (char *) st2->first; + if (new_ptr != NULL) { + st2->first = ((duk_pool_free *) new_ptr)->next; + memcpy((void *) new_ptr, (const void *) ptr, (size_t) st->size); + ((duk_pool_free *) ptr)->next = st->first; + st->first = (duk_pool_free *) ptr; + duk__alloc_pool_set_waste_marker((void *) new_ptr, size, st2->size); + duk__alloc_pool_update_highwater(g); + return (void *) new_ptr; + } + } + } + + /* Failed to resize. */ + return NULL; + } + + /* We should never be here because 'ptr' should be a valid pool + * entry and thus always found above. + */ + return NULL; +} + +void duk_free_pool(void *udata, void *ptr) { + duk_pool_global *g = (duk_pool_global *) udata; + int i, n; + +#if defined(DUK_ALLOC_POOL_DEBUG) + duk__alloc_pool_dprintf("duk_free_pool: %p %p\n", udata, ptr); +#endif + + if (ptr == NULL) { + return; + } + + for (i = 0, n = g->num_pools; i < n; i++) { + duk_pool_state *st = g->states + i; + + /* Enough to check end address only. */ + if ((char *) ptr >= st->alloc_end) { + continue; + } + + ((duk_pool_free *) ptr)->next = st->first; + st->first = (duk_pool_free *) ptr; +#if 0 /* never necessary when freeing */ + duk__alloc_pool_update_highwater(g); +#endif + return; + } + + /* We should never be here because 'ptr' should be a valid pool + * entry and thus always found above. + */ +} + +/* + * Pointer compression + */ + +#if defined(DUK_ALLOC_POOL_ROMPTR_COMPRESSION) +static void duk__alloc_pool_romptr_init(void) { + /* Scan ROM pointer range for faster detection of "is 'p' a ROM pointer" + * later on. + */ + const void * const * ptrs = (const void * const *) duk_rom_compressed_pointers; + duk_alloc_pool_romptr_low = duk_alloc_pool_romptr_high = (const void *) *ptrs; + while (*ptrs) { + if (*ptrs > duk_alloc_pool_romptr_high) { + duk_alloc_pool_romptr_high = (const void *) *ptrs; + } + if (*ptrs < duk_alloc_pool_romptr_low) { + duk_alloc_pool_romptr_low = (const void *) *ptrs; + } + ptrs++; + } +} +#endif + +/* Encode/decode functions are defined in the header to allow inlining. */ + +#if defined(DUK_ALLOC_POOL_ROMPTR_COMPRESSION) +duk_uint16_t duk_alloc_pool_enc16_rom(void *ptr) { + /* The if-condition should be the fastest possible check + * for "is 'ptr' in ROM?". If pointer is in ROM, we'd like + * to compress it quickly. Here we just scan a ~1K array + * which is very bad for performance. + */ + const void * const * ptrs = duk_rom_compressed_pointers; + while (*ptrs) { + if (*ptrs == ptr) { + return DUK_ALLOC_POOL_ROMPTR_FIRST + (duk_uint16_t) (ptrs - duk_rom_compressed_pointers); + } + ptrs++; + } + + /* We should really never be here: Duktape should only be + * compressing pointers which are in the ROM compressed + * pointers list, which are known at 'make dist' time. + * We go on, causing a pointer compression error. + */ + return 0; +} +#endif diff --git a/vendor/gopkg.in/olebedev/go-duktape.v3/duk_alloc_pool.h b/vendor/gopkg.in/olebedev/go-duktape.v3/duk_alloc_pool.h new file mode 100755 index 000000000..286ec0166 --- /dev/null +++ b/vendor/gopkg.in/olebedev/go-duktape.v3/duk_alloc_pool.h @@ -0,0 +1,223 @@ +#if !defined(DUK_ALLOC_POOL_H_INCLUDED) +#define DUK_ALLOC_POOL_H_INCLUDED + +#include "duktape.h" + +/* 32-bit (big endian) marker used at the end of pool entries so that wasted + * space can be detected. Waste tracking must be enabled explicitly. + */ +#if defined(DUK_ALLOC_POOL_TRACK_WASTE) +#define DUK_ALLOC_POOL_WASTE_MARKER 0xedcb2345UL +#endif + +/* Pointer compression with ROM strings/objects: + * + * For now, use DUK_USE_ROM_OBJECTS to signal the need for compressed ROM + * pointers. DUK_USE_ROM_PTRCOMP_FIRST is provided for the ROM pointer + * compression range minimum to avoid duplication in user code. + */ +#if defined(DUK_USE_ROM_OBJECTS) && defined(DUK_USE_HEAPPTR16) +#define DUK_ALLOC_POOL_ROMPTR_COMPRESSION +#define DUK_ALLOC_POOL_ROMPTR_FIRST DUK_USE_ROM_PTRCOMP_FIRST + +/* This extern declaration is provided by duktape.h, array provided by duktape.c. + * Because duk_config.h may include this file (to get the inline functions) we + * need to forward declare this also here. + */ +extern const void * const duk_rom_compressed_pointers[]; +#endif + +/* Pool configuration for a certain block size. */ +typedef struct { + unsigned int size; /* must be divisible by 4 and >= sizeof(void *) */ + unsigned int a; /* bytes (not count) to allocate: a*t + b, t is an arbitrary scale parameter */ + unsigned int b; +} duk_pool_config; + +/* Freelist entry, must fit into the smallest block size. */ +struct duk_pool_free; +typedef struct duk_pool_free duk_pool_free; +struct duk_pool_free { + duk_pool_free *next; +}; + +/* Pool state for a certain block size. */ +typedef struct { + duk_pool_free *first; + char *alloc_end; + unsigned int size; + unsigned int count; +#if defined(DUK_ALLOC_POOL_TRACK_HIGHWATER) + unsigned int hwm_used_count; +#endif +} duk_pool_state; + +/* Statistics for a certain pool. */ +typedef struct { + size_t used_count; + size_t used_bytes; + size_t free_count; + size_t free_bytes; + size_t waste_bytes; + size_t hwm_used_count; +} duk_pool_stats; + +/* Top level state for all pools. Pointer to this struct is used as the allocator + * userdata pointer. + */ +typedef struct { + int num_pools; + duk_pool_state *states; +#if defined(DUK_ALLOC_POOL_TRACK_HIGHWATER) + size_t hwm_used_bytes; + size_t hwm_waste_bytes; +#endif +} duk_pool_global; + +/* Statistics for the entire set of pools. */ +typedef struct { + size_t used_bytes; + size_t free_bytes; + size_t waste_bytes; + size_t hwm_used_bytes; + size_t hwm_waste_bytes; +} duk_pool_global_stats; + +/* Initialize a pool allocator, arguments: + * - buffer and size: continuous region to use for pool, must align to 4 + * - config: configuration for pools in ascending block size + * - state: state for pools, matches config order + * - num_pools: number of entries in 'config' and 'state' + * - global: global state structure + * + * The 'config', 'state', and 'global' pointers must be valid beyond the init + * call, as long as the pool is used. + * + * Returns a void pointer to be used as userdata for the allocator functions. + * Concretely the return value will be "(void *) global", i.e. the global + * state struct. If pool init fails, the return value will be NULL. + */ +void *duk_alloc_pool_init(char *buffer, + size_t size, + const duk_pool_config *configs, + duk_pool_state *states, + int num_pools, + duk_pool_global *global); + +/* Duktape allocation providers. Typing matches Duktape requirements. */ +void *duk_alloc_pool(void *udata, duk_size_t size); +void *duk_realloc_pool(void *udata, void *ptr, duk_size_t size); +void duk_free_pool(void *udata, void *ptr); + +/* Stats. */ +void duk_alloc_pool_get_pool_stats(duk_pool_state *s, duk_pool_stats *res); +void duk_alloc_pool_get_global_stats(duk_pool_global *g, duk_pool_global_stats *res); + +/* Duktape pointer compression global state (assumes single pool). */ +#if defined(DUK_USE_ROM_OBJECTS) && defined(DUK_USE_HEAPPTR16) +extern const void *duk_alloc_pool_romptr_low; +extern const void *duk_alloc_pool_romptr_high; +duk_uint16_t duk_alloc_pool_enc16_rom(void *ptr); +#endif +#if defined(DUK_USE_HEAPPTR16) +extern void *duk_alloc_pool_ptrcomp_base; +#endif + +#if 0 +duk_uint16_t duk_alloc_pool_enc16(void *ptr); +void *duk_alloc_pool_dec16(duk_uint16_t val); +#endif + +/* Inlined pointer compression functions. Gcc and clang -Os won't in + * practice inline these without an "always inline" attribute because it's + * more size efficient (by a few kB) to use explicit calls instead. Having + * these defined inline here allows performance optimized builds to inline + * pointer compression operations. + * + * Pointer compression assumes there's a single globally registered memory + * pool which makes pointer compression more efficient. This would be easy + * to fix by adding a userdata pointer to the compression functions and + * plumbing the heap userdata from the compression/decompression macros. + */ + +/* DUK_ALWAYS_INLINE is not a public API symbol so it may go away in even a + * minor update. But it's pragmatic for this extra because it handles many + * compilers via duk_config.h detection. Check that the macro exists so that + * if it's gone, we can still compile. + */ +#if defined(DUK_ALWAYS_INLINE) +#define DUK__ALLOC_POOL_ALWAYS_INLINE DUK_ALWAYS_INLINE +#else +#define DUK__ALLOC_POOL_ALWAYS_INLINE /* nop */ +#endif + +#if defined(DUK_USE_HEAPPTR16) +static DUK__ALLOC_POOL_ALWAYS_INLINE duk_uint16_t duk_alloc_pool_enc16(void *ptr) { + if (ptr == NULL) { + /* With 'return 0' gcc and clang -Os generate inefficient code. + * For example, gcc -Os generates: + * + * 0804911d : + * 804911d: 55 push %ebp + * 804911e: 85 c0 test %eax,%eax + * 8049120: 89 e5 mov %esp,%ebp + * 8049122: 74 0b je 804912f + * 8049124: 2b 05 e4 90 07 08 sub 0x80790e4,%eax + * 804912a: c1 e8 02 shr $0x2,%eax + * 804912d: eb 02 jmp 8049131 + * 804912f: 31 c0 xor %eax,%eax + * 8049131: 5d pop %ebp + * 8049132: c3 ret + * + * The NULL path checks %eax for zero; if it is zero, a zero + * is unnecessarily loaded into %eax again. The non-zero path + * has an unnecessary jump as a side effect of this. + * + * Using 'return (duk_uint16_t) (intptr_t) ptr;' generates similarly + * inefficient code; not sure how to make the result better. + */ + return 0; + } +#if defined(DUK_ALLOC_POOL_ROMPTR_COMPRESSION) + if (ptr >= duk_alloc_pool_romptr_low && ptr <= duk_alloc_pool_romptr_high) { + /* This is complex enough now to need a separate function. */ + return duk_alloc_pool_enc16_rom(ptr); + } +#endif + return (duk_uint16_t) (((size_t) ((char *) ptr - (char *) duk_alloc_pool_ptrcomp_base)) >> 2); +} + +static DUK__ALLOC_POOL_ALWAYS_INLINE void *duk_alloc_pool_dec16(duk_uint16_t val) { + if (val == 0) { + /* As with enc16 the gcc and clang -Os output is inefficient, + * e.g. gcc -Os: + * + * 08049133 : + * 8049133: 55 push %ebp + * 8049134: 66 85 c0 test %ax,%ax + * 8049137: 89 e5 mov %esp,%ebp + * 8049139: 74 0e je 8049149 + * 804913b: 8b 15 e4 90 07 08 mov 0x80790e4,%edx + * 8049141: 0f b7 c0 movzwl %ax,%eax + * 8049144: 8d 04 82 lea (%edx,%eax,4),%eax + * 8049147: eb 02 jmp 804914b + * 8049149: 31 c0 xor %eax,%eax + * 804914b: 5d pop %ebp + * 804914c: c3 ret + */ + return NULL; + } +#if defined(DUK_ALLOC_POOL_ROMPTR_COMPRESSION) + if (val >= DUK_ALLOC_POOL_ROMPTR_FIRST) { + /* This is a blind lookup, could check index validity. + * Duktape should never decompress a pointer which would + * be out-of-bounds here. + */ + return (void *) (intptr_t) (duk_rom_compressed_pointers[val - DUK_ALLOC_POOL_ROMPTR_FIRST]); + } +#endif + return (void *) ((char *) duk_alloc_pool_ptrcomp_base + (((size_t) val) << 2)); +} +#endif + +#endif /* DUK_ALLOC_POOL_H_INCLUDED */ diff --git a/vendor/gopkg.in/olebedev/go-duktape.v3/duk_config.h b/vendor/gopkg.in/olebedev/go-duktape.v3/duk_config.h new file mode 100755 index 000000000..3f217ef7d --- /dev/null +++ b/vendor/gopkg.in/olebedev/go-duktape.v3/duk_config.h @@ -0,0 +1,3672 @@ +/* + * duk_config.h configuration header generated by genconfig.py. + * + * Git commit: a459cf3c9bd1779fc01b435d69302b742675a08f + * Git describe: v2.2.0 + * Git branch: master + * + * Supported platforms: + * - Mac OSX, iPhone, Darwin + * - Orbis + * - OpenBSD + * - Generic BSD + * - Atari ST TOS + * - AmigaOS + * - Durango (XboxOne) + * - Windows + * - Flashplayer (Crossbridge) + * - QNX + * - TI-Nspire + * - Emscripten + * - Linux + * - Solaris + * - AIX + * - HPUX + * - Generic POSIX + * - Cygwin + * - Generic UNIX + * - Generic fallback + * + * Supported architectures: + * - x86 + * - x64 + * - x32 + * - ARM 32-bit + * - ARM 64-bit + * - MIPS 32-bit + * - MIPS 64-bit + * - PowerPC 32-bit + * - PowerPC 64-bit + * - SPARC 32-bit + * - SPARC 64-bit + * - SuperH + * - Motorola 68k + * - Emscripten + * - Generic + * + * Supported compilers: + * - Clang + * - GCC + * - MSVC + * - Emscripten + * - TinyC + * - VBCC + * - Bruce's C compiler + * - Generic + * + */ + +#if !defined(DUK_CONFIG_H_INCLUDED) +#define DUK_CONFIG_H_INCLUDED + +/* + * Intermediate helper defines + */ + +/* DLL build detection */ +/* not configured for DLL build */ +#undef DUK_F_DLL_BUILD + +/* Apple OSX, iOS */ +#if defined(__APPLE__) +#define DUK_F_APPLE +#endif + +/* FreeBSD */ +#if defined(__FreeBSD__) || defined(__FreeBSD) +#define DUK_F_FREEBSD +#endif + +/* Orbis (PS4) variant */ +#if defined(DUK_F_FREEBSD) && defined(__ORBIS__) +#define DUK_F_ORBIS +#endif + +/* OpenBSD */ +#if defined(__OpenBSD__) || defined(__OpenBSD) +#define DUK_F_OPENBSD +#endif + +/* NetBSD */ +#if defined(__NetBSD__) || defined(__NetBSD) +#define DUK_F_NETBSD +#endif + +/* BSD variant */ +#if defined(DUK_F_FREEBSD) || defined(DUK_F_NETBSD) || defined(DUK_F_OPENBSD) || \ + defined(__bsdi__) || defined(__DragonFly__) +#define DUK_F_BSD +#endif + +/* Atari ST TOS. __TOS__ defined by PureC. No platform define in VBCC + * apparently, so to use with VBCC user must define __TOS__ manually. + */ +#if defined(__TOS__) +#define DUK_F_TOS +#endif + +/* Motorola 68K. Not defined by VBCC, so user must define one of these + * manually when using VBCC. + */ +#if defined(__m68k__) || defined(M68000) || defined(__MC68K__) +#define DUK_F_M68K +#endif + +/* AmigaOS. Neither AMIGA nor __amigaos__ is defined on VBCC, so user must + * define 'AMIGA' manually when using VBCC. + */ +#if defined(AMIGA) || defined(__amigaos__) +#define DUK_F_AMIGAOS +#endif + +/* PowerPC */ +#if defined(__powerpc) || defined(__powerpc__) || defined(__PPC__) +#define DUK_F_PPC +#if defined(__PPC64__) || defined(__LP64__) || defined(_LP64) +#define DUK_F_PPC64 +#else +#define DUK_F_PPC32 +#endif +#endif + +/* Durango (Xbox One) */ +#if defined(_DURANGO) || defined(_XBOX_ONE) +#define DUK_F_DURANGO +#endif + +/* Windows, both 32-bit and 64-bit */ +#if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64) || \ + defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__) +#define DUK_F_WINDOWS +#if defined(_WIN64) || defined(WIN64) +#define DUK_F_WIN64 +#else +#define DUK_F_WIN32 +#endif +#endif + +/* Flash player (e.g. Crossbridge) */ +#if defined(__FLASHPLAYER__) +#define DUK_F_FLASHPLAYER +#endif + +/* QNX */ +#if defined(__QNX__) +#define DUK_F_QNX +#endif + +/* TI-Nspire (using Ndless) */ +#if defined(_TINSPIRE) +#define DUK_F_TINSPIRE +#endif + +/* Emscripten (provided explicitly by user), improve if possible */ +#if defined(EMSCRIPTEN) +#define DUK_F_EMSCRIPTEN +#endif + +/* BCC (Bruce's C compiler): this is a "torture target" for compilation */ +#if defined(__BCC__) || defined(__BCC_VERSION__) +#define DUK_F_BCC +#endif + +/* Linux */ +#if defined(__linux) || defined(__linux__) || defined(linux) +#define DUK_F_LINUX +#endif + +/* illumos / Solaris */ +#if defined(__sun) && defined(__SVR4) +#define DUK_F_SUN +#if defined(__SUNPRO_C) && (__SUNPRO_C < 0x550) +#define DUK_F_OLD_SOLARIS +/* Defines _ILP32 / _LP64 required by DUK_F_X86/DUK_F_X64. Platforms + * are processed before architectures, so this happens before the + * DUK_F_X86/DUK_F_X64 detection is emitted. + */ +#include +#endif +#endif + +/* AIX */ +#if defined(_AIX) +/* defined(__xlc__) || defined(__IBMC__): works but too wide */ +#define DUK_F_AIX +#endif + +/* HPUX */ +#if defined(__hpux) +#define DUK_F_HPUX +#if defined(__ia64) +#define DUK_F_HPUX_ITANIUM +#endif +#endif + +/* POSIX */ +#if defined(__posix) +#define DUK_F_POSIX +#endif + +/* Cygwin */ +#if defined(__CYGWIN__) +#define DUK_F_CYGWIN +#endif + +/* Generic Unix (includes Cygwin) */ +#if defined(__unix) || defined(__unix__) || defined(unix) || \ + defined(DUK_F_LINUX) || defined(DUK_F_BSD) +#define DUK_F_UNIX +#endif + +/* C++ */ +#undef DUK_F_CPP +#if defined(__cplusplus) +#define DUK_F_CPP +#endif + +/* Intel x86 (32-bit), x64 (64-bit) or x32 (64-bit but 32-bit pointers), + * define only one of DUK_F_X86, DUK_F_X64, DUK_F_X32. + * https://sites.google.com/site/x32abi/ + * + * With DUK_F_OLD_SOLARIS the header must be included + * before this. + */ +#if defined(__amd64__) || defined(__amd64) || \ + defined(__x86_64__) || defined(__x86_64) || \ + defined(_M_X64) || defined(_M_AMD64) +#if defined(__ILP32__) || defined(_ILP32) +#define DUK_F_X32 +#else +#define DUK_F_X64 +#endif +#elif defined(i386) || defined(__i386) || defined(__i386__) || \ + defined(__i486__) || defined(__i586__) || defined(__i686__) || \ + defined(__IA32__) || defined(_M_IX86) || defined(__X86__) || \ + defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__) +#if defined(__LP64__) || defined(_LP64) +/* This should not really happen, but would indicate x64. */ +#define DUK_F_X64 +#else +#define DUK_F_X86 +#endif +#endif + +/* ARM */ +#if defined(__arm__) || defined(__thumb__) || defined(_ARM) || defined(_M_ARM) || defined(__aarch64__) +#define DUK_F_ARM +#if defined(__LP64__) || defined(_LP64) || defined(__arm64) || defined(__arm64__) || defined(__aarch64__) +#define DUK_F_ARM64 +#else +#define DUK_F_ARM32 +#endif +#endif + +/* MIPS. Related defines: __MIPSEB__, __MIPSEL__, __mips_isa_rev, __LP64__ */ +#if defined(__mips__) || defined(mips) || defined(_MIPS_ISA) || \ + defined(_R3000) || defined(_R4000) || defined(_R5900) || \ + defined(_MIPS_ISA_MIPS1) || defined(_MIPS_ISA_MIPS2) || \ + defined(_MIPS_ISA_MIPS3) || defined(_MIPS_ISA_MIPS4) || \ + defined(__mips) || defined(__MIPS__) +#define DUK_F_MIPS +#if defined(__LP64__) || defined(_LP64) || defined(__mips64) || \ + defined(__mips64__) || defined(__mips_n64) +#define DUK_F_MIPS64 +#else +#define DUK_F_MIPS32 +#endif +#endif + +/* SPARC */ +#if defined(sparc) || defined(__sparc) || defined(__sparc__) +#define DUK_F_SPARC +#if defined(__LP64__) || defined(_LP64) +#define DUK_F_SPARC64 +#else +#define DUK_F_SPARC32 +#endif +#endif + +/* SuperH */ +#if defined(__sh__) || \ + defined(__sh1__) || defined(__SH1__) || \ + defined(__sh2__) || defined(__SH2__) || \ + defined(__sh3__) || defined(__SH3__) || \ + defined(__sh4__) || defined(__SH4__) || \ + defined(__sh5__) || defined(__SH5__) +#define DUK_F_SUPERH +#endif + +/* Clang */ +#if defined(__clang__) +#define DUK_F_CLANG +#endif + +/* C99 or above */ +#undef DUK_F_C99 +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +#define DUK_F_C99 +#endif + +/* C++11 or above */ +#undef DUK_F_CPP11 +#if defined(__cplusplus) && (__cplusplus >= 201103L) +#define DUK_F_CPP11 +#endif + +/* GCC. Clang also defines __GNUC__ so don't detect GCC if using Clang. */ +#if defined(__GNUC__) && !defined(__clang__) && !defined(DUK_F_CLANG) +#define DUK_F_GCC +#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +/* Convenience, e.g. gcc 4.5.1 == 40501; http://stackoverflow.com/questions/6031819/emulating-gccs-builtin-unreachable */ +#define DUK_F_GCC_VERSION (__GNUC__ * 10000L + __GNUC_MINOR__ * 100L + __GNUC_PATCHLEVEL__) +#else +#error cannot figure out gcc version +#endif +#endif + +/* MinGW. Also GCC flags (DUK_F_GCC) are enabled now. */ +#if defined(__MINGW32__) || defined(__MINGW64__) +#define DUK_F_MINGW +#endif + +/* MSVC */ +#if defined(_MSC_VER) +/* MSVC preprocessor defines: http://msdn.microsoft.com/en-us/library/b0084kay.aspx + * _MSC_FULL_VER includes the build number, but it has at least two formats, see e.g. + * BOOST_MSVC_FULL_VER in http://www.boost.org/doc/libs/1_52_0/boost/config/compiler/visualc.hpp + */ +#define DUK_F_MSVC +#if defined(_MSC_FULL_VER) +#if (_MSC_FULL_VER > 100000000) +#define DUK_F_MSVC_FULL_VER _MSC_FULL_VER +#else +#define DUK_F_MSCV_FULL_VER (_MSC_FULL_VER * 10) +#endif +#endif +#endif /* _MSC_VER */ + +/* TinyC */ +#if defined(__TINYC__) +/* http://bellard.org/tcc/tcc-doc.html#SEC9 */ +#define DUK_F_TINYC +#endif + +/* VBCC */ +#if defined(__VBCC__) +#define DUK_F_VBCC +#endif + +#if defined(ANDROID) || defined(__ANDROID__) +#define DUK_F_ANDROID +#endif + +/* Atari Mint */ +#if defined(__MINT__) +#define DUK_F_MINT +#endif + +/* + * Platform autodetection + */ + +/* Workaround for older C++ compilers before including , + * see e.g.: https://sourceware.org/bugzilla/show_bug.cgi?id=15366 + */ +#if defined(__cplusplus) && !defined(__STDC_LIMIT_MACROS) +#define __STDC_LIMIT_MACROS +#endif +#if defined(__cplusplus) && !defined(__STDC_CONSTANT_MACROS) +#define __STDC_CONSTANT_MACROS +#endif + +#if defined(DUK_F_APPLE) +/* --- Mac OSX, iPhone, Darwin --- */ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include +#include + +/* http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor */ +#if TARGET_IPHONE_SIMULATOR +#define DUK_USE_OS_STRING "iphone-sim" +#elif TARGET_OS_IPHONE +#define DUK_USE_OS_STRING "iphone" +#elif TARGET_OS_MAC +#define DUK_USE_OS_STRING "osx" +#else +#define DUK_USE_OS_STRING "osx-unknown" +#endif + +/* Use _setjmp() on Apple by default, see GH-55. */ +#define DUK_JMPBUF_TYPE jmp_buf +#define DUK_SETJMP(jb) _setjmp((jb)) +#define DUK_LONGJMP(jb) _longjmp((jb), 1) +#elif defined(DUK_F_ORBIS) +/* --- Orbis --- */ +/* Orbis = PS4 */ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_S +/* no parsing (not an error) */ +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include +#include + +#define DUK_USE_OS_STRING "orbis" +#elif defined(DUK_F_OPENBSD) +/* --- OpenBSD --- */ +/* http://www.monkey.org/openbsd/archive/ports/0401/msg00089.html */ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include +#include + +#define DUK_USE_OS_STRING "openbsd" +#elif defined(DUK_F_BSD) +/* --- Generic BSD --- */ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include +#include + +#define DUK_USE_OS_STRING "bsd" +#elif defined(DUK_F_TOS) +/* --- Atari ST TOS --- */ +#define DUK_USE_DATE_NOW_TIME +#define DUK_USE_DATE_TZO_GMTIME +/* no parsing (not an error) */ +#define DUK_USE_DATE_FMT_STRFTIME +#include + +#define DUK_USE_OS_STRING "tos" + +/* TOS on M68K is always big endian. */ +#if !defined(DUK_USE_BYTEORDER) && defined(DUK_F_M68K) +#define DUK_USE_BYTEORDER 3 +#endif +#elif defined(DUK_F_AMIGAOS) +/* --- AmigaOS --- */ +#if defined(DUK_F_M68K) +/* AmigaOS on M68k */ +#define DUK_USE_DATE_NOW_TIME +#define DUK_USE_DATE_TZO_GMTIME +/* no parsing (not an error) */ +#define DUK_USE_DATE_FMT_STRFTIME +#include +#elif defined(DUK_F_PPC) +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#if !defined(UINTPTR_MAX) +#define UINTPTR_MAX UINT_MAX +#endif +#else +#error AmigaOS but not M68K/PPC, not supported now +#endif + +#define DUK_USE_OS_STRING "amigaos" + +/* AmigaOS on M68K or PPC is always big endian. */ +#if !defined(DUK_USE_BYTEORDER) && (defined(DUK_F_M68K) || defined(DUK_F_PPC)) +#define DUK_USE_BYTEORDER 3 +#endif +#elif defined(DUK_F_DURANGO) +/* --- Durango (XboxOne) --- */ +/* Durango = XboxOne + * Configuration is nearly identical to Windows, except for + * DUK_USE_DATE_TZO_WINDOWS. + */ + +/* 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. + */ +#if defined(DUK_COMPILING_DUKTAPE) && !defined(_CRT_SECURE_NO_WARNINGS) +#define _CRT_SECURE_NO_WARNINGS +#endif + +/* MSVC does not have sys/param.h */ +#define DUK_USE_DATE_NOW_WINDOWS +#define DUK_USE_DATE_TZO_WINDOWS_NO_DST +/* 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. + */ +#include +#endif + +#define DUK_USE_OS_STRING "durango" + +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 1 +#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. + */ +#if defined(DUK_COMPILING_DUKTAPE) && !defined(_CRT_SECURE_NO_WARNINGS) +#define _CRT_SECURE_NO_WARNINGS +#endif + +/* 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 +#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. + */ + +/* 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 + */ +#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" + +/* On Windows, assume we're little endian. Even Itanium which has a + * configurable endianness runs little endian in Windows. + */ +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 1 +#endif +#elif defined(DUK_F_FLASHPLAYER) +/* --- Flashplayer (Crossbridge) --- */ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include + +#define DUK_USE_OS_STRING "flashplayer" + +#if !defined(DUK_USE_BYTEORDER) && defined(DUK_F_FLASHPLAYER) +#define DUK_USE_BYTEORDER 1 +#endif +#elif defined(DUK_F_QNX) +/* --- QNX --- */ +#if defined(DUK_F_QNX) && defined(DUK_COMPILING_DUKTAPE) +/* See: /opt/qnx650/target/qnx6/usr/include/sys/platform.h */ +#define _XOPEN_SOURCE 600 +#define _POSIX_C_SOURCE 200112L +#endif + +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include + +#define DUK_USE_OS_STRING "qnx" +#elif defined(DUK_F_TINSPIRE) +/* --- TI-Nspire --- */ +#if defined(DUK_COMPILING_DUKTAPE) && !defined(_XOPEN_SOURCE) +#define _XOPEN_SOURCE /* e.g. strptime */ +#endif + +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include + +#define DUK_USE_OS_STRING "tinspire" +#elif defined(DUK_F_EMSCRIPTEN) +/* --- Emscripten --- */ +#if defined(DUK_COMPILING_DUKTAPE) +#if !defined(_POSIX_C_SOURCE) +#define _POSIX_C_SOURCE 200809L +#endif +#if !defined(_GNU_SOURCE) +#define _GNU_SOURCE /* e.g. getdate_r */ +#endif +#if !defined(_XOPEN_SOURCE) +#define _XOPEN_SOURCE /* e.g. strptime */ +#endif +#endif /* DUK_COMPILING_DUKTAPE */ + +#include +#if defined(DUK_F_BCC) +/* no endian.h */ +#else +#include +#endif /* DUK_F_BCC */ +#include +#include +#include +#include + +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME + +#define DUK_USE_OS_STRING "emscripten" +#elif defined(DUK_F_LINUX) +/* --- Linux --- */ +#if defined(DUK_COMPILING_DUKTAPE) +#if !defined(_POSIX_C_SOURCE) +#define _POSIX_C_SOURCE 200809L +#endif +#if !defined(_GNU_SOURCE) +#define _GNU_SOURCE /* e.g. getdate_r */ +#endif +#if !defined(_XOPEN_SOURCE) +#define _XOPEN_SOURCE /* e.g. strptime */ +#endif +#endif /* DUK_COMPILING_DUKTAPE */ + +#include +#if defined(DUK_F_BCC) +/* no endian.h or stdint.h */ +#else +#include +#include +#endif /* DUK_F_BCC */ +#include +#include +#include + +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#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 --- */ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME + +#include +#if defined(DUK_F_OLD_SOLARIS) +/* Old Solaris with no endian.h, stdint.h */ +#define DUK_F_NO_STDINT_H +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 3 +#endif +#else /* DUK_F_OLD_SOLARIS */ +#include +#endif /* DUK_F_OLD_SOLARIS */ + +#include +#include +#include + +#define DUK_USE_OS_STRING "solaris" +#elif defined(DUK_F_AIX) +/* --- AIX --- */ +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 3 +#endif +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include + +#define DUK_USE_OS_STRING "aix" +#elif defined(DUK_F_HPUX) +/* --- HPUX --- */ +#define DUK_F_NO_STDINT_H +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 3 +#endif +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include + +#define DUK_USE_OS_STRING "hpux" +#elif defined(DUK_F_POSIX) +/* --- Generic POSIX --- */ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include +#include + +#define DUK_USE_OS_STRING "posix" +#elif defined(DUK_F_CYGWIN) +/* --- Cygwin --- */ +/* don't use strptime() for now */ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#include +#include +#include + +#define DUK_JMPBUF_TYPE jmp_buf +#define DUK_SETJMP(jb) _setjmp((jb)) +#define DUK_LONGJMP(jb) _longjmp((jb), 1) + +#define DUK_USE_OS_STRING "windows" +#elif defined(DUK_F_UNIX) +/* --- Generic UNIX --- */ +#define DUK_USE_DATE_NOW_GETTIMEOFDAY +#define DUK_USE_DATE_TZO_GMTIME_R +#define DUK_USE_DATE_PRS_STRPTIME +#define DUK_USE_DATE_FMT_STRFTIME +#include +#include +#define DUK_USE_OS_STRING "unknown" +#else +/* --- Generic fallback --- */ +/* The most portable current time provider is time(), but it only has a + * one second resolution. + */ +#define DUK_USE_DATE_NOW_TIME + +/* The most portable way to figure out local time offset is gmtime(), + * but it's not thread safe so use with caution. + */ +#define DUK_USE_DATE_TZO_GMTIME + +/* Avoid custom date parsing and formatting for portability. */ +#undef DUK_USE_DATE_PRS_STRPTIME +#undef DUK_USE_DATE_FMT_STRFTIME + +/* Rely on C89 headers only; time.h must be here. */ +#include + +#define DUK_USE_OS_STRING "unknown" +#endif /* autodetect platform */ + +/* Shared includes: C89 */ +#include +#include +#include +#include /* varargs */ +#include +#include /* e.g. ptrdiff_t */ +#include +#include + +/* date.h is omitted, and included per platform */ + +/* Shared includes: stdint.h is C99 */ +#if defined(DUK_F_NO_STDINT_H) +/* stdint.h not available */ +#else +/* Technically C99 (C++11) but found in many systems. On some systems + * __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS must be defined before + * including stdint.h (see above). + */ +#include +#endif + +#if defined(DUK_F_CPP) +#include /* std::exception */ +#endif + +/* + * Architecture autodetection + */ + +#if defined(DUK_F_X86) +/* --- x86 --- */ +#define DUK_USE_ARCH_STRING "x86" +#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) +/* --- x64 --- */ +#define DUK_USE_ARCH_STRING "x64" +#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) +/* --- x32 --- */ +#define DUK_USE_ARCH_STRING "x32" +#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) +/* --- PowerPC 32-bit --- */ +#define DUK_USE_ARCH_STRING "ppc32" +#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) +/* --- PowerPC 64-bit --- */ +#define DUK_USE_ARCH_STRING "ppc64" +#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) +/* --- SuperH --- */ +#define DUK_USE_ARCH_STRING "sh" +/* Byte order varies, rely on autodetection. */ +/* 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) +/* --- Motorola 68k --- */ +#define DUK_USE_ARCH_STRING "m68k" +#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) +/* --- Emscripten --- */ +#define DUK_USE_ARCH_STRING "emscripten" +#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 +/* --- Generic --- */ +/* These are necessary wild guesses. */ +#define DUK_USE_ARCH_STRING "generic" +/* Rely on autodetection for byte order, alignment, and packed tval. */ +#endif /* autodetect architecture */ + +/* + * Compiler autodetection + */ + +#if defined(DUK_F_CLANG) +/* --- Clang --- */ +#if defined(DUK_F_C99) || defined(DUK_F_CPP11) +/* C99 / C++11 and above: rely on va_copy() which is required. */ +#define DUK_VA_COPY(dest,src) va_copy(dest,src) +#else +/* Clang: assume we have __va_copy() in non-C99 mode. */ +#define DUK_VA_COPY(dest,src) __va_copy(dest,src) +#endif + +#define DUK_NORETURN(decl) decl __attribute__((noreturn)) + +#if defined(__clang__) && defined(__has_builtin) +#if __has_builtin(__builtin_unreachable) +#define DUK_UNREACHABLE() do { __builtin_unreachable(); } while (0) +#endif +#endif + +#define DUK_USE_BRANCH_HINTS +#define DUK_LIKELY(x) __builtin_expect((x), 1) +#define DUK_UNLIKELY(x) __builtin_expect((x), 0) +#if defined(__clang__) && defined(__has_builtin) +#if __has_builtin(__builtin_unpredictable) +#define DUK_UNPREDICTABLE(x) __builtin_unpredictable((x)) +#endif +#endif + +#if defined(DUK_F_C99) || defined(DUK_F_CPP11) +#define DUK_NOINLINE __attribute__((noinline)) +#define DUK_INLINE inline +#define DUK_ALWAYS_INLINE inline __attribute__((always_inline)) +#endif + +/* DUK_HOT */ +/* DUK_COLD */ + +#if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS) +/* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're + * compiling Duktape or the application. + */ +#if defined(DUK_COMPILING_DUKTAPE) +#define DUK_EXTERNAL_DECL extern __declspec(dllexport) +#define DUK_EXTERNAL __declspec(dllexport) +#else +#define DUK_EXTERNAL_DECL extern __declspec(dllimport) +#define DUK_EXTERNAL should_not_happen +#endif +#if defined(DUK_SINGLE_FILE) +#define DUK_INTERNAL_DECL static +#define DUK_INTERNAL static +#else +#define DUK_INTERNAL_DECL extern +#define DUK_INTERNAL /*empty*/ +#endif +#define DUK_LOCAL_DECL static +#define DUK_LOCAL static +#else +#define DUK_EXTERNAL_DECL __attribute__ ((visibility("default"))) extern +#define DUK_EXTERNAL __attribute__ ((visibility("default"))) +#if defined(DUK_SINGLE_FILE) +#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG) +/* Minimize warnings for unused internal functions with GCC >= 3.1.1 and + * Clang. Based on documentation it should suffice to have the attribute + * in the declaration only, but in practice some warnings are generated unless + * the attribute is also applied to the definition. + */ +#define DUK_INTERNAL_DECL static __attribute__ ((unused)) +#define DUK_INTERNAL static __attribute__ ((unused)) +#else +#define DUK_INTERNAL_DECL static +#define DUK_INTERNAL static +#endif +#else +#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG) +#define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern +#define DUK_INTERNAL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) +#else +#define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) extern +#define DUK_INTERNAL __attribute__ ((visibility("hidden"))) +#endif +#endif +#define DUK_LOCAL_DECL static +#define DUK_LOCAL static +#endif + +#if defined(DUK_F_CPP) +#define DUK_USE_COMPILER_STRING "clang" +#else +#define DUK_USE_COMPILER_STRING "clang" +#endif + +#undef DUK_USE_VARIADIC_MACROS +#if defined(DUK_F_C99) || defined(DUK_F_CPP11) +#define DUK_USE_VARIADIC_MACROS +#endif + +#define DUK_USE_UNION_INITIALIZERS + +#undef DUK_USE_FLEX_C99 +#undef DUK_USE_FLEX_ZEROSIZE +#undef DUK_USE_FLEX_ONESIZE +#if defined(DUK_F_C99) +#define DUK_USE_FLEX_C99 +#else +#define DUK_USE_FLEX_ZEROSIZE +#endif + +#undef DUK_USE_GCC_PRAGMAS +#define DUK_USE_PACK_CLANG_ATTR +#elif defined(DUK_F_GCC) +/* --- GCC --- */ +#if defined(DUK_F_C99) || defined(DUK_F_CPP11) +/* C99 / C++11 and above: rely on va_copy() which is required. */ +#define DUK_VA_COPY(dest,src) va_copy(dest,src) +#else +/* GCC: assume we have __va_copy() in non-C99 mode. */ +#define DUK_VA_COPY(dest,src) __va_copy(dest,src) +#endif + +#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 20500L) +/* since gcc-2.5 */ +#define DUK_NORETURN(decl) decl __attribute__((noreturn)) +#endif + +#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L) +/* since gcc-4.5 */ +#define DUK_UNREACHABLE() do { __builtin_unreachable(); } while (0) +#endif + +#define DUK_USE_BRANCH_HINTS +#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L) +/* GCC: test not very accurate; enable only in relatively recent builds + * because of bugs in gcc-4.4 (http://lists.debian.org/debian-gcc/2010/04/msg00000.html) + */ +#define DUK_LIKELY(x) __builtin_expect((x), 1) +#define DUK_UNLIKELY(x) __builtin_expect((x), 0) +#endif +/* XXX: equivalent of clang __builtin_unpredictable? */ + +#if (defined(DUK_F_C99) || defined(DUK_F_CPP11)) && \ + defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 30101) +#define DUK_NOINLINE __attribute__((noinline)) +#define DUK_INLINE inline +#define DUK_ALWAYS_INLINE inline __attribute__((always_inline)) +#endif + +#if (defined(DUK_F_C99) || defined(DUK_F_CPP11)) && \ + defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40300) +#define DUK_HOT __attribute__((hot)) +#define DUK_COLD __attribute__((cold)) +#endif + +#if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS) +/* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're + * compiling Duktape or the application. + */ +#if defined(DUK_COMPILING_DUKTAPE) +#define DUK_EXTERNAL_DECL extern __declspec(dllexport) +#define DUK_EXTERNAL __declspec(dllexport) +#else +#define DUK_EXTERNAL_DECL extern __declspec(dllimport) +#define DUK_EXTERNAL should_not_happen +#endif +#if defined(DUK_SINGLE_FILE) +#define DUK_INTERNAL_DECL static +#define DUK_INTERNAL static +#else +#define DUK_INTERNAL_DECL extern +#define DUK_INTERNAL /*empty*/ +#endif +#define DUK_LOCAL_DECL static +#define DUK_LOCAL static +#elif defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40000) +#define DUK_EXTERNAL_DECL __attribute__ ((visibility("default"))) extern +#define DUK_EXTERNAL __attribute__ ((visibility("default"))) +#if defined(DUK_SINGLE_FILE) +#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG) +/* Minimize warnings for unused internal functions with GCC >= 3.1.1 and + * Clang. Based on documentation it should suffice to have the attribute + * in the declaration only, but in practice some warnings are generated unless + * the attribute is also applied to the definition. + */ +#define DUK_INTERNAL_DECL static __attribute__ ((unused)) +#define DUK_INTERNAL static __attribute__ ((unused)) +#else +#define DUK_INTERNAL_DECL static +#define DUK_INTERNAL static +#endif +#else +#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG) +#define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern +#define DUK_INTERNAL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) +#else +#define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) extern +#define DUK_INTERNAL __attribute__ ((visibility("hidden"))) +#endif +#endif +#define DUK_LOCAL_DECL static +#define DUK_LOCAL static +#endif + +#if defined(DUK_F_MINGW) +#if defined(DUK_F_CPP) +#define DUK_USE_COMPILER_STRING "mingw++" +#else +#define DUK_USE_COMPILER_STRING "mingw" +#endif +#else +#if defined(DUK_F_CPP) +#define DUK_USE_COMPILER_STRING "g++" +#else +#define DUK_USE_COMPILER_STRING "gcc" +#endif +#endif + +#undef DUK_USE_VARIADIC_MACROS +#if defined(DUK_F_C99) || (defined(DUK_F_CPP11) && defined(__GNUC__)) +#define DUK_USE_VARIADIC_MACROS +#endif + +#define DUK_USE_UNION_INITIALIZERS + +#undef DUK_USE_FLEX_C99 +#undef DUK_USE_FLEX_ZEROSIZE +#undef DUK_USE_FLEX_ONESIZE +#if defined(DUK_F_C99) +#define DUK_USE_FLEX_C99 +#else +#define DUK_USE_FLEX_ZEROSIZE +#endif + +#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40600) +#define DUK_USE_GCC_PRAGMAS +#else +#undef DUK_USE_GCC_PRAGMAS +#endif + +#define DUK_USE_PACK_GCC_ATTR +#elif defined(DUK_F_MSVC) +/* --- MSVC --- */ +/* http://msdn.microsoft.com/en-us/library/aa235362(VS.60).aspx */ +#define DUK_NORETURN(decl) __declspec(noreturn) decl + +/* XXX: DUK_UNREACHABLE for msvc? */ + +#undef DUK_USE_BRANCH_HINTS + +/* XXX: DUK_LIKELY, DUK_UNLIKELY for msvc? */ +/* XXX: DUK_NOINLINE, DUK_INLINE, DUK_ALWAYS_INLINE for msvc? */ + +#if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS) +/* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're + * compiling Duktape or the application. + */ +#if defined(DUK_COMPILING_DUKTAPE) +#define DUK_EXTERNAL_DECL extern __declspec(dllexport) +#define DUK_EXTERNAL __declspec(dllexport) +#else +#define DUK_EXTERNAL_DECL extern __declspec(dllimport) +#define DUK_EXTERNAL should_not_happen +#endif +#if defined(DUK_SINGLE_FILE) +#define DUK_INTERNAL_DECL static +#define DUK_INTERNAL static +#else +#define DUK_INTERNAL_DECL extern +#define DUK_INTERNAL /*empty*/ +#endif +#define DUK_LOCAL_DECL static +#define DUK_LOCAL static +#endif + +#if defined(DUK_F_CPP) +#define DUK_USE_COMPILER_STRING "msvc++" +#else +#define DUK_USE_COMPILER_STRING "msvc" +#endif + +#undef DUK_USE_VARIADIC_MACROS +#if defined(DUK_F_C99) +#define DUK_USE_VARIADIC_MACROS +#elif defined(_MSC_VER) && (_MSC_VER >= 1400) +/* VS2005+ should have variadic macros even when they're not C99. */ +#define DUK_USE_VARIADIC_MACROS +#endif + +#undef DUK_USE_UNION_INITIALIZERS +#if defined(_MSC_VER) && (_MSC_VER >= 1800) +/* VS2013+ supports union initializers but there's a bug involving union-inside-struct: + * https://connect.microsoft.com/VisualStudio/feedback/details/805981 + * The bug was fixed (at least) in VS2015 so check for VS2015 for now: + * https://blogs.msdn.microsoft.com/vcblog/2015/07/01/c-compiler-front-end-fixes-in-vs2015/ + * Manually tested using VS2013, CL reports 18.00.31101, so enable for VS2013 too. + */ +#define DUK_USE_UNION_INITIALIZERS +#endif + +#undef DUK_USE_FLEX_C99 +#undef DUK_USE_FLEX_ZEROSIZE +#undef DUK_USE_FLEX_ONESIZE +#if defined(DUK_F_C99) +#define DUK_USE_FLEX_C99 +#else +#define DUK_USE_FLEX_ZEROSIZE +#endif + +#undef DUK_USE_GCC_PRAGMAS + +#define DUK_USE_PACK_MSVC_PRAGMA + +/* These have been tested from VS2008 onwards; may work in older VS versions + * too but not enabled by default. + */ +#if defined(_MSC_VER) && (_MSC_VER >= 1500) +#define DUK_NOINLINE __declspec(noinline) +#define DUK_INLINE __inline +#define DUK_ALWAYS_INLINE __forceinline +#endif + +#if defined(_MSC_VER) && (_MSC_VER >= 1900) +#define DUK_SNPRINTF snprintf +#define DUK_VSNPRINTF vsnprintf +#else +/* (v)snprintf() is missing before MSVC 2015. Note that _(v)snprintf() does + * NOT NUL terminate on truncation, but Duktape code never assumes that. + * http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010 + */ +#define DUK_SNPRINTF _snprintf +#define DUK_VSNPRINTF _vsnprintf +#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)) + +#if defined(__clang__) && defined(__has_builtin) +#if __has_builtin(__builtin_unreachable) +#define DUK_UNREACHABLE() do { __builtin_unreachable(); } while (0) +#endif +#endif + +#define DUK_USE_BRANCH_HINTS +#define DUK_LIKELY(x) __builtin_expect((x), 1) +#define DUK_UNLIKELY(x) __builtin_expect((x), 0) +#if defined(__clang__) && defined(__has_builtin) +#if __has_builtin(__builtin_unpredictable) +#define DUK_UNPREDICTABLE(x) __builtin_unpredictable((x)) +#endif +#endif + +#if defined(DUK_F_C99) || defined(DUK_F_CPP11) +#define DUK_NOINLINE __attribute__((noinline)) +#define DUK_INLINE inline +#define DUK_ALWAYS_INLINE inline __attribute__((always_inline)) +#endif + +#define DUK_EXTERNAL_DECL __attribute__ ((visibility("default"))) extern +#define DUK_EXTERNAL __attribute__ ((visibility("default"))) +#if defined(DUK_SINGLE_FILE) +#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG) +/* Minimize warnings for unused internal functions with GCC >= 3.1.1 and + * Clang. Based on documentation it should suffice to have the attribute + * in the declaration only, but in practice some warnings are generated unless + * the attribute is also applied to the definition. + */ +#define DUK_INTERNAL_DECL static __attribute__ ((unused)) +#define DUK_INTERNAL static __attribute__ ((unused)) +#else +#define DUK_INTERNAL_DECL static +#define DUK_INTERNAL static +#endif +#else +#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG) +#define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern +#define DUK_INTERNAL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) +#else +#define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) extern +#define DUK_INTERNAL __attribute__ ((visibility("hidden"))) +#endif +#endif +#define DUK_LOCAL_DECL static +#define DUK_LOCAL static + +#define DUK_USE_COMPILER_STRING "emscripten" + +#undef DUK_USE_VARIADIC_MACROS +#if defined(DUK_F_C99) || defined(DUK_F_CPP11) +#define DUK_USE_VARIADIC_MACROS +#endif + +#define DUK_USE_UNION_INITIALIZERS + +#undef DUK_USE_FLEX_C99 +#undef DUK_USE_FLEX_ZEROSIZE +#undef DUK_USE_FLEX_ONESIZE +#if defined(DUK_F_C99) +#define DUK_USE_FLEX_C99 +#else +#define DUK_USE_FLEX_ZEROSIZE +#endif + +#undef DUK_USE_GCC_PRAGMAS +#define DUK_USE_PACK_CLANG_ATTR +#elif defined(DUK_F_TINYC) +/* --- TinyC --- */ +#undef DUK_USE_BRANCH_HINTS + +#if defined(DUK_F_CPP) +#define DUK_USE_COMPILER_STRING "tinyc++" +#else +#define DUK_USE_COMPILER_STRING "tinyc" +#endif + +/* http://bellard.org/tcc/tcc-doc.html#SEC7 */ +#define DUK_USE_VARIADIC_MACROS + +#define DUK_USE_UNION_INITIALIZERS + +/* Most portable, wastes space */ +#define DUK_USE_FLEX_ONESIZE + +/* Most portable, potentially wastes space */ +#define DUK_USE_PACK_DUMMY_MEMBER +#elif defined(DUK_F_VBCC) +/* --- VBCC --- */ +#undef DUK_USE_BRANCH_HINTS + +#if defined(DUK_F_CPP) +#define DUK_USE_COMPILER_STRING "vbcc-c++" +#else +#define DUK_USE_COMPILER_STRING "vbcc" +#endif + +#undef DUK_USE_VARIADIC_MACROS +#if defined(DUK_F_C99) || defined(DUK_F_CPP11) +#define DUK_USE_VARIADIC_MACROS +#endif + +/* VBCC supports C99 so check only for C99 for union initializer support. + * Designated union initializers would possibly work even without a C99 check. + */ +#undef DUK_USE_UNION_INITIALIZERS +#if defined(DUK_F_C99) +#define DUK_USE_UNION_INITIALIZERS +#endif + +#define DUK_USE_FLEX_ZEROSIZE +#define DUK_USE_PACK_DUMMY_MEMBER +#elif defined(DUK_F_BCC) +/* --- Bruce's C compiler --- */ +#undef DUK_USE_BRANCH_HINTS + +#if defined(DUK_F_CPP) +#define DUK_USE_COMPILER_STRING "bcc++" +#else +#define DUK_USE_COMPILER_STRING "bcc" +#endif + +/* Most portable */ +#undef DUK_USE_VARIADIC_MACROS + +/* Most portable, wastes space */ +#undef DUK_USE_UNION_INITIALIZERS + +/* Most portable, wastes space */ +#define DUK_USE_FLEX_ONESIZE + +/* Most portable, potentially wastes space */ +#define DUK_USE_PACK_DUMMY_MEMBER + +/* BCC, assume we're on x86. */ +#if !defined(DUK_USE_BYTEORDER) +#define DUK_USE_BYTEORDER 1 +#endif +#else +/* --- Generic --- */ +#undef DUK_USE_BRANCH_HINTS + +#if defined(DUK_F_CPP) +#define DUK_USE_COMPILER_STRING "generic-c++" +#else +#define DUK_USE_COMPILER_STRING "generic" +#endif + +#undef DUK_USE_VARIADIC_MACROS +#if defined(DUK_F_C99) || defined(DUK_F_CPP11) +#define DUK_USE_VARIADIC_MACROS +#endif + +/* C++ doesn't have standard designated union initializers ({ .foo = 1 }). */ +#undef DUK_USE_UNION_INITIALIZERS +#if defined(DUK_F_C99) +#define DUK_USE_UNION_INITIALIZERS +#endif + +/* Most portable, wastes space */ +#define DUK_USE_FLEX_ONESIZE + +/* Most portable, potentially wastes space */ +#define DUK_USE_PACK_DUMMY_MEMBER +#endif /* autodetect compiler */ + +/* uclibc */ +#if defined(__UCLIBC__) +#define DUK_F_UCLIBC +#endif + +/* + * Wrapper typedefs and constants for integer types, also sanity check types. + * + * C99 typedefs are quite good but not always available, and we want to avoid + * forcibly redefining the C99 typedefs. So, there are Duktape wrappers for + * all C99 typedefs and Duktape code should only use these typedefs. Type + * detection when C99 is not supported is best effort and may end up detecting + * some types incorrectly. + * + * Pointer sizes are a portability problem: pointers to different types may + * have a different size and function pointers are very difficult to manage + * portably. + * + * http://en.wikipedia.org/wiki/C_data_types#Fixed-width_integer_types + * + * Note: there's an interesting corner case when trying to define minimum + * signed integer value constants which leads to the current workaround of + * defining e.g. -0x80000000 as (-0x7fffffffL - 1L). See doc/code-issues.txt + * for a longer discussion. + * + * Note: avoid typecasts and computations in macro integer constants as they + * can then no longer be used in macro relational expressions (such as + * #if DUK_SIZE_MAX < 0xffffffffUL). There is internal code which relies on + * being able to compare DUK_SIZE_MAX against a limit. + */ + +/* XXX: add feature options to force basic types from outside? */ + +#if !defined(INT_MAX) +#error INT_MAX not defined +#endif + +/* Check that architecture is two's complement, standard C allows e.g. + * INT_MIN to be -2**31+1 (instead of -2**31). + */ +#if defined(INT_MAX) && defined(INT_MIN) +#if INT_MAX != -(INT_MIN + 1) +#error platform does not seem complement of two +#endif +#else +#error cannot check complement of two +#endif + +/* Pointer size determination based on __WORDSIZE or architecture when + * that's not available. + */ +#if defined(DUK_F_X86) || defined(DUK_F_X32) || \ + defined(DUK_F_M68K) || defined(DUK_F_PPC32) || \ + 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_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_ARM64) +#define DUK_F_64BIT_PTRS +#else +/* not sure, not needed with C99 anyway */ +#endif + +/* Intermediate define for 'have inttypes.h' */ +#undef DUK_F_HAVE_INTTYPES +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \ + !(defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC)) +/* vbcc + AmigaOS has C99 but no inttypes.h */ +#define DUK_F_HAVE_INTTYPES +#elif defined(__cplusplus) && (__cplusplus >= 201103L) +/* C++11 apparently ratified stdint.h */ +#define DUK_F_HAVE_INTTYPES +#endif + +/* Basic integer typedefs and limits, preferably from inttypes.h, otherwise + * through automatic detection. + */ +#if defined(DUK_F_HAVE_INTTYPES) +/* C99 or compatible */ + +#define DUK_F_HAVE_64BIT +#include + +typedef uint8_t duk_uint8_t; +typedef int8_t duk_int8_t; +typedef uint16_t duk_uint16_t; +typedef int16_t duk_int16_t; +typedef uint32_t duk_uint32_t; +typedef int32_t duk_int32_t; +typedef uint64_t duk_uint64_t; +typedef int64_t duk_int64_t; +typedef uint_least8_t duk_uint_least8_t; +typedef int_least8_t duk_int_least8_t; +typedef uint_least16_t duk_uint_least16_t; +typedef int_least16_t duk_int_least16_t; +typedef uint_least32_t duk_uint_least32_t; +typedef int_least32_t duk_int_least32_t; +typedef uint_least64_t duk_uint_least64_t; +typedef int_least64_t duk_int_least64_t; +typedef uint_fast8_t duk_uint_fast8_t; +typedef int_fast8_t duk_int_fast8_t; +typedef uint_fast16_t duk_uint_fast16_t; +typedef int_fast16_t duk_int_fast16_t; +typedef uint_fast32_t duk_uint_fast32_t; +typedef int_fast32_t duk_int_fast32_t; +typedef uint_fast64_t duk_uint_fast64_t; +typedef int_fast64_t duk_int_fast64_t; +typedef uintptr_t duk_uintptr_t; +typedef intptr_t duk_intptr_t; +typedef uintmax_t duk_uintmax_t; +typedef intmax_t duk_intmax_t; + +#define DUK_UINT8_MIN 0 +#define DUK_UINT8_MAX UINT8_MAX +#define DUK_INT8_MIN INT8_MIN +#define DUK_INT8_MAX INT8_MAX +#define DUK_UINT_LEAST8_MIN 0 +#define DUK_UINT_LEAST8_MAX UINT_LEAST8_MAX +#define DUK_INT_LEAST8_MIN INT_LEAST8_MIN +#define DUK_INT_LEAST8_MAX INT_LEAST8_MAX +#define DUK_UINT_FAST8_MIN 0 +#define DUK_UINT_FAST8_MAX UINT_FAST8_MAX +#define DUK_INT_FAST8_MIN INT_FAST8_MIN +#define DUK_INT_FAST8_MAX INT_FAST8_MAX +#define DUK_UINT16_MIN 0 +#define DUK_UINT16_MAX UINT16_MAX +#define DUK_INT16_MIN INT16_MIN +#define DUK_INT16_MAX INT16_MAX +#define DUK_UINT_LEAST16_MIN 0 +#define DUK_UINT_LEAST16_MAX UINT_LEAST16_MAX +#define DUK_INT_LEAST16_MIN INT_LEAST16_MIN +#define DUK_INT_LEAST16_MAX INT_LEAST16_MAX +#define DUK_UINT_FAST16_MIN 0 +#define DUK_UINT_FAST16_MAX UINT_FAST16_MAX +#define DUK_INT_FAST16_MIN INT_FAST16_MIN +#define DUK_INT_FAST16_MAX INT_FAST16_MAX +#define DUK_UINT32_MIN 0 +#define DUK_UINT32_MAX UINT32_MAX +#define DUK_INT32_MIN INT32_MIN +#define DUK_INT32_MAX INT32_MAX +#define DUK_UINT_LEAST32_MIN 0 +#define DUK_UINT_LEAST32_MAX UINT_LEAST32_MAX +#define DUK_INT_LEAST32_MIN INT_LEAST32_MIN +#define DUK_INT_LEAST32_MAX INT_LEAST32_MAX +#define DUK_UINT_FAST32_MIN 0 +#define DUK_UINT_FAST32_MAX UINT_FAST32_MAX +#define DUK_INT_FAST32_MIN INT_FAST32_MIN +#define DUK_INT_FAST32_MAX INT_FAST32_MAX +#define DUK_UINT64_MIN 0 +#define DUK_UINT64_MAX UINT64_MAX +#define DUK_INT64_MIN INT64_MIN +#define DUK_INT64_MAX INT64_MAX +#define DUK_UINT_LEAST64_MIN 0 +#define DUK_UINT_LEAST64_MAX UINT_LEAST64_MAX +#define DUK_INT_LEAST64_MIN INT_LEAST64_MIN +#define DUK_INT_LEAST64_MAX INT_LEAST64_MAX +#define DUK_UINT_FAST64_MIN 0 +#define DUK_UINT_FAST64_MAX UINT_FAST64_MAX +#define DUK_INT_FAST64_MIN INT_FAST64_MIN +#define DUK_INT_FAST64_MAX INT_FAST64_MAX + +#define DUK_UINTPTR_MIN 0 +#define DUK_UINTPTR_MAX UINTPTR_MAX +#define DUK_INTPTR_MIN INTPTR_MIN +#define DUK_INTPTR_MAX INTPTR_MAX + +#define DUK_UINTMAX_MIN 0 +#define DUK_UINTMAX_MAX UINTMAX_MAX +#define DUK_INTMAX_MIN INTMAX_MIN +#define DUK_INTMAX_MAX INTMAX_MAX + +#define DUK_SIZE_MIN 0 +#define DUK_SIZE_MAX SIZE_MAX +#undef DUK_SIZE_MAX_COMPUTED + +#else /* C99 types */ + +/* When C99 types are not available, we use heuristic detection to get + * the basic 8, 16, 32, and (possibly) 64 bit types. The fast/least + * types are then assumed to be exactly the same for now: these could + * be improved per platform but C99 types are very often now available. + * 64-bit types are not available on all platforms; this is OK at least + * on 32-bit platforms. + * + * This detection code is necessarily a bit hacky and can provide typedefs + * and defines that won't work correctly on some exotic platform. + */ + +#if (defined(CHAR_BIT) && (CHAR_BIT == 8)) || \ + (defined(UCHAR_MAX) && (UCHAR_MAX == 255)) +typedef unsigned char duk_uint8_t; +typedef signed char duk_int8_t; +#else +#error cannot detect 8-bit type +#endif + +#if defined(USHRT_MAX) && (USHRT_MAX == 65535UL) +typedef unsigned short duk_uint16_t; +typedef signed short duk_int16_t; +#elif defined(UINT_MAX) && (UINT_MAX == 65535UL) +/* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */ +typedef unsigned int duk_uint16_t; +typedef signed int duk_int16_t; +#else +#error cannot detect 16-bit type +#endif + +#if defined(UINT_MAX) && (UINT_MAX == 4294967295UL) +typedef unsigned int duk_uint32_t; +typedef signed int duk_int32_t; +#elif defined(ULONG_MAX) && (ULONG_MAX == 4294967295UL) +/* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */ +typedef unsigned long duk_uint32_t; +typedef signed long duk_int32_t; +#else +#error cannot detect 32-bit type +#endif + +/* 64-bit type detection is a bit tricky. + * + * ULLONG_MAX is a standard define. __LONG_LONG_MAX__ and __ULONG_LONG_MAX__ + * are used by at least GCC (even if system headers don't provide ULLONG_MAX). + * Some GCC variants may provide __LONG_LONG_MAX__ but not __ULONG_LONG_MAX__. + * + * ULL / LL constants are rejected / warned about by some compilers, even if + * the compiler has a 64-bit type and the compiler/system headers provide an + * unsupported constant (ULL/LL)! Try to avoid using ULL / LL constants. + * As a side effect we can only check that e.g. ULONG_MAX is larger than 32 + * bits but can't be sure it is exactly 64 bits. Self tests will catch such + * cases. + */ +#undef DUK_F_HAVE_64BIT +#if !defined(DUK_F_HAVE_64BIT) && defined(ULONG_MAX) +#if (ULONG_MAX > 4294967295UL) +#define DUK_F_HAVE_64BIT +typedef unsigned long duk_uint64_t; +typedef signed long duk_int64_t; +#endif +#endif +#if !defined(DUK_F_HAVE_64BIT) && defined(ULLONG_MAX) +#if (ULLONG_MAX > 4294967295UL) +#define DUK_F_HAVE_64BIT +typedef unsigned long long duk_uint64_t; +typedef signed long long duk_int64_t; +#endif +#endif +#if !defined(DUK_F_HAVE_64BIT) && defined(__ULONG_LONG_MAX__) +#if (__ULONG_LONG_MAX__ > 4294967295UL) +#define DUK_F_HAVE_64BIT +typedef unsigned long long duk_uint64_t; +typedef signed long long duk_int64_t; +#endif +#endif +#if !defined(DUK_F_HAVE_64BIT) && defined(__LONG_LONG_MAX__) +#if (__LONG_LONG_MAX__ > 2147483647L) +#define DUK_F_HAVE_64BIT +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) +#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 + +typedef duk_uint8_t duk_uint_least8_t; +typedef duk_int8_t duk_int_least8_t; +typedef duk_uint16_t duk_uint_least16_t; +typedef duk_int16_t duk_int_least16_t; +typedef duk_uint32_t duk_uint_least32_t; +typedef duk_int32_t duk_int_least32_t; +typedef duk_uint8_t duk_uint_fast8_t; +typedef duk_int8_t duk_int_fast8_t; +typedef duk_uint16_t duk_uint_fast16_t; +typedef duk_int16_t duk_int_fast16_t; +typedef duk_uint32_t duk_uint_fast32_t; +typedef duk_int32_t duk_int_fast32_t; +#if defined(DUK_F_HAVE_64BIT) +typedef duk_uint64_t duk_uint_least64_t; +typedef duk_int64_t duk_int_least64_t; +typedef duk_uint64_t duk_uint_fast64_t; +typedef duk_int64_t duk_int_fast64_t; +#endif +#if defined(DUK_F_HAVE_64BIT) +typedef duk_uint64_t duk_uintmax_t; +typedef duk_int64_t duk_intmax_t; +#else +typedef duk_uint32_t duk_uintmax_t; +typedef duk_int32_t duk_intmax_t; +#endif + +/* Note: the funny looking computations for signed minimum 16-bit, 32-bit, and + * 64-bit values are intentional as the obvious forms (e.g. -0x80000000L) are + * -not- portable. See code-issues.txt for a detailed discussion. + */ +#define DUK_UINT8_MIN 0UL +#define DUK_UINT8_MAX 0xffUL +#define DUK_INT8_MIN (-0x80L) +#define DUK_INT8_MAX 0x7fL +#define DUK_UINT_LEAST8_MIN 0UL +#define DUK_UINT_LEAST8_MAX 0xffUL +#define DUK_INT_LEAST8_MIN (-0x80L) +#define DUK_INT_LEAST8_MAX 0x7fL +#define DUK_UINT_FAST8_MIN 0UL +#define DUK_UINT_FAST8_MAX 0xffUL +#define DUK_INT_FAST8_MIN (-0x80L) +#define DUK_INT_FAST8_MAX 0x7fL +#define DUK_UINT16_MIN 0UL +#define DUK_UINT16_MAX 0xffffUL +#define DUK_INT16_MIN (-0x7fffL - 1L) +#define DUK_INT16_MAX 0x7fffL +#define DUK_UINT_LEAST16_MIN 0UL +#define DUK_UINT_LEAST16_MAX 0xffffUL +#define DUK_INT_LEAST16_MIN (-0x7fffL - 1L) +#define DUK_INT_LEAST16_MAX 0x7fffL +#define DUK_UINT_FAST16_MIN 0UL +#define DUK_UINT_FAST16_MAX 0xffffUL +#define DUK_INT_FAST16_MIN (-0x7fffL - 1L) +#define DUK_INT_FAST16_MAX 0x7fffL +#define DUK_UINT32_MIN 0UL +#define DUK_UINT32_MAX 0xffffffffUL +#define DUK_INT32_MIN (-0x7fffffffL - 1L) +#define DUK_INT32_MAX 0x7fffffffL +#define DUK_UINT_LEAST32_MIN 0UL +#define DUK_UINT_LEAST32_MAX 0xffffffffUL +#define DUK_INT_LEAST32_MIN (-0x7fffffffL - 1L) +#define DUK_INT_LEAST32_MAX 0x7fffffffL +#define DUK_UINT_FAST32_MIN 0UL +#define DUK_UINT_FAST32_MAX 0xffffffffUL +#define DUK_INT_FAST32_MIN (-0x7fffffffL - 1L) +#define DUK_INT_FAST32_MAX 0x7fffffffL + +/* 64-bit constants. Since LL / ULL constants are not always available, + * use computed values. These values can't be used in preprocessor + * comparisons; flag them as such. + */ +#if defined(DUK_F_HAVE_64BIT) +#define DUK_UINT64_MIN ((duk_uint64_t) 0) +#define DUK_UINT64_MAX ((duk_uint64_t) -1) +#define DUK_INT64_MIN ((duk_int64_t) (~(DUK_UINT64_MAX >> 1))) +#define DUK_INT64_MAX ((duk_int64_t) (DUK_UINT64_MAX >> 1)) +#define DUK_UINT_LEAST64_MIN DUK_UINT64_MIN +#define DUK_UINT_LEAST64_MAX DUK_UINT64_MAX +#define DUK_INT_LEAST64_MIN DUK_INT64_MIN +#define DUK_INT_LEAST64_MAX DUK_INT64_MAX +#define DUK_UINT_FAST64_MIN DUK_UINT64_MIN +#define DUK_UINT_FAST64_MAX DUK_UINT64_MAX +#define DUK_INT_FAST64_MIN DUK_INT64_MIN +#define DUK_INT_FAST64_MAX DUK_INT64_MAX +#define DUK_UINT64_MIN_COMPUTED +#define DUK_UINT64_MAX_COMPUTED +#define DUK_INT64_MIN_COMPUTED +#define DUK_INT64_MAX_COMPUTED +#define DUK_UINT_LEAST64_MIN_COMPUTED +#define DUK_UINT_LEAST64_MAX_COMPUTED +#define DUK_INT_LEAST64_MIN_COMPUTED +#define DUK_INT_LEAST64_MAX_COMPUTED +#define DUK_UINT_FAST64_MIN_COMPUTED +#define DUK_UINT_FAST64_MAX_COMPUTED +#define DUK_INT_FAST64_MIN_COMPUTED +#define DUK_INT_FAST64_MAX_COMPUTED +#endif + +#if defined(DUK_F_HAVE_64BIT) +#define DUK_UINTMAX_MIN DUK_UINT64_MIN +#define DUK_UINTMAX_MAX DUK_UINT64_MAX +#define DUK_INTMAX_MIN DUK_INT64_MIN +#define DUK_INTMAX_MAX DUK_INT64_MAX +#define DUK_UINTMAX_MIN_COMPUTED +#define DUK_UINTMAX_MAX_COMPUTED +#define DUK_INTMAX_MIN_COMPUTED +#define DUK_INTMAX_MAX_COMPUTED +#else +#define DUK_UINTMAX_MIN 0UL +#define DUK_UINTMAX_MAX 0xffffffffUL +#define DUK_INTMAX_MIN (-0x7fffffffL - 1L) +#define DUK_INTMAX_MAX 0x7fffffffL +#endif + +/* This detection is not very reliable. */ +#if defined(DUK_F_32BIT_PTRS) +typedef duk_int32_t duk_intptr_t; +typedef duk_uint32_t duk_uintptr_t; +#define DUK_UINTPTR_MIN DUK_UINT32_MIN +#define DUK_UINTPTR_MAX DUK_UINT32_MAX +#define DUK_INTPTR_MIN DUK_INT32_MIN +#define DUK_INTPTR_MAX DUK_INT32_MAX +#elif defined(DUK_F_64BIT_PTRS) && defined(DUK_F_HAVE_64BIT) +typedef duk_int64_t duk_intptr_t; +typedef duk_uint64_t duk_uintptr_t; +#define DUK_UINTPTR_MIN DUK_UINT64_MIN +#define DUK_UINTPTR_MAX DUK_UINT64_MAX +#define DUK_INTPTR_MIN DUK_INT64_MIN +#define DUK_INTPTR_MAX DUK_INT64_MAX +#define DUK_UINTPTR_MIN_COMPUTED +#define DUK_UINTPTR_MAX_COMPUTED +#define DUK_INTPTR_MIN_COMPUTED +#define DUK_INTPTR_MAX_COMPUTED +#else +#error cannot determine intptr type +#endif + +/* SIZE_MAX may be missing so use an approximate value for it. */ +#undef DUK_SIZE_MAX_COMPUTED +#if !defined(SIZE_MAX) +#define DUK_SIZE_MAX_COMPUTED +#define SIZE_MAX ((size_t) (-1)) +#endif +#define DUK_SIZE_MIN 0 +#define DUK_SIZE_MAX SIZE_MAX + +#endif /* C99 types */ + +/* A few types are assumed to always exist. */ +typedef size_t duk_size_t; +typedef ptrdiff_t duk_ptrdiff_t; + +/* The best type for an "all around int" in Duktape internals is "at least + * 32 bit signed integer" which is most convenient. Same for unsigned type. + * Prefer 'int' when large enough, as it is almost always a convenient type. + */ +#if defined(UINT_MAX) && (UINT_MAX >= 0xffffffffUL) +typedef int duk_int_t; +typedef unsigned int duk_uint_t; +#define DUK_INT_MIN INT_MIN +#define DUK_INT_MAX INT_MAX +#define DUK_UINT_MIN 0 +#define DUK_UINT_MAX UINT_MAX +#else +typedef duk_int_fast32_t duk_int_t; +typedef duk_uint_fast32_t duk_uint_t; +#define DUK_INT_MIN DUK_INT_FAST32_MIN +#define DUK_INT_MAX DUK_INT_FAST32_MAX +#define DUK_UINT_MIN DUK_UINT_FAST32_MIN +#define DUK_UINT_MAX DUK_UINT_FAST32_MAX +#endif + +/* Same as 'duk_int_t' but guaranteed to be a 'fast' variant if this + * distinction matters for the CPU. These types are used mainly in the + * executor where it might really matter. + */ +typedef duk_int_fast32_t duk_int_fast_t; +typedef duk_uint_fast32_t duk_uint_fast_t; +#define DUK_INT_FAST_MIN DUK_INT_FAST32_MIN +#define DUK_INT_FAST_MAX DUK_INT_FAST32_MAX +#define DUK_UINT_FAST_MIN DUK_UINT_FAST32_MIN +#define DUK_UINT_FAST_MAX DUK_UINT_FAST32_MAX + +/* Small integers (16 bits or more) can fall back to the 'int' type, but + * have a typedef so they are marked "small" explicitly. + */ +typedef int duk_small_int_t; +typedef unsigned int duk_small_uint_t; +#define DUK_SMALL_INT_MIN INT_MIN +#define DUK_SMALL_INT_MAX INT_MAX +#define DUK_SMALL_UINT_MIN 0 +#define DUK_SMALL_UINT_MAX UINT_MAX + +/* Fast variants of small integers, again for really fast paths like the + * executor. + */ +typedef duk_int_fast16_t duk_small_int_fast_t; +typedef duk_uint_fast16_t duk_small_uint_fast_t; +#define DUK_SMALL_INT_FAST_MIN DUK_INT_FAST16_MIN +#define DUK_SMALL_INT_FAST_MAX DUK_INT_FAST16_MAX +#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 '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 + +/* Index values must have at least 32-bit signed range. */ +typedef duk_int_t duk_idx_t; +#define DUK_IDX_MIN DUK_INT_MIN +#define DUK_IDX_MAX DUK_INT_MAX + +/* Unsigned index variant. */ +typedef duk_uint_t duk_uidx_t; +#define DUK_UIDX_MIN DUK_UINT_MIN +#define DUK_UIDX_MAX DUK_UINT_MAX + +/* Array index values, could be exact 32 bits. + * Currently no need for signed duk_arridx_t. + */ +typedef duk_uint_t duk_uarridx_t; +#define DUK_UARRIDX_MIN DUK_UINT_MIN +#define DUK_UARRIDX_MAX DUK_UINT_MAX + +/* Duktape/C function return value, platform int is enough for now to + * represent 0, 1, or negative error code. Must be compatible with + * assigning truth values (e.g. duk_ret_t rc = (foo == bar);). + */ +typedef duk_small_int_t duk_ret_t; +#define DUK_RET_MIN DUK_SMALL_INT_MIN +#define DUK_RET_MAX DUK_SMALL_INT_MAX + +/* Error codes are represented with platform int. High bits are used + * for flags and such, so 32 bits are needed. + */ +typedef duk_int_t duk_errcode_t; +#define DUK_ERRCODE_MIN DUK_INT_MIN +#define DUK_ERRCODE_MAX DUK_INT_MAX + +/* Codepoint type. Must be 32 bits or more because it is used also for + * internal codepoints. The type is signed because negative codepoints + * are used as internal markers (e.g. to mark EOF or missing argument). + * (X)UTF-8/CESU-8 encode/decode take and return an unsigned variant to + * ensure duk_uint32_t casts back and forth nicely. Almost everything + * else uses the signed one. + */ +typedef duk_int_t duk_codepoint_t; +typedef duk_uint_t duk_ucodepoint_t; +#define DUK_CODEPOINT_MIN DUK_INT_MIN +#define DUK_CODEPOINT_MAX DUK_INT_MAX +#define DUK_UCODEPOINT_MIN DUK_UINT_MIN +#define DUK_UCODEPOINT_MAX DUK_UINT_MAX + +/* IEEE float/double typedef. */ +typedef float duk_float_t; +typedef double duk_double_t; + +/* We're generally assuming that we're working on a platform with a 32-bit + * address space. If DUK_SIZE_MAX is a typecast value (which is necessary + * if SIZE_MAX is missing), the check must be avoided because the + * preprocessor can't do a comparison. + */ +#if !defined(DUK_SIZE_MAX) +#error DUK_SIZE_MAX is undefined, probably missing SIZE_MAX +#elif !defined(DUK_SIZE_MAX_COMPUTED) +#if DUK_SIZE_MAX < 0xffffffffUL +/* On some systems SIZE_MAX can be smaller than max unsigned 32-bit value + * which seems incorrect if size_t is (at least) an unsigned 32-bit type. + * However, it doesn't seem useful to error out compilation if this is the + * case. + */ +#endif +#endif + +/* 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. + * + * Quite incomplete now. Use 64-bit types if detected (C99 or other detection) + * unless they are known to be unreliable. For instance, 64-bit types are + * available on VBCC but seem to misbehave. + */ +#if defined(DUK_F_HAVE_64BIT) && !defined(DUK_F_VBCC) +#define DUK_USE_64BIT_OPS +#else +#undef DUK_USE_64BIT_OPS +#endif + +/* + * Fill-ins for platform, architecture, and compiler + */ + +/* An abort()-like primitive is needed by the default fatal error handler. */ +#if !defined(DUK_ABORT) +#define DUK_ABORT abort +#endif + +#if !defined(DUK_SETJMP) +#define DUK_JMPBUF_TYPE jmp_buf +#define DUK_SETJMP(jb) setjmp((jb)) +#define DUK_LONGJMP(jb) longjmp((jb), 1) +#endif + +#if 0 +/* sigsetjmp() alternative */ +#define DUK_JMPBUF_TYPE sigjmp_buf +#define DUK_SETJMP(jb) sigsetjmp((jb)) +#define DUK_LONGJMP(jb) siglongjmp((jb), 1) +#endif + +/* Special naming to avoid conflict with e.g. DUK_FREE() in duk_heap.h + * (which is unfortunately named). May sometimes need replacement, e.g. + * some compilers don't handle zero length or NULL correctly in realloc(). + */ +#if !defined(DUK_ANSI_MALLOC) +#define DUK_ANSI_MALLOC malloc +#endif +#if !defined(DUK_ANSI_REALLOC) +#define DUK_ANSI_REALLOC realloc +#endif +#if !defined(DUK_ANSI_CALLOC) +#define DUK_ANSI_CALLOC calloc +#endif +#if !defined(DUK_ANSI_FREE) +#define DUK_ANSI_FREE free +#endif + +/* ANSI C (various versions) and some implementations require that the + * pointer arguments to memset(), memcpy(), and memmove() be valid values + * even when byte size is 0 (even a NULL pointer is considered invalid in + * this context). Zero-size operations as such are allowed, as long as their + * pointer arguments point to a valid memory area. The DUK_MEMSET(), + * DUK_MEMCPY(), and DUK_MEMMOVE() macros require this same behavior, i.e.: + * (1) pointers must be valid and non-NULL, (2) zero size must otherwise be + * allowed. If these are not fulfilled, a macro wrapper is needed. + * + * http://stackoverflow.com/questions/5243012/is-it-guaranteed-to-be-safe-to-perform-memcpy0-0-0 + * http://lists.cs.uiuc.edu/pipermail/llvmdev/2007-October/011065.html + * + * Not sure what's the required behavior when a pointer points just past the + * end of a buffer, which often happens in practice (e.g. zero size memmoves). + * For example, if allocation size is 3, the following pointer would not + * technically point to a valid memory byte: + * + * <-- alloc --> + * | 0 | 1 | 2 | ..... + * ^-- p=3, points after last valid byte (2) + */ +#if !defined(DUK_MEMCPY) +#if defined(DUK_F_UCLIBC) +/* Old uclibcs have a broken memcpy so use memmove instead (this is overly wide + * now on purpose): http://lists.uclibc.org/pipermail/uclibc-cvs/2008-October/025511.html + */ +#define DUK_MEMCPY memmove +#else +#define DUK_MEMCPY memcpy +#endif +#endif +#if !defined(DUK_MEMMOVE) +#define DUK_MEMMOVE memmove +#endif +#if !defined(DUK_MEMCMP) +#define DUK_MEMCMP memcmp +#endif +#if !defined(DUK_MEMSET) +#define DUK_MEMSET memset +#endif +#if !defined(DUK_STRLEN) +#define DUK_STRLEN strlen +#endif +#if !defined(DUK_STRCMP) +#define DUK_STRCMP strcmp +#endif +#if !defined(DUK_STRNCMP) +#define DUK_STRNCMP strncmp +#endif +#if !defined(DUK_SPRINTF) +#define DUK_SPRINTF sprintf +#endif +#if !defined(DUK_SNPRINTF) +/* snprintf() is technically not part of C89 but usually available. */ +#define DUK_SNPRINTF snprintf +#endif +#if !defined(DUK_VSPRINTF) +#define DUK_VSPRINTF vsprintf +#endif +#if !defined(DUK_VSNPRINTF) +/* vsnprintf() is technically not part of C89 but usually available. */ +#define DUK_VSNPRINTF vsnprintf +#endif +#if !defined(DUK_SSCANF) +#define DUK_SSCANF sscanf +#endif +#if !defined(DUK_VSSCANF) +#define DUK_VSSCANF vsscanf +#endif +#if !defined(DUK_MEMZERO) +#define DUK_MEMZERO(p,n) DUK_MEMSET((p), 0, (n)) +#endif + +#if !defined(DUK_DOUBLE_INFINITY) +#undef DUK_USE_COMPUTED_INFINITY +#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION < 40600) +/* GCC older than 4.6: avoid overflow warnings related to using INFINITY */ +#define DUK_DOUBLE_INFINITY (__builtin_inf()) +#elif defined(INFINITY) +#define DUK_DOUBLE_INFINITY ((double) INFINITY) +#elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC) && \ + !defined(DUK_F_OLD_SOLARIS) && !defined(DUK_F_AIX) +#define DUK_DOUBLE_INFINITY (1.0 / 0.0) +#else +/* In VBCC (1.0 / 0.0) results in a warning and 0.0 instead of infinity. + * Use a computed infinity (initialized when a heap is created at the + * latest). + */ +#define DUK_USE_COMPUTED_INFINITY +#define DUK_DOUBLE_INFINITY duk_computed_infinity +#endif +#endif + +#if !defined(DUK_DOUBLE_NAN) +#undef DUK_USE_COMPUTED_NAN +#if defined(NAN) +#define DUK_DOUBLE_NAN NAN +#elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC) && \ + !defined(DUK_F_OLD_SOLARIS) && !defined(DUK_F_AIX) +#define DUK_DOUBLE_NAN (0.0 / 0.0) +#else +/* In VBCC (0.0 / 0.0) results in a warning and 0.0 instead of NaN. + * In MSVC (VS2010 Express) (0.0 / 0.0) results in a compile error. + * Use a computed NaN (initialized when a heap is created at the + * latest). + */ +#define DUK_USE_COMPUTED_NAN +#define DUK_DOUBLE_NAN duk_computed_nan +#endif +#endif + +/* Many platforms are missing fpclassify() and friends, so use replacements + * if necessary. The replacement constants (FP_NAN etc) can be anything but + * match Linux constants now. + */ +#undef DUK_USE_REPL_FPCLASSIFY +#undef DUK_USE_REPL_SIGNBIT +#undef DUK_USE_REPL_ISFINITE +#undef DUK_USE_REPL_ISNAN +#undef DUK_USE_REPL_ISINF + +/* Complex condition broken into separate parts. */ +#undef DUK_F_USE_REPL_ALL +#if !(defined(FP_NAN) && defined(FP_INFINITE) && defined(FP_ZERO) && \ + defined(FP_SUBNORMAL) && defined(FP_NORMAL)) +/* Missing some obvious constants. */ +#define DUK_F_USE_REPL_ALL +#elif defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC) +/* VBCC is missing the built-ins even in C99 mode (perhaps a header issue). */ +#define DUK_F_USE_REPL_ALL +#elif defined(DUK_F_AMIGAOS) && defined(DUK_F_M68K) +/* AmigaOS + M68K seems to have math issues even when using GCC cross + * compilation. Use replacements for all AmigaOS versions on M68K + * regardless of compiler. + */ +#define DUK_F_USE_REPL_ALL +#elif defined(DUK_F_FREEBSD) && defined(DUK_F_CLANG) +/* Placeholder fix for (detection is wider than necessary): + * http://llvm.org/bugs/show_bug.cgi?id=17788 + */ +#define DUK_F_USE_REPL_ALL +#elif defined(DUK_F_UCLIBC) +/* At least some uclibc versions have broken floating point math. For + * example, fpclassify() can incorrectly classify certain NaN formats. + * To be safe, use replacements. + */ +#define DUK_F_USE_REPL_ALL +#elif defined(DUK_F_AIX) +/* Older versions may be missing isnan(), etc. */ +#define DUK_F_USE_REPL_ALL +#endif + +#if defined(DUK_F_USE_REPL_ALL) +#define DUK_USE_REPL_FPCLASSIFY +#define DUK_USE_REPL_SIGNBIT +#define DUK_USE_REPL_ISFINITE +#define DUK_USE_REPL_ISNAN +#define DUK_USE_REPL_ISINF +#define DUK_FPCLASSIFY duk_repl_fpclassify +#define DUK_SIGNBIT duk_repl_signbit +#define DUK_ISFINITE duk_repl_isfinite +#define DUK_ISNAN duk_repl_isnan +#define DUK_ISINF duk_repl_isinf +#define DUK_FP_NAN 0 +#define DUK_FP_INFINITE 1 +#define DUK_FP_ZERO 2 +#define DUK_FP_SUBNORMAL 3 +#define DUK_FP_NORMAL 4 +#else +#define DUK_FPCLASSIFY fpclassify +#define DUK_SIGNBIT signbit +#define DUK_ISFINITE isfinite +#define DUK_ISNAN isnan +#define DUK_ISINF isinf +#define DUK_FP_NAN FP_NAN +#define DUK_FP_INFINITE FP_INFINITE +#define DUK_FP_ZERO FP_ZERO +#define DUK_FP_SUBNORMAL FP_SUBNORMAL +#define DUK_FP_NORMAL FP_NORMAL +#endif + +#if defined(DUK_F_USE_REPL_ALL) +#undef DUK_F_USE_REPL_ALL +#endif + +/* These functions don't currently need replacement but are wrapped for + * completeness. Because these are used as function pointers, they need + * to be defined as concrete C functions (not macros). + */ +#if !defined(DUK_FABS) +#define DUK_FABS fabs +#endif +#if !defined(DUK_FLOOR) +#define DUK_FLOOR floor +#endif +#if !defined(DUK_CEIL) +#define DUK_CEIL ceil +#endif +#if !defined(DUK_FMOD) +#define DUK_FMOD fmod +#endif +#if !defined(DUK_POW) +#define DUK_POW pow +#endif +#if !defined(DUK_ACOS) +#define DUK_ACOS acos +#endif +#if !defined(DUK_ASIN) +#define DUK_ASIN asin +#endif +#if !defined(DUK_ATAN) +#define DUK_ATAN atan +#endif +#if !defined(DUK_ATAN2) +#define DUK_ATAN2 atan2 +#endif +#if !defined(DUK_SIN) +#define DUK_SIN sin +#endif +#if !defined(DUK_COS) +#define DUK_COS cos +#endif +#if !defined(DUK_TAN) +#define DUK_TAN tan +#endif +#if !defined(DUK_EXP) +#define DUK_EXP exp +#endif +#if !defined(DUK_LOG) +#define DUK_LOG log +#endif +#if !defined(DUK_SQRT) +#define DUK_SQRT sqrt +#endif + +/* The functions below exist only in C99/C++11 or later and need a workaround + * for platforms that don't include them. MSVC isn't detected as C99, but + * these functions also exist in MSVC 2013 and later so include a clause for + * that too. Android doesn't have log2; disable all of these for Android. + */ +#if (defined(DUK_F_C99) || defined(DUK_F_CPP11) || (defined(_MSC_VER) && (_MSC_VER >= 1800))) && \ + !defined(DUK_F_ANDROID) && !defined(DUK_F_MINT) +#if !defined(DUK_CBRT) +#define DUK_CBRT cbrt +#endif +#if !defined(DUK_LOG2) +#define DUK_LOG2 log2 +#endif +#if !defined(DUK_LOG10) +#define DUK_LOG10 log10 +#endif +#if !defined(DUK_TRUNC) +#define DUK_TRUNC trunc +#endif +#endif /* DUK_F_C99 etc */ + +/* NetBSD 6.0 x86 (at least) has a few problems with pow() semantics, + * see test-bug-netbsd-math-pow.js. MinGW has similar (but different) + * issues, see test-bug-mingw-math-issues.js. Enable pow() workarounds + * for these targets. + */ +#undef DUK_USE_POW_WORKAROUNDS +#if defined(DUK_F_NETBSD) || defined(DUK_F_MINGW) +#define DUK_USE_POW_WORKAROUNDS +#endif + +/* Similar workarounds for atan2() semantics issues. MinGW issues are + * documented in test-bug-mingw-math-issues.js. + */ +#undef DUK_USE_ATAN2_WORKAROUNDS +#if defined(DUK_F_MINGW) +#define DUK_USE_ATAN2_WORKAROUNDS +#endif + +/* Rely as little as possible on compiler behavior for NaN comparison, + * signed zero handling, etc. Currently never activated but may be needed + * for broken compilers. + */ +#undef DUK_USE_PARANOID_MATH + +/* There was a curious bug where test-bi-date-canceling.js would fail e.g. + * on 64-bit Ubuntu, gcc-4.8.1, -m32, and no -std=c99. Some date computations + * using doubles would be optimized which then broke some corner case tests. + * The problem goes away by adding 'volatile' to the datetime computations. + * Not sure what the actual triggering conditions are, but using this on + * non-C99 systems solves the known issues and has relatively little cost + * on other platforms. + */ +#undef DUK_USE_PARANOID_DATE_COMPUTATION +#if !defined(DUK_F_C99) +#define DUK_USE_PARANOID_DATE_COMPUTATION +#endif + +/* + * Byte order and double memory layout detection + * + * Endianness detection is a major portability hassle because the macros + * and headers are not standardized. There's even variance across UNIX + * platforms. Even with "standard" headers, details like underscore count + * varies between platforms, e.g. both __BYTE_ORDER and _BYTE_ORDER are used + * (Crossbridge has a single underscore, for instance). + * + * The checks below are structured with this in mind: several approaches are + * used, and at the end we check if any of them worked. This allows generic + * approaches to be tried first, and platform/compiler specific hacks tried + * last. As a last resort, the user can force a specific endianness, as it's + * not likely that automatic detection will work on the most exotic platforms. + * + * Duktape supports little and big endian machines. There's also support + * for a hybrid used by some ARM machines where integers are little endian + * but IEEE double values use a mixed order (12345678 -> 43218765). This + * byte order for doubles is referred to as "mixed endian". + */ + +/* GCC and Clang provide endianness defines as built-in predefines, with + * leading and trailing double underscores (e.g. __BYTE_ORDER__). See + * output of "make gccpredefs" and "make clangpredefs". Clang doesn't + * seem to provide __FLOAT_WORD_ORDER__; assume not mixed endian for clang. + * http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html + */ +#if !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__) +#if defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) +#if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__) +#define DUK_USE_BYTEORDER 1 +#elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__) +#define DUK_USE_BYTEORDER 2 +#elif !defined(__FLOAT_WORD_ORDER__) +/* Float word order not known, assume not a hybrid. */ +#define DUK_USE_BYTEORDER 1 +#else +/* Byte order is little endian but cannot determine IEEE double word order. */ +#endif /* float word order */ +#elif defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) +#if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__) +#define DUK_USE_BYTEORDER 3 +#elif !defined(__FLOAT_WORD_ORDER__) +/* Float word order not known, assume not a hybrid. */ +#define DUK_USE_BYTEORDER 3 +#else +/* Byte order is big endian but cannot determine IEEE double word order. */ +#endif /* float word order */ +#else +/* Cannot determine byte order; __ORDER_PDP_ENDIAN__ is related to 32-bit + * integer ordering and is not relevant. + */ +#endif /* integer byte order */ +#endif /* !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__) */ + +/* More or less standard endianness predefines provided by header files. + * The ARM hybrid case is detected by assuming that __FLOAT_WORD_ORDER + * will be big endian, see: http://lists.mysql.com/internals/443. + * On some platforms some defines may be present with an empty value which + * causes comparisons to fail: https://github.com/svaarala/duktape/issues/453. + */ +#if !defined(DUK_USE_BYTEORDER) +#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && (__BYTE_ORDER == __LITTLE_ENDIAN) || \ + defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && (_BYTE_ORDER == _LITTLE_ENDIAN) || \ + defined(__LITTLE_ENDIAN__) +#if defined(__FLOAT_WORD_ORDER) && defined(__LITTLE_ENDIAN) && (__FLOAT_WORD_ORDER == __LITTLE_ENDIAN) || \ + defined(_FLOAT_WORD_ORDER) && defined(_LITTLE_ENDIAN) && (_FLOAT_WORD_ORDER == _LITTLE_ENDIAN) +#define DUK_USE_BYTEORDER 1 +#elif defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \ + defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN) +#define DUK_USE_BYTEORDER 2 +#elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER) +/* Float word order not known, assume not a hybrid. */ +#define DUK_USE_BYTEORDER 1 +#else +/* Byte order is little endian but cannot determine IEEE double word order. */ +#endif /* float word order */ +#elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN) || \ + defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && (_BYTE_ORDER == _BIG_ENDIAN) || \ + defined(__BIG_ENDIAN__) +#if defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \ + defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN) +#define DUK_USE_BYTEORDER 3 +#elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER) +/* Float word order not known, assume not a hybrid. */ +#define DUK_USE_BYTEORDER 3 +#else +/* Byte order is big endian but cannot determine IEEE double word order. */ +#endif /* float word order */ +#else +/* Cannot determine byte order. */ +#endif /* integer byte order */ +#endif /* !defined(DUK_USE_BYTEORDER) */ + +/* QNX gcc cross compiler seems to define e.g. __LITTLEENDIAN__ or __BIGENDIAN__: + * $ /opt/qnx650/host/linux/x86/usr/bin/i486-pc-nto-qnx6.5.0-gcc -dM -E - > 24) | \ + ((((duk_uint32_t) (x)) >> 8) & 0xff00UL) | \ + ((((duk_uint32_t) (x)) << 8) & 0xff0000UL) | \ + (((duk_uint32_t) (x)) << 24)) +#endif +#if !defined(DUK_BSWAP16) +#define DUK_BSWAP16(x) \ + ((duk_uint16_t) (x) >> 8) | \ + ((duk_uint16_t) (x) << 8) +#endif + +/* DUK_USE_VARIADIC_MACROS: required from compilers, so no fill-in. */ +/* DUK_USE_UNION_INITIALIZERS: required from compilers, so no fill-in. */ + +#if !(defined(DUK_USE_FLEX_C99) || defined(DUK_USE_FLEX_ZEROSIZE) || defined(DUK_USE_FLEX_ONESIZE)) +#if defined(DUK_F_C99) +#define DUK_USE_FLEX_C99 +#else +#define DUK_USE_FLEX_ZEROSIZE /* Not standard but common enough */ +#endif +#endif + +#if !(defined(DUK_USE_PACK_GCC_ATTR) || defined(DUK_USE_PACK_CLANG_ATTR) || \ + defined(DUK_USE_PACK_MSVC_PRAGMA) || defined(DUK_USE_PACK_DUMMY_MEMBER)) +#define DUK_USE_PACK_DUMMY_MEMBER +#endif + +#if 0 /* not defined by default */ +#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. + */ +#if !defined(DUK_SINGLE_FILE) +#undef DUK_NOINLINE +#undef DUK_INLINE +#undef DUK_ALWAYS_INLINE +#define DUK_NOINLINE /*nop*/ +#define DUK_INLINE /*nop*/ +#define DUK_ALWAYS_INLINE /*nop*/ +#endif + +/* + * Check whether or not a packed duk_tval representation is possible. + * What's basically required is that pointers are 32-bit values + * (sizeof(void *) == 4). Best effort check, not always accurate. + * If guess goes wrong, crashes may result; self tests also verify + * the guess. + */ + +/* Explicit marker needed; may be 'defined', 'undefined, 'or 'not provided'. */ +#if !defined(DUK_F_PACKED_TVAL_PROVIDED) +#undef DUK_F_PACKED_TVAL_POSSIBLE + +/* Strict C99 case: DUK_UINTPTR_MAX (= UINTPTR_MAX) should be very reliable */ +#if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX) +#if (DUK_UINTPTR_MAX <= 0xffffffffUL) +#define DUK_F_PACKED_TVAL_POSSIBLE +#endif +#endif + +/* Non-C99 case, still relying on DUK_UINTPTR_MAX, as long as it is not a computed value */ +#if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX) && !defined(DUK_UINTPTR_MAX_COMPUTED) +#if (DUK_UINTPTR_MAX <= 0xffffffffUL) +#define DUK_F_PACKED_TVAL_POSSIBLE +#endif +#endif + +/* DUK_SIZE_MAX (= SIZE_MAX) is often reliable */ +#if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_SIZE_MAX) && !defined(DUK_SIZE_MAX_COMPUTED) +#if (DUK_SIZE_MAX <= 0xffffffffUL) +#define DUK_F_PACKED_TVAL_POSSIBLE +#endif +#endif + +#undef DUK_USE_PACKED_TVAL +#if defined(DUK_F_PACKED_TVAL_POSSIBLE) +#define DUK_USE_PACKED_TVAL +#endif + +#undef DUK_F_PACKED_TVAL_POSSIBLE +#endif /* DUK_F_PACKED_TVAL_PROVIDED */ +/* Object property allocation layout has implications for memory and code + * footprint and generated code size/speed. The best layout also depends + * on whether the platform has alignment requirements or benefits from + * having mostly aligned accesses. + */ +#undef DUK_USE_HOBJECT_LAYOUT_1 +#undef DUK_USE_HOBJECT_LAYOUT_2 +#undef DUK_USE_HOBJECT_LAYOUT_3 +#if (DUK_USE_ALIGN_BY == 1) +/* On platforms without any alignment issues, layout 1 is preferable + * because it compiles to slightly less code and provides direct access + * to property keys. + */ +#define DUK_USE_HOBJECT_LAYOUT_1 +#else +/* On other platforms use layout 2, which requires some padding but + * is a bit more natural than layout 3 in ordering the entries. Layout + * 3 is currently not used. + */ +#define DUK_USE_HOBJECT_LAYOUT_2 +#endif + +/* GCC/clang inaccurate math would break compliance and probably duk_tval, + * so refuse to compile. Relax this if -ffast-math is tested to work. + */ +#if defined(__FAST_MATH__) +#error __FAST_MATH__ defined, refusing to compile +#endif + +/* + * Autogenerated defaults + */ + +#define DUK_USE_ARRAY_BUILTIN +#define DUK_USE_ARRAY_FASTPATH +#define DUK_USE_ARRAY_PROP_FASTPATH +#undef DUK_USE_ASSERTIONS +#define DUK_USE_AUGMENT_ERROR_CREATE +#define DUK_USE_AUGMENT_ERROR_THROW +#define DUK_USE_AVOID_PLATFORM_FUNCPTRS +#define DUK_USE_BASE64_FASTPATH +#define DUK_USE_BOOLEAN_BUILTIN +#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 +#undef DUK_USE_CPP_EXCEPTIONS +#undef DUK_USE_DATAPTR16 +#undef DUK_USE_DATAPTR_DEC16 +#undef DUK_USE_DATAPTR_ENC16 +#define DUK_USE_DATE_BUILTIN +#undef DUK_USE_DATE_FORMAT_STRING +#undef DUK_USE_DATE_GET_LOCAL_TZOFFSET +#undef DUK_USE_DATE_GET_NOW +#undef DUK_USE_DATE_PARSE_STRING +#undef DUK_USE_DATE_PRS_GETDATE +#undef DUK_USE_DEBUG +#undef DUK_USE_DEBUGGER_DUMPHEAP +#undef DUK_USE_DEBUGGER_INSPECT +#undef DUK_USE_DEBUGGER_PAUSE_UNCAUGHT +#undef DUK_USE_DEBUGGER_SUPPORT +#define DUK_USE_DEBUGGER_THROW_NOTIFY +#undef DUK_USE_DEBUGGER_TRANSPORT_TORTURE +#define DUK_USE_DEBUG_BUFSIZE 65536L +#define DUK_USE_DEBUG_LEVEL 0 +#undef DUK_USE_DEBUG_WRITE +#define DUK_USE_DOUBLE_LINKED_HEAP +#define DUK_USE_DUKTAPE_BUILTIN +#define DUK_USE_ENCODING_BUILTINS +#define DUK_USE_ERRCREATE +#define DUK_USE_ERRTHROW +#define DUK_USE_ES6 +#define DUK_USE_ES6_OBJECT_PROTO_PROPERTY +#define DUK_USE_ES6_OBJECT_SETPROTOTYPEOF +#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 +#undef DUK_USE_EXEC_FUN_LOCAL +#undef DUK_USE_EXEC_INDIRECT_BOUND_CHECK +#undef DUK_USE_EXEC_PREFER_SIZE +#define DUK_USE_EXEC_REGCONST_OPTIMIZE +#undef DUK_USE_EXEC_TIMEOUT_CHECK +#undef DUK_USE_EXPLICIT_NULL_INIT +#undef DUK_USE_EXTSTR_FREE +#undef DUK_USE_EXTSTR_INTERN_CHECK +#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 +#undef DUK_USE_FUNCPTR_DEC16 +#undef DUK_USE_FUNCPTR_ENC16 +#define DUK_USE_FUNCTION_BUILTIN +#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 +#undef DUK_USE_HEAPPTR16 +#undef DUK_USE_HEAPPTR_DEC16 +#undef DUK_USE_HEAPPTR_ENC16 +#define DUK_USE_HEX_FASTPATH +#define DUK_USE_HOBJECT_ARRAY_ABANDON_LIMIT 2 +#define DUK_USE_HOBJECT_ARRAY_FAST_RESIZE_LIMIT 9 +#define DUK_USE_HOBJECT_ARRAY_MINGROW_ADD 16 +#define DUK_USE_HOBJECT_ARRAY_MINGROW_DIVISOR 8 +#define DUK_USE_HOBJECT_ENTRY_MINGROW_ADD 16 +#define DUK_USE_HOBJECT_ENTRY_MINGROW_DIVISOR 8 +#define DUK_USE_HOBJECT_HASH_PART +#define DUK_USE_HOBJECT_HASH_PROP_LIMIT 8 +#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 +#undef DUK_USE_INTERRUPT_COUNTER +#undef DUK_USE_INTERRUPT_DEBUG_FIXUP +#define DUK_USE_JC +#define DUK_USE_JSON_BUILTIN +#define DUK_USE_JSON_DECNUMBER_FASTPATH +#define DUK_USE_JSON_DECSTRING_FASTPATH +#define DUK_USE_JSON_DEC_RECLIMIT 1000 +#define DUK_USE_JSON_EATWHITE_FASTPATH +#define DUK_USE_JSON_ENC_RECLIMIT 1000 +#define DUK_USE_JSON_QUOTESTRING_FASTPATH +#undef DUK_USE_JSON_STRINGIFY_FASTPATH +#define DUK_USE_JSON_SUPPORT +#define DUK_USE_JX +#define DUK_USE_LEXER_SLIDING_WINDOW +#undef DUK_USE_LIGHTFUNC_BUILTINS +#define DUK_USE_MARK_AND_SWEEP_RECLIMIT 256 +#define DUK_USE_MATH_BUILTIN +#define DUK_USE_NATIVE_CALL_RECLIMIT 1000 +#define DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER +#define DUK_USE_NONSTD_ARRAY_MAP_TRAILER +#define DUK_USE_NONSTD_ARRAY_SPLICE_DELCOUNT +#undef DUK_USE_NONSTD_FUNC_CALLER_PROPERTY +#undef DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY +#define DUK_USE_NONSTD_FUNC_STMT +#define DUK_USE_NONSTD_GETTER_KEY_ARGUMENT +#define DUK_USE_NONSTD_JSON_ESC_U2028_U2029 +#define DUK_USE_NONSTD_SETTER_KEY_ARGUMENT +#define DUK_USE_NONSTD_STRING_FROMCHARCODE_32BIT +#define DUK_USE_NUMBER_BUILTIN +#define DUK_USE_OBJECT_BUILTIN +#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 +#define DUK_USE_REGEXP_SUPPORT +#undef DUK_USE_ROM_GLOBAL_CLONE +#undef DUK_USE_ROM_GLOBAL_INHERIT +#undef DUK_USE_ROM_OBJECTS +#define DUK_USE_ROM_PTRCOMP_FIRST 63488L +#undef DUK_USE_ROM_STRINGS +#define DUK_USE_SECTION_B +#undef DUK_USE_SELF_TESTS +#define DUK_USE_SHEBANG_COMMENTS +#undef DUK_USE_SHUFFLE_TORTURE +#define DUK_USE_SOURCE_NONBMP +#undef DUK_USE_STRHASH16 +#undef DUK_USE_STRHASH_DENSE +#define DUK_USE_STRHASH_SKIP_SHIFT 5 +#define DUK_USE_STRICT_DECL +#undef DUK_USE_STRICT_UTF8_SOURCE +#define DUK_USE_STRING_BUILTIN +#undef DUK_USE_STRLEN16 +#define DUK_USE_STRTAB_GROW_LIMIT 17 +#define DUK_USE_STRTAB_MAXSIZE 268435456L +#define DUK_USE_STRTAB_MINSIZE 1024 +#undef DUK_USE_STRTAB_PTRCOMP +#define DUK_USE_STRTAB_RESIZE_CHECK_MASK 255 +#define DUK_USE_STRTAB_SHRINK_LIMIT 6 +#undef DUK_USE_STRTAB_TORTURE +#undef DUK_USE_SYMBOL_BUILTIN +#define DUK_USE_TAILCALL +#define DUK_USE_TARGET_INFO "unknown" +#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 +#define DUK_USE_VOLUNTARY_GC +#define DUK_USE_ZERO_BUFFER_DATA + +/* + * You may add overriding #define/#undef directives below for + * customization. You of course cannot un-#include or un-typedef + * anything; these require direct changes above. + */ + +/* __OVERRIDE_DEFINES__ */ + +/* + * Date provider selection + * + * User may define DUK_USE_DATE_GET_NOW() etc directly, in which case we'll + * rely on an external provider. If this is not done, revert to previous + * behavior and use Unix/Windows built-in provider. + */ + +#if defined(DUK_COMPILING_DUKTAPE) + +#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() +#elif defined(DUK_USE_DATE_NOW_TIME) +#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() +#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 + +#if defined(DUK_USE_DATE_GET_LOCAL_TZOFFSET) +/* External provider already defined. */ +#elif defined(DUK_USE_DATE_TZO_GMTIME_R) || defined(DUK_USE_DATE_TZO_GMTIME_S) || defined(DUK_USE_DATE_TZO_GMTIME) +#define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d) duk_bi_date_get_local_tzoffset_gmtime((d)) +#elif defined(DUK_USE_DATE_TZO_WINDOWS) +#define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d) duk_bi_date_get_local_tzoffset_windows((d)) +#elif defined(DUK_USE_DATE_TZO_WINDOWS_NO_DST) +#define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d) duk_bi_date_get_local_tzoffset_windows_no_dst((d)) +#else +#error no provider for DUK_USE_DATE_GET_LOCAL_TZOFFSET() +#endif + +#if defined(DUK_USE_DATE_PARSE_STRING) +/* External provider already defined. */ +#elif defined(DUK_USE_DATE_PRS_STRPTIME) +#define DUK_USE_DATE_PARSE_STRING(ctx,str) duk_bi_date_parse_string_strptime((ctx), (str)) +#elif defined(DUK_USE_DATE_PRS_GETDATE) +#define DUK_USE_DATE_PARSE_STRING(ctx,str) duk_bi_date_parse_string_getdate((ctx), (str)) +#else +/* No provider for DUK_USE_DATE_PARSE_STRING(), fall back to ISO 8601 only. */ +#endif + +#if defined(DUK_USE_DATE_FORMAT_STRING) +/* External provider already defined. */ +#elif defined(DUK_USE_DATE_FMT_STRFTIME) +#define DUK_USE_DATE_FORMAT_STRING(ctx,parts,tzoffset,flags) \ + duk_bi_date_format_parts_strftime((ctx), (parts), (tzoffset), (flags)) +#else +/* 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 */ + +/* + * Checks for legacy feature options (DUK_OPT_xxx) + */ + +#if defined(DUK_OPT_ASSERTIONS) +#error unsupported legacy feature option DUK_OPT_ASSERTIONS used +#endif +#if defined(DUK_OPT_BUFFEROBJECT_SUPPORT) +#error unsupported legacy feature option DUK_OPT_BUFFEROBJECT_SUPPORT used +#endif +#if defined(DUK_OPT_BUFLEN16) +#error unsupported legacy feature option DUK_OPT_BUFLEN16 used +#endif +#if defined(DUK_OPT_DATAPTR16) +#error unsupported legacy feature option DUK_OPT_DATAPTR16 used +#endif +#if defined(DUK_OPT_DATAPTR_DEC16) +#error unsupported legacy feature option DUK_OPT_DATAPTR_DEC16 used +#endif +#if defined(DUK_OPT_DATAPTR_ENC16) +#error unsupported legacy feature option DUK_OPT_DATAPTR_ENC16 used +#endif +#if defined(DUK_OPT_DDDPRINT) +#error unsupported legacy feature option DUK_OPT_DDDPRINT used +#endif +#if defined(DUK_OPT_DDPRINT) +#error unsupported legacy feature option DUK_OPT_DDPRINT used +#endif +#if defined(DUK_OPT_DEBUG) +#error unsupported legacy feature option DUK_OPT_DEBUG used +#endif +#if defined(DUK_OPT_DEBUGGER_DUMPHEAP) +#error unsupported legacy feature option DUK_OPT_DEBUGGER_DUMPHEAP used +#endif +#if defined(DUK_OPT_DEBUGGER_FWD_LOGGING) +#error unsupported legacy feature option DUK_OPT_DEBUGGER_FWD_LOGGING used +#endif +#if defined(DUK_OPT_DEBUGGER_FWD_PRINTALERT) +#error unsupported legacy feature option DUK_OPT_DEBUGGER_FWD_PRINTALERT used +#endif +#if defined(DUK_OPT_DEBUGGER_SUPPORT) +#error unsupported legacy feature option DUK_OPT_DEBUGGER_SUPPORT used +#endif +#if defined(DUK_OPT_DEBUGGER_TRANSPORT_TORTURE) +#error unsupported legacy feature option DUK_OPT_DEBUGGER_TRANSPORT_TORTURE used +#endif +#if defined(DUK_OPT_DEBUG_BUFSIZE) +#error unsupported legacy feature option DUK_OPT_DEBUG_BUFSIZE used +#endif +#if defined(DUK_OPT_DECLARE) +#error unsupported legacy feature option DUK_OPT_DECLARE used +#endif +#if defined(DUK_OPT_DEEP_C_STACK) +#error unsupported legacy feature option DUK_OPT_DEEP_C_STACK used +#endif +#if defined(DUK_OPT_DLL_BUILD) +#error unsupported legacy feature option DUK_OPT_DLL_BUILD used +#endif +#if defined(DUK_OPT_DPRINT) +#error unsupported legacy feature option DUK_OPT_DPRINT used +#endif +#if defined(DUK_OPT_DPRINT_COLORS) +#error unsupported legacy feature option DUK_OPT_DPRINT_COLORS used +#endif +#if defined(DUK_OPT_DPRINT_RDTSC) +#error unsupported legacy feature option DUK_OPT_DPRINT_RDTSC used +#endif +#if defined(DUK_OPT_EXEC_TIMEOUT_CHECK) +#error unsupported legacy feature option DUK_OPT_EXEC_TIMEOUT_CHECK used +#endif +#if defined(DUK_OPT_EXTERNAL_STRINGS) +#error unsupported legacy feature option DUK_OPT_EXTERNAL_STRINGS used +#endif +#if defined(DUK_OPT_EXTSTR_FREE) +#error unsupported legacy feature option DUK_OPT_EXTSTR_FREE used +#endif +#if defined(DUK_OPT_EXTSTR_INTERN_CHECK) +#error unsupported legacy feature option DUK_OPT_EXTSTR_INTERN_CHECK used +#endif +#if defined(DUK_OPT_FASTINT) +#error unsupported legacy feature option DUK_OPT_FASTINT used +#endif +#if defined(DUK_OPT_FORCE_ALIGN) +#error unsupported legacy feature option DUK_OPT_FORCE_ALIGN used +#endif +#if defined(DUK_OPT_FORCE_BYTEORDER) +#error unsupported legacy feature option DUK_OPT_FORCE_BYTEORDER used +#endif +#if defined(DUK_OPT_FUNCPTR16) +#error unsupported legacy feature option DUK_OPT_FUNCPTR16 used +#endif +#if defined(DUK_OPT_FUNCPTR_DEC16) +#error unsupported legacy feature option DUK_OPT_FUNCPTR_DEC16 used +#endif +#if defined(DUK_OPT_FUNCPTR_ENC16) +#error unsupported legacy feature option DUK_OPT_FUNCPTR_ENC16 used +#endif +#if defined(DUK_OPT_FUNC_NONSTD_CALLER_PROPERTY) +#error unsupported legacy feature option DUK_OPT_FUNC_NONSTD_CALLER_PROPERTY used +#endif +#if defined(DUK_OPT_FUNC_NONSTD_SOURCE_PROPERTY) +#error unsupported legacy feature option DUK_OPT_FUNC_NONSTD_SOURCE_PROPERTY used +#endif +#if defined(DUK_OPT_GC_TORTURE) +#error unsupported legacy feature option DUK_OPT_GC_TORTURE used +#endif +#if defined(DUK_OPT_HAVE_CUSTOM_H) +#error unsupported legacy feature option DUK_OPT_HAVE_CUSTOM_H used +#endif +#if defined(DUK_OPT_HEAPPTR16) +#error unsupported legacy feature option DUK_OPT_HEAPPTR16 used +#endif +#if defined(DUK_OPT_HEAPPTR_DEC16) +#error unsupported legacy feature option DUK_OPT_HEAPPTR_DEC16 used +#endif +#if defined(DUK_OPT_HEAPPTR_ENC16) +#error unsupported legacy feature option DUK_OPT_HEAPPTR_ENC16 used +#endif +#if defined(DUK_OPT_INTERRUPT_COUNTER) +#error unsupported legacy feature option DUK_OPT_INTERRUPT_COUNTER used +#endif +#if defined(DUK_OPT_JSON_STRINGIFY_FASTPATH) +#error unsupported legacy feature option DUK_OPT_JSON_STRINGIFY_FASTPATH used +#endif +#if defined(DUK_OPT_LIGHTFUNC_BUILTINS) +#error unsupported legacy feature option DUK_OPT_LIGHTFUNC_BUILTINS used +#endif +#if defined(DUK_OPT_NONSTD_FUNC_CALLER_PROPERTY) +#error unsupported legacy feature option DUK_OPT_NONSTD_FUNC_CALLER_PROPERTY used +#endif +#if defined(DUK_OPT_NONSTD_FUNC_SOURCE_PROPERTY) +#error unsupported legacy feature option DUK_OPT_NONSTD_FUNC_SOURCE_PROPERTY used +#endif +#if defined(DUK_OPT_NO_ARRAY_SPLICE_NONSTD_DELCOUNT) +#error unsupported legacy feature option DUK_OPT_NO_ARRAY_SPLICE_NONSTD_DELCOUNT used +#endif +#if defined(DUK_OPT_NO_AUGMENT_ERRORS) +#error unsupported legacy feature option DUK_OPT_NO_AUGMENT_ERRORS used +#endif +#if defined(DUK_OPT_NO_BROWSER_LIKE) +#error unsupported legacy feature option DUK_OPT_NO_BROWSER_LIKE used +#endif +#if defined(DUK_OPT_NO_BUFFEROBJECT_SUPPORT) +#error unsupported legacy feature option DUK_OPT_NO_BUFFEROBJECT_SUPPORT used +#endif +#if defined(DUK_OPT_NO_BYTECODE_DUMP_SUPPORT) +#error unsupported legacy feature option DUK_OPT_NO_BYTECODE_DUMP_SUPPORT used +#endif +#if defined(DUK_OPT_NO_COMMONJS_MODULES) +#error unsupported legacy feature option DUK_OPT_NO_COMMONJS_MODULES used +#endif +#if defined(DUK_OPT_NO_ES6_OBJECT_PROTO_PROPERTY) +#error unsupported legacy feature option DUK_OPT_NO_ES6_OBJECT_PROTO_PROPERTY used +#endif +#if defined(DUK_OPT_NO_ES6_OBJECT_SETPROTOTYPEOF) +#error unsupported legacy feature option DUK_OPT_NO_ES6_OBJECT_SETPROTOTYPEOF used +#endif +#if defined(DUK_OPT_NO_ES6_PROXY) +#error unsupported legacy feature option DUK_OPT_NO_ES6_PROXY used +#endif +#if defined(DUK_OPT_NO_FILE_IO) +#error unsupported legacy feature option DUK_OPT_NO_FILE_IO used +#endif +#if defined(DUK_OPT_NO_FUNC_STMT) +#error unsupported legacy feature option DUK_OPT_NO_FUNC_STMT used +#endif +#if defined(DUK_OPT_NO_JC) +#error unsupported legacy feature option DUK_OPT_NO_JC used +#endif +#if defined(DUK_OPT_NO_JSONC) +#error unsupported legacy feature option DUK_OPT_NO_JSONC used +#endif +#if defined(DUK_OPT_NO_JSONX) +#error unsupported legacy feature option DUK_OPT_NO_JSONX used +#endif +#if defined(DUK_OPT_NO_JX) +#error unsupported legacy feature option DUK_OPT_NO_JX used +#endif +#if defined(DUK_OPT_NO_MARK_AND_SWEEP) +#error unsupported legacy feature option DUK_OPT_NO_MARK_AND_SWEEP used +#endif +#if defined(DUK_OPT_NO_MS_STRINGTABLE_RESIZE) +#error unsupported legacy feature option DUK_OPT_NO_MS_STRINGTABLE_RESIZE used +#endif +#if defined(DUK_OPT_NO_NONSTD_ACCESSOR_KEY_ARGUMENT) +#error unsupported legacy feature option DUK_OPT_NO_NONSTD_ACCESSOR_KEY_ARGUMENT used +#endif +#if defined(DUK_OPT_NO_NONSTD_ARRAY_CONCAT_TRAILER) +#error unsupported legacy feature option DUK_OPT_NO_NONSTD_ARRAY_CONCAT_TRAILER used +#endif +#if defined(DUK_OPT_NO_NONSTD_ARRAY_MAP_TRAILER) +#error unsupported legacy feature option DUK_OPT_NO_NONSTD_ARRAY_MAP_TRAILER used +#endif +#if defined(DUK_OPT_NO_NONSTD_ARRAY_SPLICE_DELCOUNT) +#error unsupported legacy feature option DUK_OPT_NO_NONSTD_ARRAY_SPLICE_DELCOUNT used +#endif +#if defined(DUK_OPT_NO_NONSTD_FUNC_STMT) +#error unsupported legacy feature option DUK_OPT_NO_NONSTD_FUNC_STMT used +#endif +#if defined(DUK_OPT_NO_NONSTD_JSON_ESC_U2028_U2029) +#error unsupported legacy feature option DUK_OPT_NO_NONSTD_JSON_ESC_U2028_U2029 used +#endif +#if defined(DUK_OPT_NO_NONSTD_STRING_FROMCHARCODE_32BIT) +#error unsupported legacy feature option DUK_OPT_NO_NONSTD_STRING_FROMCHARCODE_32BIT used +#endif +#if defined(DUK_OPT_NO_OBJECT_ES6_PROTO_PROPERTY) +#error unsupported legacy feature option DUK_OPT_NO_OBJECT_ES6_PROTO_PROPERTY used +#endif +#if defined(DUK_OPT_NO_OBJECT_ES6_SETPROTOTYPEOF) +#error unsupported legacy feature option DUK_OPT_NO_OBJECT_ES6_SETPROTOTYPEOF used +#endif +#if defined(DUK_OPT_NO_OCTAL_SUPPORT) +#error unsupported legacy feature option DUK_OPT_NO_OCTAL_SUPPORT used +#endif +#if defined(DUK_OPT_NO_PACKED_TVAL) +#error unsupported legacy feature option DUK_OPT_NO_PACKED_TVAL used +#endif +#if defined(DUK_OPT_NO_PC2LINE) +#error unsupported legacy feature option DUK_OPT_NO_PC2LINE used +#endif +#if defined(DUK_OPT_NO_REFERENCE_COUNTING) +#error unsupported legacy feature option DUK_OPT_NO_REFERENCE_COUNTING used +#endif +#if defined(DUK_OPT_NO_REGEXP_SUPPORT) +#error unsupported legacy feature option DUK_OPT_NO_REGEXP_SUPPORT used +#endif +#if defined(DUK_OPT_NO_SECTION_B) +#error unsupported legacy feature option DUK_OPT_NO_SECTION_B used +#endif +#if defined(DUK_OPT_NO_SOURCE_NONBMP) +#error unsupported legacy feature option DUK_OPT_NO_SOURCE_NONBMP used +#endif +#if defined(DUK_OPT_NO_STRICT_DECL) +#error unsupported legacy feature option DUK_OPT_NO_STRICT_DECL used +#endif +#if defined(DUK_OPT_NO_TRACEBACKS) +#error unsupported legacy feature option DUK_OPT_NO_TRACEBACKS used +#endif +#if defined(DUK_OPT_NO_VERBOSE_ERRORS) +#error unsupported legacy feature option DUK_OPT_NO_VERBOSE_ERRORS used +#endif +#if defined(DUK_OPT_NO_VOLUNTARY_GC) +#error unsupported legacy feature option DUK_OPT_NO_VOLUNTARY_GC used +#endif +#if defined(DUK_OPT_NO_ZERO_BUFFER_DATA) +#error unsupported legacy feature option DUK_OPT_NO_ZERO_BUFFER_DATA used +#endif +#if defined(DUK_OPT_OBJSIZES16) +#error unsupported legacy feature option DUK_OPT_OBJSIZES16 used +#endif +#if defined(DUK_OPT_PANIC_HANDLER) +#error unsupported legacy feature option DUK_OPT_PANIC_HANDLER used +#endif +#if defined(DUK_OPT_REFCOUNT16) +#error unsupported legacy feature option DUK_OPT_REFCOUNT16 used +#endif +#if defined(DUK_OPT_SEGFAULT_ON_PANIC) +#error unsupported legacy feature option DUK_OPT_SEGFAULT_ON_PANIC used +#endif +#if defined(DUK_OPT_SELF_TESTS) +#error unsupported legacy feature option DUK_OPT_SELF_TESTS used +#endif +#if defined(DUK_OPT_SETJMP) +#error unsupported legacy feature option DUK_OPT_SETJMP used +#endif +#if defined(DUK_OPT_SHUFFLE_TORTURE) +#error unsupported legacy feature option DUK_OPT_SHUFFLE_TORTURE used +#endif +#if defined(DUK_OPT_SIGSETJMP) +#error unsupported legacy feature option DUK_OPT_SIGSETJMP used +#endif +#if defined(DUK_OPT_STRHASH16) +#error unsupported legacy feature option DUK_OPT_STRHASH16 used +#endif +#if defined(DUK_OPT_STRICT_UTF8_SOURCE) +#error unsupported legacy feature option DUK_OPT_STRICT_UTF8_SOURCE used +#endif +#if defined(DUK_OPT_STRLEN16) +#error unsupported legacy feature option DUK_OPT_STRLEN16 used +#endif +#if defined(DUK_OPT_STRTAB_CHAIN) +#error unsupported legacy feature option DUK_OPT_STRTAB_CHAIN used +#endif +#if defined(DUK_OPT_STRTAB_CHAIN_SIZE) +#error unsupported legacy feature option DUK_OPT_STRTAB_CHAIN_SIZE used +#endif +#if defined(DUK_OPT_TARGET_INFO) +#error unsupported legacy feature option DUK_OPT_TARGET_INFO used +#endif +#if defined(DUK_OPT_TRACEBACK_DEPTH) +#error unsupported legacy feature option DUK_OPT_TRACEBACK_DEPTH used +#endif +#if defined(DUK_OPT_UNDERSCORE_SETJMP) +#error unsupported legacy feature option DUK_OPT_UNDERSCORE_SETJMP used +#endif +#if defined(DUK_OPT_USER_INITJS) +#error unsupported legacy feature option DUK_OPT_USER_INITJS used +#endif + +/* + * Checks for config option consistency (DUK_USE_xxx) + */ + +#if defined(DUK_USE_32BIT_PTRS) +#error unsupported config option used (option has been removed): DUK_USE_32BIT_PTRS +#endif +#if defined(DUK_USE_ALIGN_4) +#error unsupported config option used (option has been removed): DUK_USE_ALIGN_4 +#endif +#if defined(DUK_USE_ALIGN_8) +#error unsupported config option used (option has been removed): DUK_USE_ALIGN_8 +#endif +#if defined(DUK_USE_BROWSER_LIKE) +#error unsupported config option used (option has been removed): DUK_USE_BROWSER_LIKE +#endif +#if defined(DUK_USE_BUILTIN_INITJS) +#error unsupported config option used (option has been removed): DUK_USE_BUILTIN_INITJS +#endif +#if defined(DUK_USE_BYTEORDER_FORCED) +#error unsupported config option used (option has been removed): DUK_USE_BYTEORDER_FORCED +#endif +#if defined(DUK_USE_DATAPTR_DEC16) && !defined(DUK_USE_DATAPTR16) +#error config option DUK_USE_DATAPTR_DEC16 requires option DUK_USE_DATAPTR16 (which is missing) +#endif +#if defined(DUK_USE_DATAPTR_ENC16) && !defined(DUK_USE_DATAPTR16) +#error config option DUK_USE_DATAPTR_ENC16 requires option DUK_USE_DATAPTR16 (which is missing) +#endif +#if defined(DUK_USE_DDDPRINT) +#error unsupported config option used (option has been removed): DUK_USE_DDDPRINT +#endif +#if defined(DUK_USE_DDPRINT) +#error unsupported config option used (option has been removed): DUK_USE_DDPRINT +#endif +#if defined(DUK_USE_DEBUGGER_FWD_LOGGING) +#error unsupported config option used (option has been removed): DUK_USE_DEBUGGER_FWD_LOGGING +#endif +#if defined(DUK_USE_DEBUGGER_FWD_PRINTALERT) +#error unsupported config option used (option has been removed): DUK_USE_DEBUGGER_FWD_PRINTALERT +#endif +#if defined(DUK_USE_DEBUGGER_SUPPORT) && !defined(DUK_USE_INTERRUPT_COUNTER) +#error config option DUK_USE_DEBUGGER_SUPPORT requires option DUK_USE_INTERRUPT_COUNTER (which is missing) +#endif +#if defined(DUK_USE_DEEP_C_STACK) +#error unsupported config option used (option has been removed): DUK_USE_DEEP_C_STACK +#endif +#if defined(DUK_USE_DOUBLE_BE) +#error unsupported config option used (option has been removed): DUK_USE_DOUBLE_BE +#endif +#if defined(DUK_USE_DOUBLE_BE) && defined(DUK_USE_DOUBLE_LE) +#error config option DUK_USE_DOUBLE_BE conflicts with option DUK_USE_DOUBLE_LE (which is also defined) +#endif +#if defined(DUK_USE_DOUBLE_BE) && defined(DUK_USE_DOUBLE_ME) +#error config option DUK_USE_DOUBLE_BE conflicts with option DUK_USE_DOUBLE_ME (which is also defined) +#endif +#if defined(DUK_USE_DOUBLE_LE) +#error unsupported config option used (option has been removed): DUK_USE_DOUBLE_LE +#endif +#if defined(DUK_USE_DOUBLE_LE) && defined(DUK_USE_DOUBLE_BE) +#error config option DUK_USE_DOUBLE_LE conflicts with option DUK_USE_DOUBLE_BE (which is also defined) +#endif +#if defined(DUK_USE_DOUBLE_LE) && defined(DUK_USE_DOUBLE_ME) +#error config option DUK_USE_DOUBLE_LE conflicts with option DUK_USE_DOUBLE_ME (which is also defined) +#endif +#if defined(DUK_USE_DOUBLE_ME) +#error unsupported config option used (option has been removed): DUK_USE_DOUBLE_ME +#endif +#if defined(DUK_USE_DOUBLE_ME) && defined(DUK_USE_DOUBLE_LE) +#error config option DUK_USE_DOUBLE_ME conflicts with option DUK_USE_DOUBLE_LE (which is also defined) +#endif +#if defined(DUK_USE_DOUBLE_ME) && defined(DUK_USE_DOUBLE_BE) +#error config option DUK_USE_DOUBLE_ME conflicts with option DUK_USE_DOUBLE_BE (which is also defined) +#endif +#if defined(DUK_USE_DPRINT) +#error unsupported config option used (option has been removed): DUK_USE_DPRINT +#endif +#if defined(DUK_USE_DPRINT) && !defined(DUK_USE_DEBUG) +#error config option DUK_USE_DPRINT requires option DUK_USE_DEBUG (which is missing) +#endif +#if defined(DUK_USE_DPRINT_COLORS) +#error unsupported config option used (option has been removed): DUK_USE_DPRINT_COLORS +#endif +#if defined(DUK_USE_DPRINT_RDTSC) +#error unsupported config option used (option has been removed): DUK_USE_DPRINT_RDTSC +#endif +#if defined(DUK_USE_ES6_REGEXP_BRACES) +#error unsupported config option used (option has been removed): DUK_USE_ES6_REGEXP_BRACES +#endif +#if defined(DUK_USE_ESBC_MAX_BYTES) && !defined(DUK_USE_ESBC_LIMITS) +#error config option DUK_USE_ESBC_MAX_BYTES requires option DUK_USE_ESBC_LIMITS (which is missing) +#endif +#if defined(DUK_USE_ESBC_MAX_LINENUMBER) && !defined(DUK_USE_ESBC_LIMITS) +#error config option DUK_USE_ESBC_MAX_LINENUMBER requires option DUK_USE_ESBC_LIMITS (which is missing) +#endif +#if defined(DUK_USE_EXEC_TIMEOUT_CHECK) && !defined(DUK_USE_INTERRUPT_COUNTER) +#error config option DUK_USE_EXEC_TIMEOUT_CHECK requires option DUK_USE_INTERRUPT_COUNTER (which is missing) +#endif +#if defined(DUK_USE_EXTSTR_FREE) && !defined(DUK_USE_HSTRING_EXTDATA) +#error config option DUK_USE_EXTSTR_FREE requires option DUK_USE_HSTRING_EXTDATA (which is missing) +#endif +#if defined(DUK_USE_EXTSTR_INTERN_CHECK) && !defined(DUK_USE_HSTRING_EXTDATA) +#error config option DUK_USE_EXTSTR_INTERN_CHECK requires option DUK_USE_HSTRING_EXTDATA (which is missing) +#endif +#if defined(DUK_USE_FASTINT) && !defined(DUK_USE_64BIT_OPS) +#error config option DUK_USE_FASTINT requires option DUK_USE_64BIT_OPS (which is missing) +#endif +#if defined(DUK_USE_FILE_IO) +#error unsupported config option used (option has been removed): DUK_USE_FILE_IO +#endif +#if defined(DUK_USE_FULL_TVAL) +#error unsupported config option used (option has been removed): DUK_USE_FULL_TVAL +#endif +#if defined(DUK_USE_FUNCPTR_DEC16) && !defined(DUK_USE_FUNCPTR16) +#error config option DUK_USE_FUNCPTR_DEC16 requires option DUK_USE_FUNCPTR16 (which is missing) +#endif +#if defined(DUK_USE_FUNCPTR_ENC16) && !defined(DUK_USE_FUNCPTR16) +#error config option DUK_USE_FUNCPTR_ENC16 requires option DUK_USE_FUNCPTR16 (which is missing) +#endif +#if defined(DUK_USE_HASHBYTES_UNALIGNED_U32_ACCESS) +#error unsupported config option used (option has been removed): DUK_USE_HASHBYTES_UNALIGNED_U32_ACCESS +#endif +#if defined(DUK_USE_HEAPPTR16) && defined(DUK_USE_DEBUG) +#error config option DUK_USE_HEAPPTR16 conflicts with option DUK_USE_DEBUG (which is also defined) +#endif +#if defined(DUK_USE_HEAPPTR_DEC16) && !defined(DUK_USE_HEAPPTR16) +#error config option DUK_USE_HEAPPTR_DEC16 requires option DUK_USE_HEAPPTR16 (which is missing) +#endif +#if defined(DUK_USE_HEAPPTR_ENC16) && !defined(DUK_USE_HEAPPTR16) +#error config option DUK_USE_HEAPPTR_ENC16 requires option DUK_USE_HEAPPTR16 (which is missing) +#endif +#if defined(DUK_USE_INTEGER_BE) +#error unsupported config option used (option has been removed): DUK_USE_INTEGER_BE +#endif +#if defined(DUK_USE_INTEGER_BE) && defined(DUK_USE_INTEGER_LE) +#error config option DUK_USE_INTEGER_BE conflicts with option DUK_USE_INTEGER_LE (which is also defined) +#endif +#if defined(DUK_USE_INTEGER_BE) && defined(DUK_USE_INTEGER_ME) +#error config option DUK_USE_INTEGER_BE conflicts with option DUK_USE_INTEGER_ME (which is also defined) +#endif +#if defined(DUK_USE_INTEGER_LE) +#error unsupported config option used (option has been removed): DUK_USE_INTEGER_LE +#endif +#if defined(DUK_USE_INTEGER_LE) && defined(DUK_USE_INTEGER_BE) +#error config option DUK_USE_INTEGER_LE conflicts with option DUK_USE_INTEGER_BE (which is also defined) +#endif +#if defined(DUK_USE_INTEGER_LE) && defined(DUK_USE_INTEGER_ME) +#error config option DUK_USE_INTEGER_LE conflicts with option DUK_USE_INTEGER_ME (which is also defined) +#endif +#if defined(DUK_USE_INTEGER_ME) +#error unsupported config option used (option has been removed): DUK_USE_INTEGER_ME +#endif +#if defined(DUK_USE_INTEGER_ME) && defined(DUK_USE_INTEGER_LE) +#error config option DUK_USE_INTEGER_ME conflicts with option DUK_USE_INTEGER_LE (which is also defined) +#endif +#if defined(DUK_USE_INTEGER_ME) && defined(DUK_USE_INTEGER_BE) +#error config option DUK_USE_INTEGER_ME conflicts with option DUK_USE_INTEGER_BE (which is also defined) +#endif +#if defined(DUK_USE_MARKANDSWEEP_FINALIZER_TORTURE) +#error unsupported config option used (option has been removed): DUK_USE_MARKANDSWEEP_FINALIZER_TORTURE +#endif +#if defined(DUK_USE_MARK_AND_SWEEP) +#error unsupported config option used (option has been removed): DUK_USE_MARK_AND_SWEEP +#endif +#if defined(DUK_USE_MATH_FMAX) +#error unsupported config option used (option has been removed): DUK_USE_MATH_FMAX +#endif +#if defined(DUK_USE_MATH_FMIN) +#error unsupported config option used (option has been removed): DUK_USE_MATH_FMIN +#endif +#if defined(DUK_USE_MATH_ROUND) +#error unsupported config option used (option has been removed): DUK_USE_MATH_ROUND +#endif +#if defined(DUK_USE_MS_STRINGTABLE_RESIZE) +#error unsupported config option used (option has been removed): DUK_USE_MS_STRINGTABLE_RESIZE +#endif +#if defined(DUK_USE_NONSTD_REGEXP_DOLLAR_ESCAPE) +#error unsupported config option used (option has been removed): DUK_USE_NONSTD_REGEXP_DOLLAR_ESCAPE +#endif +#if defined(DUK_USE_NO_DOUBLE_ALIASING_SELFTEST) +#error unsupported config option used (option has been removed): DUK_USE_NO_DOUBLE_ALIASING_SELFTEST +#endif +#if defined(DUK_USE_OCTAL_SUPPORT) +#error unsupported config option used (option has been removed): DUK_USE_OCTAL_SUPPORT +#endif +#if defined(DUK_USE_PACKED_TVAL_POSSIBLE) +#error unsupported config option used (option has been removed): DUK_USE_PACKED_TVAL_POSSIBLE +#endif +#if defined(DUK_USE_PANIC_ABORT) +#error unsupported config option used (option has been removed): DUK_USE_PANIC_ABORT +#endif +#if defined(DUK_USE_PANIC_EXIT) +#error unsupported config option used (option has been removed): DUK_USE_PANIC_EXIT +#endif +#if defined(DUK_USE_PANIC_HANDLER) +#error unsupported config option used (option has been removed): DUK_USE_PANIC_HANDLER +#endif +#if defined(DUK_USE_PANIC_SEGFAULT) +#error unsupported config option used (option has been removed): DUK_USE_PANIC_SEGFAULT +#endif +#if defined(DUK_USE_POW_NETBSD_WORKAROUND) +#error unsupported config option used (option has been removed): DUK_USE_POW_NETBSD_WORKAROUND +#endif +#if defined(DUK_USE_RDTSC) +#error unsupported config option used (option has been removed): DUK_USE_RDTSC +#endif +#if defined(DUK_USE_REFZERO_FINALIZER_TORTURE) +#error unsupported config option used (option has been removed): DUK_USE_REFZERO_FINALIZER_TORTURE +#endif +#if defined(DUK_USE_ROM_GLOBAL_CLONE) && !defined(DUK_USE_ROM_STRINGS) +#error config option DUK_USE_ROM_GLOBAL_CLONE requires option DUK_USE_ROM_STRINGS (which is missing) +#endif +#if defined(DUK_USE_ROM_GLOBAL_CLONE) && !defined(DUK_USE_ROM_OBJECTS) +#error config option DUK_USE_ROM_GLOBAL_CLONE requires option DUK_USE_ROM_OBJECTS (which is missing) +#endif +#if defined(DUK_USE_ROM_GLOBAL_CLONE) && defined(DUK_USE_ROM_GLOBAL_INHERIT) +#error config option DUK_USE_ROM_GLOBAL_CLONE conflicts with option DUK_USE_ROM_GLOBAL_INHERIT (which is also defined) +#endif +#if defined(DUK_USE_ROM_GLOBAL_INHERIT) && !defined(DUK_USE_ROM_STRINGS) +#error config option DUK_USE_ROM_GLOBAL_INHERIT requires option DUK_USE_ROM_STRINGS (which is missing) +#endif +#if defined(DUK_USE_ROM_GLOBAL_INHERIT) && !defined(DUK_USE_ROM_OBJECTS) +#error config option DUK_USE_ROM_GLOBAL_INHERIT requires option DUK_USE_ROM_OBJECTS (which is missing) +#endif +#if defined(DUK_USE_ROM_GLOBAL_INHERIT) && defined(DUK_USE_ROM_GLOBAL_CLONE) +#error config option DUK_USE_ROM_GLOBAL_INHERIT conflicts with option DUK_USE_ROM_GLOBAL_CLONE (which is also defined) +#endif +#if defined(DUK_USE_ROM_OBJECTS) && !defined(DUK_USE_ROM_STRINGS) +#error config option DUK_USE_ROM_OBJECTS requires option DUK_USE_ROM_STRINGS (which is missing) +#endif +#if defined(DUK_USE_ROM_STRINGS) && !defined(DUK_USE_ROM_OBJECTS) +#error config option DUK_USE_ROM_STRINGS requires option DUK_USE_ROM_OBJECTS (which is missing) +#endif +#if defined(DUK_USE_SETJMP) +#error unsupported config option used (option has been removed): DUK_USE_SETJMP +#endif +#if defined(DUK_USE_SIGSETJMP) +#error unsupported config option used (option has been removed): DUK_USE_SIGSETJMP +#endif +#if defined(DUK_USE_STRTAB_CHAIN) +#error unsupported config option used (option has been removed): DUK_USE_STRTAB_CHAIN +#endif +#if defined(DUK_USE_STRTAB_CHAIN_SIZE) +#error unsupported config option used (option has been removed): DUK_USE_STRTAB_CHAIN_SIZE +#endif +#if defined(DUK_USE_STRTAB_CHAIN_SIZE) && !defined(DUK_USE_STRTAB_CHAIN) +#error config option DUK_USE_STRTAB_CHAIN_SIZE requires option DUK_USE_STRTAB_CHAIN (which is missing) +#endif +#if defined(DUK_USE_STRTAB_PROBE) +#error unsupported config option used (option has been removed): DUK_USE_STRTAB_PROBE +#endif +#if defined(DUK_USE_STRTAB_PTRCOMP) && !defined(DUK_USE_HEAPPTR16) +#error config option DUK_USE_STRTAB_PTRCOMP requires option DUK_USE_HEAPPTR16 (which is missing) +#endif +#if defined(DUK_USE_TAILCALL) && defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY) +#error config option DUK_USE_TAILCALL conflicts with option DUK_USE_NONSTD_FUNC_CALLER_PROPERTY (which is also defined) +#endif +#if defined(DUK_USE_UNALIGNED_ACCESSES_POSSIBLE) +#error unsupported config option used (option has been removed): DUK_USE_UNALIGNED_ACCESSES_POSSIBLE +#endif +#if defined(DUK_USE_UNDERSCORE_SETJMP) +#error unsupported config option used (option has been removed): DUK_USE_UNDERSCORE_SETJMP +#endif +#if defined(DUK_USE_USER_INITJS) +#error unsupported config option used (option has been removed): DUK_USE_USER_INITJS +#endif + +#if defined(DUK_USE_CPP_EXCEPTIONS) && !defined(__cplusplus) +#error DUK_USE_CPP_EXCEPTIONS enabled but not compiling with a C++ compiler +#endif + +/* + * Convert DUK_USE_BYTEORDER, from whatever source, into currently used + * internal defines. If detection failed, #error out. + */ + +#if defined(DUK_USE_BYTEORDER) +#if (DUK_USE_BYTEORDER == 1) +#define DUK_USE_INTEGER_LE +#define DUK_USE_DOUBLE_LE +#elif (DUK_USE_BYTEORDER == 2) +#define DUK_USE_INTEGER_LE /* integer endianness is little on purpose */ +#define DUK_USE_DOUBLE_ME +#elif (DUK_USE_BYTEORDER == 3) +#define DUK_USE_INTEGER_BE +#define DUK_USE_DOUBLE_BE +#else +#error unsupported: byte order invalid +#endif /* byte order */ +#else +#error unsupported: byte order detection failed +#endif /* defined(DUK_USE_BYTEORDER) */ + +#endif /* DUK_CONFIG_H_INCLUDED */ diff --git a/vendor/gopkg.in/olebedev/go-duktape.v3/duk_console.c b/vendor/gopkg.in/olebedev/go-duktape.v3/duk_console.c new file mode 100755 index 000000000..9a29903cf --- /dev/null +++ b/vendor/gopkg.in/olebedev/go-duktape.v3/duk_console.c @@ -0,0 +1,163 @@ +/* + * Minimal 'console' binding. + * + * https://github.com/DeveloperToolsWG/console-object/blob/master/api.md + * https://developers.google.com/web/tools/chrome-devtools/debug/console/console-reference + * https://developer.mozilla.org/en/docs/Web/API/console + */ + +#include +#include +#include "duktape.h" +#include "duk_console.h" + +/* XXX: Add some form of log level filtering. */ + +/* XXX: For now logs everything to stdout, V8/Node.js logs debug/info level + * to stdout, warn and above to stderr. Should this extra do the same? + */ + +/* XXX: Should all output be written via e.g. console.write(formattedMsg)? + * This would make it easier for user code to redirect all console output + * to a custom backend. + */ + +/* XXX: Init console object using duk_def_prop() when that call is available. */ + +static duk_ret_t duk__console_log_helper(duk_context *ctx, const char *error_name) { + duk_idx_t i, n; + duk_uint_t flags; + + flags = (duk_uint_t) duk_get_current_magic(ctx); + + n = duk_get_top(ctx); + + duk_get_global_string(ctx, "console"); + duk_get_prop_string(ctx, -1, "format"); + + for (i = 0; i < n; i++) { + if (duk_check_type_mask(ctx, i, DUK_TYPE_MASK_OBJECT)) { + /* Slow path formatting. */ + duk_dup(ctx, -1); /* console.format */ + duk_dup(ctx, i); + duk_call(ctx, 1); + duk_replace(ctx, i); /* arg[i] = console.format(arg[i]); */ + } + } + + duk_pop_2(ctx); + + duk_push_string(ctx, " "); + duk_insert(ctx, 0); + duk_join(ctx, n); + + if (error_name) { + duk_push_error_object(ctx, DUK_ERR_ERROR, "%s", duk_require_string(ctx, -1)); + duk_push_string(ctx, "name"); + duk_push_string(ctx, error_name); + duk_def_prop(ctx, -3, DUK_DEFPROP_FORCE | DUK_DEFPROP_HAVE_VALUE); /* to get e.g. 'Trace: 1 2 3' */ + duk_get_prop_string(ctx, -1, "stack"); + } + + fprintf(stdout, "%s\n", duk_to_string(ctx, -1)); + if (flags & DUK_CONSOLE_FLUSH) { + fflush(stdout); + } + return 0; +} + +static duk_ret_t duk__console_assert(duk_context *ctx) { + if (duk_to_boolean(ctx, 0)) { + return 0; + } + duk_remove(ctx, 0); + + return duk__console_log_helper(ctx, "AssertionError"); +} + +static duk_ret_t duk__console_log(duk_context *ctx) { + return duk__console_log_helper(ctx, NULL); +} + +static duk_ret_t duk__console_trace(duk_context *ctx) { + return duk__console_log_helper(ctx, "Trace"); +} + +static duk_ret_t duk__console_info(duk_context *ctx) { + return duk__console_log_helper(ctx, NULL); +} + +static duk_ret_t duk__console_warn(duk_context *ctx) { + return duk__console_log_helper(ctx, NULL); +} + +static duk_ret_t duk__console_error(duk_context *ctx) { + return duk__console_log_helper(ctx, "Error"); +} + +static duk_ret_t duk__console_dir(duk_context *ctx) { + /* For now, just share the formatting of .log() */ + return duk__console_log_helper(ctx, 0); +} + +static void duk__console_reg_vararg_func(duk_context *ctx, duk_c_function func, const char *name, duk_uint_t flags) { + duk_push_c_function(ctx, func, DUK_VARARGS); + duk_push_string(ctx, "name"); + duk_push_string(ctx, name); + duk_def_prop(ctx, -3, DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_FORCE); /* Improve stacktraces by displaying function name */ + duk_set_magic(ctx, -1, (duk_int_t) flags); + duk_put_prop_string(ctx, -2, name); +} + +void duk_console_init(duk_context *ctx, duk_uint_t flags) { + duk_push_object(ctx); + + /* Custom function to format objects; user can replace. + * For now, try JX-formatting and if that fails, fall back + * to ToString(v). + */ + duk_eval_string(ctx, + "(function (E) {" + "return function format(v){" + "try{" + "return E('jx',v);" + "}catch(e){" + "return String(v);" /* String() allows symbols, ToString() internal algorithm doesn't. */ + "}" + "};" + "})(Duktape.enc)"); + duk_put_prop_string(ctx, -2, "format"); + + duk__console_reg_vararg_func(ctx, duk__console_assert, "assert", flags); + duk__console_reg_vararg_func(ctx, duk__console_log, "log", flags); + duk__console_reg_vararg_func(ctx, duk__console_log, "debug", flags); /* alias to console.log */ + duk__console_reg_vararg_func(ctx, duk__console_trace, "trace", flags); + duk__console_reg_vararg_func(ctx, duk__console_info, "info", flags); + duk__console_reg_vararg_func(ctx, duk__console_warn, "warn", flags); + duk__console_reg_vararg_func(ctx, duk__console_error, "error", flags); + duk__console_reg_vararg_func(ctx, duk__console_error, "exception", flags); /* alias to console.error */ + duk__console_reg_vararg_func(ctx, duk__console_dir, "dir", flags); + + duk_put_global_string(ctx, "console"); + + /* Proxy wrapping: ensures any undefined console method calls are + * ignored silently. This is required specifically by the + * DeveloperToolsWG proposal (and is implemented also by Firefox: + * https://bugzilla.mozilla.org/show_bug.cgi?id=629607). + */ + + if (flags & DUK_CONSOLE_PROXY_WRAPPER) { + /* Tolerate errors: Proxy may be disabled. */ + duk_peval_string_noresult(ctx, + "(function(){" + "var D=function(){};" + "console=new Proxy(console,{" + "get:function(t,k){" + "var v=t[k];" + "return typeof v==='function'?v:D;" + "}" + "});" + "})();" + ); + } +} diff --git a/vendor/gopkg.in/olebedev/go-duktape.v3/duk_console.h b/vendor/gopkg.in/olebedev/go-duktape.v3/duk_console.h new file mode 100755 index 000000000..1488a95fa --- /dev/null +++ b/vendor/gopkg.in/olebedev/go-duktape.v3/duk_console.h @@ -0,0 +1,14 @@ +#if !defined(DUK_CONSOLE_H_INCLUDED) +#define DUK_CONSOLE_H_INCLUDED + +#include "duktape.h" + +/* Use a proxy wrapper to make undefined methods (console.foo()) no-ops. */ +#define DUK_CONSOLE_PROXY_WRAPPER (1 << 0) + +/* Flush output after every call. */ +#define DUK_CONSOLE_FLUSH (1 << 1) + +extern void duk_console_init(duk_context *ctx, duk_uint_t flags); + +#endif /* DUK_CONSOLE_H_INCLUDED */ diff --git a/vendor/gopkg.in/olebedev/go-duktape.v3/duk_logging.c b/vendor/gopkg.in/olebedev/go-duktape.v3/duk_logging.c new file mode 100755 index 000000000..9be2c1c27 --- /dev/null +++ b/vendor/gopkg.in/olebedev/go-duktape.v3/duk_logging.c @@ -0,0 +1,380 @@ +/* + * Logging support + */ + +#include +#include +#include +#include "duktape.h" +#include "duk_logging.h" + +/* XXX: uses stderr always for now, configurable? */ + +#define DUK_LOGGING_FLUSH /* Duktape 1.x: flush stderr */ + +/* 3-letter log level strings. */ +static const char duk__log_level_strings[] = { + 'T', 'R', 'C', 'D', 'B', 'G', 'I', 'N', 'F', + 'W', 'R', 'N', 'E', 'R', 'R', 'F', 'T', 'L' +}; + +/* Log method names. */ +static const char *duk__log_method_names[] = { + "trace", "debug", "info", "warn", "error", "fatal" +}; + +/* Constructor. */ +static duk_ret_t duk__logger_constructor(duk_context *ctx) { + duk_idx_t nargs; + + /* Calling as a non-constructor is not meaningful. */ + if (!duk_is_constructor_call(ctx)) { + return DUK_RET_TYPE_ERROR; + } + + nargs = duk_get_top(ctx); + duk_set_top(ctx, 1); + + duk_push_this(ctx); + + /* [ name this ] */ + + if (nargs == 0) { + /* Automatic defaulting of logger name from caller. This + * would work poorly with tail calls, but constructor calls + * are currently never tail calls, so tail calls are not an + * issue now. + */ + + duk_inspect_callstack_entry(ctx, -2); + if (duk_is_object(ctx, -1)) { + if (duk_get_prop_string(ctx, -1, "function")) { + if (duk_get_prop_string(ctx, -1, "fileName")) { + if (duk_is_string(ctx, -1)) { + duk_replace(ctx, 0); + } + } + } + } + /* Leave values on stack on purpose, ignored below. */ + + /* Stripping the filename might be a good idea + * ("/foo/bar/quux.js" -> logger name "quux"), + * but now used verbatim. + */ + } + /* The stack is unbalanced here on purpose; we only rely on the + * initial two values: [ name this ]. + */ + + if (duk_is_string(ctx, 0)) { + duk_dup(ctx, 0); + duk_put_prop_string(ctx, 1, "n"); + } else { + /* don't set 'n' at all, inherited value is used as name */ + } + + duk_compact(ctx, 1); + + return 0; /* keep default instance */ +} + +/* Default function to format objects. Tries to use toLogString() but falls + * back to toString(). Any errors are propagated out without catching. + */ +static duk_ret_t duk__logger_prototype_fmt(duk_context *ctx) { + if (duk_get_prop_string(ctx, 0, "toLogString")) { + /* [ arg toLogString ] */ + + duk_dup(ctx, 0); + duk_call_method(ctx, 0); + + /* [ arg result ] */ + return 1; + } + + /* [ arg undefined ] */ + duk_pop(ctx); + duk_to_string(ctx, 0); + return 1; +} + +/* Default function to write a formatted log line. Writes to stderr, + * appending a newline to the log line. + * + * The argument is a buffer; avoid coercing the buffer to a string to + * avoid string table traffic. + */ +static duk_ret_t duk__logger_prototype_raw(duk_context *ctx) { + const char *data; + duk_size_t data_len; + + data = (const char *) duk_require_buffer(ctx, 0, &data_len); + fwrite((const void *) data, 1, data_len, stderr); + fputc((int) '\n', stderr); +#if defined(DUK_LOGGING_FLUSH) + fflush(stderr); +#endif + return 0; +} + +/* Log frontend shared helper, magic value indicates log level. Provides + * frontend functions: trace(), debug(), info(), warn(), error(), fatal(). + * This needs to have small footprint, reasonable performance, minimal + * memory churn, etc. + */ +static duk_ret_t duk__logger_prototype_log_shared(duk_context *ctx) { + duk_double_t now; + duk_time_components comp; + duk_small_int_t entry_lev; + duk_small_int_t logger_lev; + duk_int_t nargs; + duk_int_t i; + duk_size_t tot_len; + const duk_uint8_t *arg_str; + duk_size_t arg_len; + duk_uint8_t *buf, *p; + const duk_uint8_t *q; + duk_uint8_t date_buf[32]; /* maximum format length is 24+1 (NUL), round up. */ + duk_size_t date_len; + duk_small_int_t rc; + + /* XXX: sanitize to printable (and maybe ASCII) */ + /* XXX: better multiline */ + + /* + * Logger arguments are: + * + * magic: log level (0-5) + * this: logger + * stack: plain log args + * + * We want to minimize memory churn so a two-pass approach + * is used: first pass formats arguments and computes final + * string length, second pass copies strings into a buffer + * allocated directly with the correct size. If the backend + * function plays nice, it won't coerce the buffer to a string + * (and thus intern it). + */ + + entry_lev = duk_get_current_magic(ctx); + if (entry_lev < DUK_LOG_TRACE || entry_lev > DUK_LOG_FATAL) { + /* Should never happen, check just in case. */ + return 0; + } + nargs = duk_get_top(ctx); + + /* [ arg1 ... argN this ] */ + + /* + * Log level check + */ + + duk_push_this(ctx); + + duk_get_prop_string(ctx, -1, "l"); + logger_lev = (duk_small_int_t) duk_get_int(ctx, -1); + if (entry_lev < logger_lev) { + return 0; + } + /* log level could be popped but that's not necessary */ + + now = duk_get_now(ctx); + duk_time_to_components(ctx, now, &comp); + sprintf((char *) date_buf, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", + (int) comp.year, (int) comp.month + 1, (int) comp.day, + (int) comp.hours, (int) comp.minutes, (int) comp.seconds, + (int) comp.milliseconds); + + date_len = strlen((const char *) date_buf); + + duk_get_prop_string(ctx, -2, "n"); + duk_to_string(ctx, -1); + + /* [ arg1 ... argN this loggerLevel loggerName ] */ + + /* + * Pass 1 + */ + + /* Line format: