Skip to content

Commit

Permalink
Merge pull request #74 from jessedoyle/duk/2.7.0
Browse files Browse the repository at this point in the history
feat(engine): Update to Duktape 2.7.0
  • Loading branch information
jessedoyle authored Apr 6, 2023
2 parents abd80b9 + 4c32bcc commit bf57059
Show file tree
Hide file tree
Showing 17 changed files with 12,277 additions and 10,585 deletions.
3 changes: 3 additions & 0 deletions .ameba.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Style/PredicateName:
Excluded:
- src/duktape/api/error_handling.cr
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
.crystal/
.build/
ext/.tmp
src/.build
/doc/
/lib
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# v1.1.0 - April 5, 2023

* Update from Duktape 2.5.0 to 2.7.0!
* Define a default fatal handler for the Duktape heap. This change only impacts heaps created via `LibDUK.create_heap`. Heaps created via `Dukatpe::Context`, `Duktape::Sandbox` or `Duktape::Runtime` are not affected.
* See the release notes for more information:
- [v2.6.0](https://github.com/svaarala/duktape/blob/5e169deafbbd12823665f5d30fb4c4c04e3dfa26/doc/release-notes-v2-6.rst)
- [v2.7.0](https://github.com/svaarala/duktape/blob/5e169deafbbd12823665f5d30fb4c4c04e3dfa26/doc/release-notes-v2-7.rst)

# v1.0.1 - Oct 22, 2022

* Fix a segfault that occurs on Crystal >= 1.6.0. Thanks @z64!, #74
Expand Down
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: all spec duktape libduktape clean cleanlib
.PHONY: all spec duktape libduktape update clean cleanlib

CRYSTAL_BIN := $(shell which crystal)
CRYSTAL_LOG_LEVEL ?= NONE
Expand All @@ -10,20 +10,34 @@ EXT := $(CURRENT)/ext
OUTPUT := $(CURRENT)/.build

all: duktape

duktape: $(OUTPUT)/duktape

libduktape:
$(MAKE) -C $(EXT) libduktape

# use the following to update the native engine:
# VERSION=X.X.X make clean cleanlib update libduktape
update:
$(MAKE) -C $(EXT) -f Makefile.internal update-duktape

spec: all_spec
@LOG_LEVEL=$(CRYSTAL_LOG_LEVEL) LOG_SOURCES=$(CRYSTAL_LOG_SOURCES) $(OUTPUT)/all_spec

all_spec: $(OUTPUT)/all_spec

$(OUTPUT)/all_spec: $(SOURCES) $(SPEC_SOURCES)
@mkdir -p $(OUTPUT)
$(CRYSTAL_BIN) build -o $@ spec/all_spec.cr --warnings all

$(OUTPUT)/duktape: $(SOURCES)
@mkdir -p $(OUTPUT)
$(CRYSTAL_BIN) build -o $@ src/duktape.cr --warnings all

clean:
rm -rf $(OUTPUT)
rm -rf $(CURRENT)/.crystal

cleanlib:
$(MAKE) -C $(EXT) clean
$(MAKE) -C $(EXT) -f Makefile.internal clean
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Duktape.cr

[![GitHub version](https://badge.fury.io/gh/jessedoyle%2Fduktape.cr.svg)](http://badge.fury.io/gh/jessedoyle%2Fduktape.cr)
[![Build Status](https://travis-ci.org/jessedoyle/duktape.cr.svg?branch=master)](https://travis-ci.org/jessedoyle/duktape.cr)
![Build Status](https://github.com/jessedoyle/duktape.cr/actions/workflows/ci.yml/badge.svg)

Duktape.cr provides Crystal bindings to the [Duktape](https://github.com/svaarala/duktape) javascript engine.

Expand All @@ -27,7 +27,7 @@ then execute:
shards install
```

Shards will automatically make the native library. You can make the library manually by calling `make libduktape`.
Shards will automatically build the native library. You can compile the engine manually by invoking `make libduktape`.

## Usage

Expand Down Expand Up @@ -205,6 +205,16 @@ I'll accept any pull requests that are well tested for bugs/features with Duktap

You should fork the main repo, create a feature branch, write tests and submit a pull request.

## Maintenance

### Engine Updates

The engine can be updated by invoking the following make target:

```bash
VERSION=X.X.X make update
```

## License

Duktape.cr is licensed under the MIT License. Please see `LICENSE` for details.
6 changes: 5 additions & 1 deletion ext/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

CURRENT := $(shell pwd)
EXT := $(CURRENT)
PREV := $(shell dirname `pwd`])
PREV := $(shell dirname `pwd`)
OUTPUT := $(PREV)/src/.build
LIBDIR := $(OUTPUT)/lib
INCLUDEDIR := $(OUTPUT)/include
Expand All @@ -16,15 +16,19 @@ CFLAGS ?= \
-fomit-frame-pointer

libduktape: $(OUTPUT)/libduktape.o $(LIBDIR)/libduktape.a $(INCLUDEDIR)/duktape.h

$(OUTPUT)/libduktape.o: $(EXT)/duktape.c
@mkdir -p $(OUTPUT)
$(CC) -o $@ $(EXT)/duktape.c $(CFLAGS)

$(LIBDIR)/libduktape.a:
@mkdir -p $(LIBDIR)
ar rcs $(LIBDIR)/libduktape.a $(OUTPUT)/libduktape.o

$(INCLUDEDIR)/duktape.h:
@mkdir -p $(INCLUDEDIR)
cp $(EXT)/duktape.h $(EXT)/duk_config.h $(INCLUDEDIR)

clean:
rm -rf $(OUTPUT)
rm -rf $(CURRENT)/.crystal
33 changes: 33 additions & 0 deletions ext/Makefile.internal
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.PHONY: update-duktape clean

VERSION ?= 2.7.0
TAG := v$(VERSION)
TMP_DIR ?= .tmp
DUKTAPE := $(TMP_DIR)/duktape-$(VERSION)
PYTHON ?= "python2"

update-duktape: $(TMP_DIR)/build
cp $(TMP_DIR)/build/{duk_config.h,duktape.c,duktape.h} .

$(TMP_DIR)/build: $(DUKTAPE)
$(PYTHON) $(DUKTAPE)/tools/configure.py \
--source-directory $(DUKTAPE)/src-input \
--config-metadata $(DUKTAPE)/config \
--output-directory $@ \
--option-file duktape_runtime_options.yml

$(TMP_DIR)/duktape-%: $(TMP_DIR)/duktape-%.tar.xz
mkdir -p $@
tar -xf $^ --directory $(TMP_DIR)

$(TMP_DIR)/duktape-%.tar.xz: $(TMP_DIR)
@curl -L https://github.com/svaarala/duktape/releases/download/$(TAG)/duktape-$(VERSION).tar.xz \
--user-agent crystal/duktape.cr \
--silent \
--output $@

$(TMP_DIR):
mkdir -p $@

clean:
rm -rf $(TMP_DIR)
87 changes: 39 additions & 48 deletions ext/duk_config.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* duk_config.h configuration header generated by genconfig.py.
*
* Git commit: 6001888049cb42656f8649db020e804bcdeca6a7
* Git describe: v2.5.0
* Git branch: HEAD
* Git commit: a6c488a7b8f1a6a4ba1189645c66b4ee58cbe686
* Git describe: a6c488a-dirty
* Git branch: duk/2.7.0
*
* Supported platforms:
* - Mac OSX, iPhone, Darwin
Expand Down Expand Up @@ -964,9 +964,7 @@
#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
/* No forced byteorder (both little and big endian are possible). */
#undef DUK_USE_PACKED_TVAL
#define DUK_F_PACKED_TVAL_PROVIDED
#elif defined(DUK_F_SPARC32)
Expand Down Expand Up @@ -2902,9 +2900,40 @@ typedef struct duk_hthread duk_context;
#undef DUK_USE_COMPILER_STRING
#define DUK_USE_COMPILER_STRING "crystal/llvm"

#define DUK_USE_DEBUGGER_SUPPORT
#define DUK_USE_EXEC_TIMEOUT_CHECK duk_cr_timeout
struct timeout_data {
struct timeval start;
struct timeval timeout;
};
DUK_INTERNAL_DECL duk_bool_t duk_cr_timeout(void *udata) {
if (udata) {
duk_ret_t rc;
struct timeout_data data = *(struct timeout_data*) udata;
struct timeval now;
struct timeval delta;
rc = gettimeofday(&now, NULL);

if (rc != 0) {
return 1;
}

delta.tv_sec = now.tv_sec - data.start.tv_sec;
delta.tv_usec = now.tv_usec - data.start.tv_usec;

if (delta.tv_sec > data.timeout.tv_sec) {
return 1;
} else if ((delta.tv_sec == data.timeout.tv_sec) && (delta.tv_usec > data.timeout.tv_usec)) {
return 1;
} else {
return 0;
}
} else {
return 0;
}
}

#define DUK_USE_FASTINT
#define DUK_USE_FATAL_HANDLER(udata, msg) do { const char *fatal_msg = (msg); fprintf(stderr, "*** FATAL ERROR: %s\n", fatal_msg ? fatal_msg : "no message"); fflush(stderr); *((volatile unsigned int *) 0) = (unsigned int) 0xdeadbeefUL; abort(); } while(0)
#define DUK_USE_INTERRUPT_COUNTER
#define DUK_USE_JSON_STRINGIFY_FASTPATH
#define DUK_USE_TARGET_INFO "duktape.cr"
Expand Down Expand Up @@ -2934,6 +2963,8 @@ typedef struct duk_hthread duk_context;
#define DUK_USE_CACHE_CATCHER
#define DUK_USE_CALLSTACK_LIMIT 10000
#define DUK_USE_CBOR_BUILTIN
#define DUK_USE_CBOR_DEC_RECLIMIT 1000
#define DUK_USE_CBOR_ENC_RECLIMIT 1000
#define DUK_USE_CBOR_SUPPORT
#define DUK_USE_COMPILER_RECLIMIT 2500
#define DUK_USE_COROUTINE_SUPPORT
Expand All @@ -2951,6 +2982,7 @@ typedef struct duk_hthread duk_context;
#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
Expand Down Expand Up @@ -2982,7 +3014,6 @@ typedef struct duk_hthread duk_context;
#undef DUK_USE_EXTSTR_FREE
#undef DUK_USE_EXTSTR_INTERN_CHECK
#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
Expand Down Expand Up @@ -3107,46 +3138,6 @@ typedef struct duk_hthread duk_context;
*/

/* __OVERRIDE_DEFINES__ */
/* CUSTOM: timeout function */
#define DUK_CR_USE_USER_DECLARE() \
struct timeout_data \
{ \
struct timeval start; \
struct timeval timeout; \
}; \
DUK_INTERNAL_DECL duk_bool_t duk_cr_timeout(void *udata) \
{ \
if (udata) \
{ \
duk_ret_t rc; \
struct timeout_data data = *(struct timeout_data*) udata; \
struct timeval now; \
struct timeval diff; \
rc = gettimeofday(&now, NULL); \
if (rc != 0) \
{ \
return 1; \
} \
diff.tv_sec = now.tv_sec - data.start.tv_sec; \
diff.tv_usec = now.tv_usec - data.start.tv_usec; \
if (diff.tv_sec > data.timeout.tv_sec) \
{ \
return 1; \
} \
else if ((diff.tv_sec == data.timeout.tv_sec) && (diff.tv_usec > data.timeout.tv_usec)) \
{ \
return 1; \
} \
else \
{ \
return 0; \
} \
} \
else \
{ \
return 0; \
} \
}

/*
* Conditional includes
Expand Down
Loading

0 comments on commit bf57059

Please sign in to comment.