aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AUTHORS1
-rw-r--r--src/library_browser.js12
-rw-r--r--src/library_fs.js3
-rw-r--r--src/postamble.js2
-rw-r--r--src/shell.js1
-rw-r--r--system/include/emscripten/bind.h4
-rw-r--r--system/include/emscripten/wire.h5
-rw-r--r--tests/core/test_i64_varargs.in1
-rw-r--r--tests/core/test_i64_varargs.out4
-rw-r--r--tests/embind/embind.test.js12
-rw-r--r--tests/embind/embind_test.cpp37
-rw-r--r--tests/fs/test_emptyPath.c14
-rw-r--r--tests/fs/test_emptyPath.out2
-rw-r--r--tests/test_core.py6
-rw-r--r--tests/test_other.py12
15 files changed, 104 insertions, 12 deletions
diff --git a/AUTHORS b/AUTHORS
index 5930c012..44b8e0ea 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -145,3 +145,4 @@ a license to everyone to use it as detailed in LICENSE.)
* Ningxin Hu <ningxin.hu@intel.com> (copyright owned by Intel)
* Nicolas Guillemot <nlguillemot@gmail.com>
* Sathyanarayanan Gunasekaran <gsathya.ceg@gmail.com> (copyright owned by Mozilla Foundation)
+* Nikolay Vorobyov <nik.vorobyov@gmail.com>
diff --git a/src/library_browser.js b/src/library_browser.js
index fff9387e..a3e68209 100644
--- a/src/library_browser.js
+++ b/src/library_browser.js
@@ -216,6 +216,12 @@ mergeInto(LibraryManager.library, {
// Canvas event setup
var canvas = Module['canvas'];
+ function pointerLockChange() {
+ Browser.pointerLock = document['pointerLockElement'] === canvas ||
+ document['mozPointerLockElement'] === canvas ||
+ document['webkitPointerLockElement'] === canvas ||
+ document['msPointerLockElement'] === canvas;
+ }
if (canvas) {
// forced aspect ratio can be enabled by defining 'forcedAspectRatio' on Module
// Module['forcedAspectRatio'] = 4 / 3;
@@ -232,12 +238,6 @@ mergeInto(LibraryManager.library, {
function(){}; // no-op if function does not exist
canvas.exitPointerLock = canvas.exitPointerLock.bind(document);
- function pointerLockChange() {
- Browser.pointerLock = document['pointerLockElement'] === canvas ||
- document['mozPointerLockElement'] === canvas ||
- document['webkitPointerLockElement'] === canvas ||
- document['msPointerLockElement'] === canvas;
- }
document.addEventListener('pointerlockchange', pointerLockChange, false);
document.addEventListener('mozpointerlockchange', pointerLockChange, false);
diff --git a/src/library_fs.js b/src/library_fs.js
index d825892c..a75dab97 100644
--- a/src/library_fs.js
+++ b/src/library_fs.js
@@ -932,6 +932,9 @@ mergeInto(LibraryManager.library, {
});
},
open: function(path, flags, mode, fd_start, fd_end) {
+ if (path === "") {
+ throw new FS.ErrnoError(ERRNO_CODES.ENOENT);
+ }
flags = typeof flags === 'string' ? FS.modeStringToFlags(flags) : flags;
mode = typeof mode === 'undefined' ? 438 /* 0666 */ : mode;
if ((flags & {{{ cDefine('O_CREAT') }}})) {
diff --git a/src/postamble.js b/src/postamble.js
index b90049bc..94b88d4e 100644
--- a/src/postamble.js
+++ b/src/postamble.js
@@ -56,7 +56,7 @@ Module['callMain'] = Module.callMain = function callMain(args) {
argv.push(0);
}
}
- var argv = [allocate(intArrayFromString("/bin/this.program"), 'i8', ALLOC_NORMAL) ];
+ var argv = [allocate(intArrayFromString(Module['thisProgram'] || '/bin/this.program'), 'i8', ALLOC_NORMAL) ];
pad();
for (var i = 0; i < argc-1; i = i + 1) {
argv.push(allocate(intArrayFromString(args[i]), 'i8', ALLOC_NORMAL));
diff --git a/src/shell.js b/src/shell.js
index 279a3461..85b13337 100644
--- a/src/shell.js
+++ b/src/shell.js
@@ -70,6 +70,7 @@ if (ENVIRONMENT_IS_NODE) {
globalEval(read(f));
};
+ Module['thisProgram'] = process['argv'][1];
Module['arguments'] = process['argv'].slice(2);
module['exports'] = Module;
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h
index 7bc28ff6..67e7c6a3 100644
--- a/system/include/emscripten/bind.h
+++ b/system/include/emscripten/bind.h
@@ -422,8 +422,8 @@ namespace emscripten {
namespace internal {
template<typename ClassType, typename... Args>
- ClassType* operator_new(Args... args) {
- return new ClassType(args...);
+ ClassType* operator_new(Args&&... args) {
+ return new ClassType(std::forward<Args>(args)...);
}
template<typename WrapperType, typename ClassType, typename... Args>
diff --git a/system/include/emscripten/wire.h b/system/include/emscripten/wire.h
index c20e2f55..1a9432d6 100644
--- a/system/include/emscripten/wire.h
+++ b/system/include/emscripten/wire.h
@@ -293,7 +293,6 @@ namespace emscripten {
}
};
- // Is this necessary?
template<typename T>
struct GenericBindingType<std::unique_ptr<T>> {
typedef typename BindingType<T>::WireType WireType;
@@ -301,6 +300,10 @@ namespace emscripten {
static WireType toWireType(std::unique_ptr<T> p) {
return BindingType<T>::toWireType(*p);
}
+
+ static std::unique_ptr<T> fromWireType(WireType wt) {
+ return std::unique_ptr<T>(new T(std::move(BindingType<T>::fromWireType(wt))));
+ }
};
template<typename Enum>
diff --git a/tests/core/test_i64_varargs.in b/tests/core/test_i64_varargs.in
index 7d2e4267..a0cbec64 100644
--- a/tests/core/test_i64_varargs.in
+++ b/tests/core/test_i64_varargs.in
@@ -16,6 +16,7 @@ int64_t ccv_cache_generate_signature(char *msg, int len, int64_t sig_start,
}
int main(int argc, char **argv) {
+ argv[0] = "...";
for (int i = 0; i < argc; i++) {
int64_t x;
if (i % 123123 == 0)
diff --git a/tests/core/test_i64_varargs.out b/tests/core/test_i64_varargs.out
index 8c7b7843..01832abc 100644
--- a/tests/core/test_i64_varargs.out
+++ b/tests/core/test_i64_varargs.out
@@ -1,6 +1,6 @@
-in/this.program
+.
nada
-1536
+1504
a
nada
5760
diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js
index 432202ff..f1de1a12 100644
--- a/tests/embind/embind.test.js
+++ b/tests/embind/embind.test.js
@@ -604,6 +604,18 @@ module({
c.delete();
});
+ test("can pass unique_ptr", function() {
+ var p = cm.embind_test_return_unique_ptr(42);
+ var m = cm.embind_test_accept_unique_ptr(p);
+ assert.equal(42, m);
+ });
+
+ test("can pass unique_ptr to constructor", function() {
+ var c = new cm.embind_test_construct_class_with_unique_ptr(42);
+ assert.equal(42, c.getValue());
+ c.delete();
+ });
+
test("can get member classes then call its member functions", function() {
var p = new cm.ParentClass();
var c = p.getBigClass();
diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp
index 30267994..7ac321a8 100644
--- a/tests/embind/embind_test.cpp
+++ b/tests/embind/embind_test.cpp
@@ -856,6 +856,32 @@ void emval_test_call_function(val v, int i, float f, TupleVector tv, StructVecto
v(i, f, tv, sv);
}
+class UniquePtrToConstructor {
+public:
+ UniquePtrToConstructor(std::unique_ptr<int> p)
+ : value(*p)
+ {}
+
+ int getValue() const {
+ return value;
+ }
+
+private:
+ int value;
+};
+
+std::unique_ptr<int> embind_test_return_unique_ptr(int v) {
+ return std::unique_ptr<int>(new int(v));
+}
+
+UniquePtrToConstructor* embind_test_construct_class_with_unique_ptr(int v) {
+ return new UniquePtrToConstructor(embind_test_return_unique_ptr(v));
+}
+
+int embind_test_accept_unique_ptr(std::unique_ptr<int> p) {
+ return *p.get();
+}
+
std::unique_ptr<ValHolder> emval_test_return_unique_ptr() {
return std::unique_ptr<ValHolder>(new ValHolder(val::object()));
}
@@ -1175,6 +1201,8 @@ struct AbstractClassWithConstructor {
: s(s)
{}
+ virtual ~AbstractClassWithConstructor() {};
+
virtual std::string abstractMethod() = 0;
std::string concreteMethod() {
return s;
@@ -1818,6 +1846,15 @@ EMSCRIPTEN_BINDINGS(tests) {
function("embind_test_accept_small_class_instance", &embind_test_accept_small_class_instance);
function("embind_test_accept_big_class_instance", &embind_test_accept_big_class_instance);
+ class_<UniquePtrToConstructor>("UniquePtrToConstructor")
+ .constructor<std::unique_ptr<int>>()
+ .function("getValue", &UniquePtrToConstructor::getValue)
+ ;
+
+ function("embind_test_construct_class_with_unique_ptr", embind_test_construct_class_with_unique_ptr, allow_raw_pointer<ret_val>());
+ function("embind_test_return_unique_ptr", embind_test_return_unique_ptr);
+ function("embind_test_accept_unique_ptr", embind_test_accept_unique_ptr);
+
function("embind_test_return_raw_base_ptr", embind_test_return_raw_base_ptr, allow_raw_pointer<ret_val>());
function("embind_test_return_raw_derived_ptr_as_base", embind_test_return_raw_derived_ptr_as_base, allow_raw_pointer<ret_val>());
function("embind_test_return_raw_sibling_derived_ptr_as_base", embind_test_return_raw_sibling_derived_ptr_as_base, allow_raw_pointer<ret_val>());
diff --git a/tests/fs/test_emptyPath.c b/tests/fs/test_emptyPath.c
new file mode 100644
index 00000000..27d56ea1
--- /dev/null
+++ b/tests/fs/test_emptyPath.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+int main() {
+ FILE* f1 = fopen("s", "r");
+ if (f1 == NULL) {
+ printf("file 's' not found!\n");
+ }
+
+ FILE* f2 = fopen("", "r");
+ if (f2 == NULL) {
+ printf("file '' not found!\n");
+ }
+ return 0;
+}
diff --git a/tests/fs/test_emptyPath.out b/tests/fs/test_emptyPath.out
new file mode 100644
index 00000000..78352877
--- /dev/null
+++ b/tests/fs/test_emptyPath.out
@@ -0,0 +1,2 @@
+file 's' not found!
+file '' not found!
diff --git a/tests/test_core.py b/tests/test_core.py
index 08e3594e..137e5e4a 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -4348,6 +4348,12 @@ def process(filename):
out = path_from_root('tests', 'fs', 'test_writeFile.out')
self.do_run_from_file(src, out)
+ def test_fs_emptyPath(self):
+ if self.emcc_args is None: return self.skip('requires emcc')
+ src = path_from_root('tests', 'fs', 'test_emptyPath.c')
+ out = path_from_root('tests', 'fs', 'test_emptyPath.out')
+ self.do_run_from_file(src, out)
+
def test_fs_append(self):
if self.emcc_args is None: return self.skip('requires emcc')
src = open(path_from_root('tests', 'fs', 'test_append.c'), 'r').read()
diff --git a/tests/test_other.py b/tests/test_other.py
index 14c3f00b..4fb90b1a 100644
--- a/tests/test_other.py
+++ b/tests/test_other.py
@@ -2892,3 +2892,15 @@ int main(int argc, char **argv) {
Popen([PYTHON, EMCC, 'src.cpp']).communicate()
self.assertContained('read: 0\nfile size is 104\n', run_js('a.out.js'))
+ def test_argv0_node(self):
+ open('code.cpp', 'w').write(r'''
+#include <stdio.h>
+int main(int argc, char **argv) {
+ printf("I am %s.\n", argv[0]);
+ return 0;
+}
+''')
+
+ Popen([PYTHON, EMCC, 'code.cpp']).communicate()
+ self.assertContained('I am ' + self.get_dir().replace('\\', '/') + '/a.out.js', run_js('a.out.js', engine=NODE_JS).replace('\\', '/'))
+