mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-11-24 06:33:33 +03:00
Speed up Travis by running Webpack in fewer tests (#381)
* Reorganize Travis configuration * Add a `JOB` env var descriptor to all matrix entries. Not used anywhere but is useful when viewing the whole build on Travis's web interface. * Reorganize where builds are located, moving slow builds first and fast ones last. * Change checking the CLI builds from `cargo build` to `cargo check` * Use YAML references to reduce some duplication * Print some more timing statistics for each test * Extract `Project` helper in tests to a module This'll help make it a bit more extensible over time. At the same time the methods are also slightly reorganized to read more clearly from top to bottom. * Migrate all tests away from Webpack Wepback can take a significant amount of time to execute and when it's multiplied by hundreds of tests that adds up really quickly! After investigating Node's `--experimental-modules` option it looks like it's suitable for our use so this switches all tests to using JS files (moving away from TypeScript as well) with `--experimental-modules` with Node. Tests will be selectively re-enabled with webpack and node.js specific output (that doesn't require `--experimental-modules`), coming in later commits. * Restore the node test for node.js output Ensures it's workable as-is * Only generate typescript with webpack * Only read wasm files for webpack * Skip package.json/node_modules for now * Only generate webpack config if needed * Start a dedicated test module for typescript Will hopefully verify the generated Typescript compiles OK. * Remove unneeded `node` method * Fixup some rebase conflicts * Don't run asmjs example on travis * Fixup generator tests * Attempt to fix windows * Comment windows fix * More test fixes * More exclusions * More test fixes * Relax eslint regex Catch mjs modules as well * Fix eslint * Speed up travis on examples slightly
This commit is contained in:
parent
e912b9d2a2
commit
efa4a2b8fa
@ -6,6 +6,7 @@ module.exports = {
|
||||
node: true
|
||||
},
|
||||
extends: 'eslint:recommended',
|
||||
parser: 'babel-eslint',
|
||||
parserOptions: {
|
||||
sourceType: 'module'
|
||||
},
|
||||
|
146
.travis.yml
146
.travis.yml
@ -1,20 +1,38 @@
|
||||
language: rust
|
||||
sudo: false
|
||||
|
||||
INSTALL_NODE_VIA_NVM: &INSTALL_NODE_VIA_NVM
|
||||
- rustup target add wasm32-unknown-unknown
|
||||
- curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
|
||||
- source ~/.nvm/nvm.sh
|
||||
- nvm install v10.5
|
||||
|
||||
|
||||
DEPLOY_TO_GITHUB: &DEPLOY_TO_GITHUB
|
||||
before_deploy:
|
||||
|
|
||||
name="wasm-bindgen-$TRAVIS_TAG-$TARGET"
|
||||
mkdir "$name"
|
||||
cp "target/$TARGET/release/{wasm-bindgen,wasm2es6js}" "$name/"
|
||||
cp README.md LICENSE-MIT LICENSE-APACHE "$name/"
|
||||
tar czvf "$name.tar.gz" "$name"
|
||||
deploy:
|
||||
api_key:
|
||||
secure: "qCiELnEnvyKpWHDttgTNf+ElZGbWlvthu5aOIj5nYfov+h6g1+mkWnDFP6at/WPlE78zE/f/z/dL2KB2I7w/cxH/T4P1nWh0A9DvrpY6hqWkK2pgN5dPeWE/a4flI7AdH0A6wMRw7m00uMgDjlzN78v7XueccpJCxSO5allQN5jweAQvMX2QA07TbLRJc7Lq6lfVwSf8OfrcO8qCbcIzJTsC4vtbh6jkUYg1OAaU2tAYlskBy9ZYmHWCExIAu/zxzcJY9OpApPD9Ea4CyrsfjniAyRBJ87Weh/sP4XhiWeRPVmvA4HAzv4Pps9ps+Ar5QmsX53rhKQ3id7/VPR8ggaAHxrYUiJPvJRtbP6cKKOlDiK0ooP+vI4vjxWeNVj9ibEolSYOlT0ENIvPK1BppA6VgAoJOjwPr0Q16Ma4AmvLkIkowJiXCm2Jlje/5c0vPEAGJVgUtkj3jFQzgXwyEMpzxUlhHmYpmnfeaM0tK/Kiiwe1monL/ydMlyfV55kNylylCg+XoTnf420AFChKbD4DM5Z7ZsjU9g8fF3LUoN0sKpmLDp+GvwjLi9YtGogWB71Q2MFp43MSL0YLshkyYYoZKrVMiy5J9hKNUxhT2jNEq53Z69syIHHMCxHL9GoAcuHxIKOA7uTMW0aCoyy2I+dfAKKsrUGwGYaNC5LZdUQI="
|
||||
file_glob: true
|
||||
file:
|
||||
- wasm-bindgen-$TRAVIS_TAG-$TARGET.tar.gz
|
||||
on:
|
||||
tags: true
|
||||
provider: releases
|
||||
skip_cleanup: true
|
||||
|
||||
matrix:
|
||||
include:
|
||||
# CLI builds on stable
|
||||
- rust: stable
|
||||
install: true
|
||||
script: cargo build --manifest-path crates/cli/Cargo.toml
|
||||
|
||||
# Tests pass on nightly
|
||||
- rust: nightly
|
||||
before_install:
|
||||
- rustup target add wasm32-unknown-unknown
|
||||
- curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
|
||||
- source ~/.nvm/nvm.sh
|
||||
- nvm install v10.5
|
||||
env: JOB=test-bindgen
|
||||
before_install: *INSTALL_NODE_VIA_NVM
|
||||
install:
|
||||
# dirties git repository, there doesn't seem to be a way to resolve this other than
|
||||
# to run `npm install` twice or by using `npm ci` (which is currently broken)
|
||||
@ -22,82 +40,68 @@ matrix:
|
||||
script:
|
||||
- cargo test
|
||||
# Check JS output from all tests against eslint
|
||||
- ./node_modules/.bin/eslint ./target/generated-tests/*/out*.js
|
||||
env: RUST_BACKTRACE=1
|
||||
- ./node_modules/.bin/eslint ./target/generated-tests/*/out*js
|
||||
|
||||
# All examples work
|
||||
- rust: nightly
|
||||
env: JOB=examples-build
|
||||
install: *INSTALL_NODE_VIA_NVM
|
||||
script:
|
||||
- mkdir node_modules
|
||||
- |
|
||||
for dir in `ls examples | grep -v README | grep -v asm.js | grep -v no_modules`; do
|
||||
(cd examples/$dir &&
|
||||
sed -i 's/: "webpack-dev-server"/: "webpack"/' package.json &&
|
||||
ln -s ../../node_modules . &&
|
||||
./build.sh) || exit 1;
|
||||
done
|
||||
|
||||
# Tests pass on nightly using yarn
|
||||
- rust: nightly
|
||||
before_install:
|
||||
- rustup target add wasm32-unknown-unknown
|
||||
- curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
|
||||
- source ~/.nvm/nvm.sh
|
||||
- nvm install v10.5
|
||||
env: JOB=test-yarn-smoke
|
||||
before_install: *INSTALL_NODE_VIA_NVM
|
||||
install:
|
||||
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.7.0
|
||||
- export PATH=$HOME/.yarn/bin:$PATH
|
||||
install:
|
||||
- yarn install --freeze-lockfile
|
||||
script:
|
||||
- cargo test
|
||||
# Check JS output from all tests against eslint
|
||||
- ./node_modules/.bin/eslint ./target/generated-tests/*/out*.js
|
||||
env: RUST_BACKTRACE=1
|
||||
script: cargo test api::works
|
||||
|
||||
# WebIDL tests pass on nightly
|
||||
- rust: nightly
|
||||
env: JOB=test-webidl
|
||||
before_install: rustup component add rustfmt-preview --toolchain nightly
|
||||
script: (cd crates/webidl && cargo test)
|
||||
env: RUST_BACKTRACE=1 RUST_LOG=wasm_bindgen_webidl
|
||||
script: cargo test --manifest-path crates/webidl/Cargo.toml
|
||||
|
||||
# Dist linux binary
|
||||
- env: TARGET=x86_64-unknown-linux-musl DEPLOY=1
|
||||
rust: nightly
|
||||
- rust: nightly
|
||||
env: JOB=dist-linux TARGET=x86_64-unknown-linux-musl
|
||||
before_script: rustup target add $TARGET
|
||||
script: cargo build --manifest-path crates/cli/Cargo.toml --release --target $TARGET
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- musl-tools
|
||||
<<: *DEPLOY_TO_GITHUB
|
||||
|
||||
# Dist OSX binary
|
||||
- os: osx
|
||||
rust: nightly
|
||||
env: MACOSX_DEPLOYMENT_TARGET=10.7 DEPLOY=1 TARGET=x86_64-apple-darwin
|
||||
- rust: nightly
|
||||
os: osx
|
||||
env: JOB=dist-osx MACOSX_DEPLOYMENT_TARGET=10.7 TARGET=x86_64-apple-darwin
|
||||
script: cargo build --manifest-path crates/cli/Cargo.toml --release --target $TARGET
|
||||
install: true
|
||||
<<: *DEPLOY_TO_GITHUB
|
||||
|
||||
# We can build the tool on nightly
|
||||
# CLI builds on stable
|
||||
- rust: stable
|
||||
env: JOB=check-stable-cli
|
||||
script: cargo check --manifest-path crates/cli/Cargo.toml
|
||||
# CLI builds on nightly
|
||||
- rust: nightly
|
||||
script: cargo install --debug --path crates/cli
|
||||
|
||||
# All examples work
|
||||
- rust: nightly
|
||||
before_install:
|
||||
- rustup target add wasm32-unknown-unknown
|
||||
- curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
|
||||
- source ~/.nvm/nvm.sh
|
||||
- nvm install v10.5
|
||||
script:
|
||||
- |
|
||||
(cd examples/hello_world && sed -i 's/: "webpack-dev-server"/: "webpack"/' package.json && ./build.sh)
|
||||
- |
|
||||
(cd examples/smorgasboard && sed -i 's/: "webpack-dev-server"/: "webpack"/' package.json && ./build.sh)
|
||||
- |
|
||||
(cd examples/console_log && sed -i 's/: "webpack-dev-server"/: "webpack"/' package.json && ./build.sh)
|
||||
- |
|
||||
(cd examples/math && sed -i 's/: "webpack-dev-server"/: "webpack"/' package.json && ./build.sh)
|
||||
- |
|
||||
(cd examples/dom && sed -i 's/: "webpack-dev-server"/: "webpack"/' package.json && ./build.sh)
|
||||
- |
|
||||
(cd examples/wasm-in-wasm && sed -i 's/: "webpack-dev-server"/: "webpack"/' package.json && ./build.sh)
|
||||
- |
|
||||
(cd examples/char && sed -i 's/: "webpack-dev-server"/: "webpack"/' package.json && ./build.sh)
|
||||
- |
|
||||
(cd examples/closures && sed -i 's/: "webpack-dev-server"/: "webpack"/' package.json && ./build.sh)
|
||||
- |
|
||||
(cd examples/comments && sed -i 's/: "webpack-dev-server"/: "webpack"/' package.json && ./build.sh)
|
||||
env: JOB=check-nightly-cli
|
||||
script: cargo check --manifest-path crates/cli/Cargo.toml
|
||||
|
||||
# Build the guide.
|
||||
- rust: stable
|
||||
env: JOB=guide-build-and-deploy
|
||||
cache:
|
||||
- cargo
|
||||
before_script:
|
||||
@ -119,25 +123,3 @@ matrix:
|
||||
notifications:
|
||||
email:
|
||||
on_success: never
|
||||
|
||||
before_deploy:
|
||||
|
|
||||
if [[ "$DEPLOY" == "1" ]]; then
|
||||
name="wasm-bindgen-$TRAVIS_TAG-$TARGET"
|
||||
mkdir "$name"
|
||||
cp "target/$TARGET/release/{wasm-bindgen,wasm2es6js}" "$name/"
|
||||
cp README.md LICENSE-MIT LICENSE-APACHE "$name/"
|
||||
tar czvf "$name.tar.gz" "$name"
|
||||
fi
|
||||
|
||||
deploy:
|
||||
api_key:
|
||||
secure: "qCiELnEnvyKpWHDttgTNf+ElZGbWlvthu5aOIj5nYfov+h6g1+mkWnDFP6at/WPlE78zE/f/z/dL2KB2I7w/cxH/T4P1nWh0A9DvrpY6hqWkK2pgN5dPeWE/a4flI7AdH0A6wMRw7m00uMgDjlzN78v7XueccpJCxSO5allQN5jweAQvMX2QA07TbLRJc7Lq6lfVwSf8OfrcO8qCbcIzJTsC4vtbh6jkUYg1OAaU2tAYlskBy9ZYmHWCExIAu/zxzcJY9OpApPD9Ea4CyrsfjniAyRBJ87Weh/sP4XhiWeRPVmvA4HAzv4Pps9ps+Ar5QmsX53rhKQ3id7/VPR8ggaAHxrYUiJPvJRtbP6cKKOlDiK0ooP+vI4vjxWeNVj9ibEolSYOlT0ENIvPK1BppA6VgAoJOjwPr0Q16Ma4AmvLkIkowJiXCm2Jlje/5c0vPEAGJVgUtkj3jFQzgXwyEMpzxUlhHmYpmnfeaM0tK/Kiiwe1monL/ydMlyfV55kNylylCg+XoTnf420AFChKbD4DM5Z7ZsjU9g8fF3LUoN0sKpmLDp+GvwjLi9YtGogWB71Q2MFp43MSL0YLshkyYYoZKrVMiy5J9hKNUxhT2jNEq53Z69syIHHMCxHL9GoAcuHxIKOA7uTMW0aCoyy2I+dfAKKsrUGwGYaNC5LZdUQI="
|
||||
file_glob: true
|
||||
file:
|
||||
- wasm-bindgen-$TRAVIS_TAG-$TARGET.tar.gz
|
||||
on:
|
||||
condition: $DEPLOY = 1
|
||||
tags: true
|
||||
provider: releases
|
||||
skip_cleanup: true
|
||||
|
@ -60,7 +60,7 @@ impl<'a> Context<'a> {
|
||||
if let Some(ref c) = comments {
|
||||
self.globals.push_str(c);
|
||||
}
|
||||
let global = if self.config.nodejs {
|
||||
let global = if self.use_node_require() {
|
||||
if contents.starts_with("class") {
|
||||
format!("{1}\nmodule.exports.{0} = {0};\n", name, contents)
|
||||
} else {
|
||||
@ -412,12 +412,12 @@ impl<'a> Context<'a> {
|
||||
} else {
|
||||
let import_wasm = if self.globals.len() == 0 {
|
||||
String::new()
|
||||
} else if self.config.nodejs {
|
||||
} else if self.use_node_require() {
|
||||
self.footer
|
||||
.push_str(&format!("wasm = require('./{}_bg');", module_name));
|
||||
format!("var wasm;")
|
||||
} else {
|
||||
format!("import * as wasm from './{}_bg.wasm';", module_name)
|
||||
format!("import * as wasm from './{}_bg';", module_name)
|
||||
};
|
||||
|
||||
format!(
|
||||
@ -977,7 +977,9 @@ impl<'a> Context<'a> {
|
||||
if !self.exposed_globals.insert("text_encoder") {
|
||||
return;
|
||||
}
|
||||
if self.config.nodejs {
|
||||
if self.config.nodejs_experimental_modules {
|
||||
self.imports.push_str("import { TextEncoder } from 'util';\n");
|
||||
} else if self.config.nodejs {
|
||||
self.global(
|
||||
"
|
||||
const TextEncoder = require('util').TextEncoder;
|
||||
@ -1003,7 +1005,9 @@ impl<'a> Context<'a> {
|
||||
if !self.exposed_globals.insert("text_decoder") {
|
||||
return;
|
||||
}
|
||||
if self.config.nodejs {
|
||||
if self.config.nodejs_experimental_modules {
|
||||
self.imports.push_str("import { TextDecoder } from 'util';\n");
|
||||
} else if self.config.nodejs {
|
||||
self.global(
|
||||
"
|
||||
const TextDecoder = require('util').TextDecoder;
|
||||
@ -1585,6 +1589,10 @@ impl<'a> Context<'a> {
|
||||
*section.payload_mut() = contents.into_bytes();
|
||||
self.module.sections_mut().push(Section::Custom(section));
|
||||
}
|
||||
|
||||
fn use_node_require(&self) -> bool {
|
||||
self.config.nodejs && !self.config.nodejs_experimental_modules
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> SubContext<'a, 'b> {
|
||||
@ -1944,7 +1952,7 @@ impl<'a, 'b> SubContext<'a, 'b> {
|
||||
let name = import.js_namespace.as_ref().map(|s| &**s).unwrap_or(item);
|
||||
|
||||
if self.cx.imported_names.insert(name.to_string()) {
|
||||
if self.cx.config.nodejs {
|
||||
if self.cx.use_node_require() {
|
||||
self.cx.imports.push_str(&format!(
|
||||
"\
|
||||
const {} = require('{}').{};\n\
|
||||
|
@ -24,6 +24,7 @@ pub mod wasm2es6js;
|
||||
pub struct Bindgen {
|
||||
path: Option<PathBuf>,
|
||||
nodejs: bool,
|
||||
nodejs_experimental_modules: bool,
|
||||
browser: bool,
|
||||
no_modules: bool,
|
||||
no_modules_global: Option<String>,
|
||||
@ -37,6 +38,7 @@ impl Bindgen {
|
||||
Bindgen {
|
||||
path: None,
|
||||
nodejs: false,
|
||||
nodejs_experimental_modules: false,
|
||||
browser: false,
|
||||
no_modules: false,
|
||||
no_modules_global: None,
|
||||
@ -56,6 +58,11 @@ impl Bindgen {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn nodejs_experimental_modules(&mut self, node: bool) -> &mut Bindgen {
|
||||
self.nodejs_experimental_modules = node;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn browser(&mut self, browser: bool) -> &mut Bindgen {
|
||||
self.browser = browser;
|
||||
self
|
||||
@ -162,7 +169,8 @@ impl Bindgen {
|
||||
cx.finalize(stem)?
|
||||
};
|
||||
|
||||
let js_path = out_dir.join(stem).with_extension("js");
|
||||
let extension = if self.nodejs_experimental_modules { "mjs" } else { "js" };
|
||||
let js_path = out_dir.join(stem).with_extension(extension);
|
||||
File::create(&js_path)
|
||||
.and_then(|mut f| f.write_all(reset_indentation(&js).as_bytes()))
|
||||
.with_context(|_| format!("failed to write `{}`", js_path.display()))?;
|
||||
@ -177,7 +185,7 @@ impl Bindgen {
|
||||
let wasm_path = out_dir.join(format!("{}_bg", stem)).with_extension("wasm");
|
||||
|
||||
if self.nodejs {
|
||||
let js_path = wasm_path.with_extension("js");
|
||||
let js_path = wasm_path.with_extension(extension);
|
||||
let shim = self.generate_node_wasm_import(&module, &wasm_path);
|
||||
File::create(&js_path)
|
||||
.and_then(|mut f| f.write_all(shim.as_bytes()))
|
||||
@ -200,22 +208,62 @@ impl Bindgen {
|
||||
}
|
||||
|
||||
let mut shim = String::new();
|
||||
|
||||
if self.nodejs_experimental_modules {
|
||||
for (i, module) in imports.iter().enumerate() {
|
||||
shim.push_str(&format!("import * as import{} from '{}';\n",
|
||||
i, module));
|
||||
}
|
||||
// On windows skip the leading `/` which comes out when we parse a
|
||||
// url to use `C:\...` instead of `\C:\...`
|
||||
shim.push_str(&format!("
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import * as url from 'url';
|
||||
import * as process from 'process';
|
||||
|
||||
let file = path.dirname(url.parse(import.meta.url).pathname);
|
||||
if (process.platform === 'win32') {{
|
||||
file = file.substring(1);
|
||||
}}
|
||||
const bytes = fs.readFileSync(path.join(file, '{}'));
|
||||
", path.file_name().unwrap().to_str().unwrap()));
|
||||
} else {
|
||||
shim.push_str(&format!("
|
||||
const path = require('path').join(__dirname, '{}');
|
||||
const bytes = require('fs').readFileSync(path);
|
||||
", path.file_name().unwrap().to_str().unwrap()));
|
||||
}
|
||||
shim.push_str("let imports = {};\n");
|
||||
for module in imports {
|
||||
shim.push_str(&format!("imports['{0}'] = require('{0}');\n", module));
|
||||
for (i, module) in imports.iter().enumerate() {
|
||||
if self.nodejs_experimental_modules {
|
||||
shim.push_str(&format!("imports['{}'] = import{};\n", module, i));
|
||||
} else {
|
||||
shim.push_str(&format!("imports['{0}'] = require('{0}');\n", module));
|
||||
}
|
||||
}
|
||||
|
||||
shim.push_str(&format!(
|
||||
"
|
||||
const join = require('path').join;
|
||||
const bytes = require('fs').readFileSync(join(__dirname, '{}'));
|
||||
const wasmModule = new WebAssembly.Module(bytes);
|
||||
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
|
||||
module.exports = wasmInstance.exports;
|
||||
const wasmModule = new WebAssembly.Module(bytes);
|
||||
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
|
||||
",
|
||||
path.file_name().unwrap().to_str().unwrap()
|
||||
));
|
||||
|
||||
if self.nodejs_experimental_modules {
|
||||
if let Some(e) = m.export_section() {
|
||||
for name in e.entries().iter().map(|e| e.field()) {
|
||||
shim.push_str("export const ");
|
||||
shim.push_str(name);
|
||||
shim.push_str(" = wasmInstance.exports.");
|
||||
shim.push_str(name);
|
||||
shim.push_str(";\n");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
shim.push_str("module.exports = wasmInstance.exports;\n");
|
||||
}
|
||||
|
||||
reset_indentation(&shim)
|
||||
}
|
||||
}
|
||||
|
517
package-lock.json
generated
517
package-lock.json
generated
@ -2,6 +2,156 @@
|
||||
"requires": true,
|
||||
"lockfileVersion": 1,
|
||||
"dependencies": {
|
||||
"@babel/code-frame": {
|
||||
"version": "7.0.0-beta.44",
|
||||
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0-beta.44.tgz",
|
||||
"integrity": "sha512-cuAuTTIQ9RqcFRJ/Y8PvTh+paepNcaGxwQwjIDRWPXmzzyAeCO4KqS9ikMvq0MCbRk6GlYKwfzStrcP3/jSL8g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/highlight": "7.0.0-beta.44"
|
||||
}
|
||||
},
|
||||
"@babel/generator": {
|
||||
"version": "7.0.0-beta.44",
|
||||
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.0.0-beta.44.tgz",
|
||||
"integrity": "sha512-5xVb7hlhjGcdkKpMXgicAVgx8syK5VJz193k0i/0sLP6DzE6lRrU1K3B/rFefgdo9LPGMAOOOAWW4jycj07ShQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/types": "7.0.0-beta.44",
|
||||
"jsesc": "^2.5.1",
|
||||
"lodash": "^4.2.0",
|
||||
"source-map": "^0.5.0",
|
||||
"trim-right": "^1.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"jsesc": {
|
||||
"version": "2.5.1",
|
||||
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.1.tgz",
|
||||
"integrity": "sha1-5CGiqOINawgZ3yiQj3glJrlt0f4=",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"@babel/helper-function-name": {
|
||||
"version": "7.0.0-beta.44",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.0.0-beta.44.tgz",
|
||||
"integrity": "sha512-MHRG2qZMKMFaBavX0LWpfZ2e+hLloT++N7rfM3DYOMUOGCD8cVjqZpwiL8a0bOX3IYcQev1ruciT0gdFFRTxzg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/helper-get-function-arity": "7.0.0-beta.44",
|
||||
"@babel/template": "7.0.0-beta.44",
|
||||
"@babel/types": "7.0.0-beta.44"
|
||||
}
|
||||
},
|
||||
"@babel/helper-get-function-arity": {
|
||||
"version": "7.0.0-beta.44",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helper-get-function-arity/-/helper-get-function-arity-7.0.0-beta.44.tgz",
|
||||
"integrity": "sha512-w0YjWVwrM2HwP6/H3sEgrSQdkCaxppqFeJtAnB23pRiJB5E/O9Yp7JAAeWBl+gGEgmBFinnTyOv2RN7rcSmMiw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/types": "7.0.0-beta.44"
|
||||
}
|
||||
},
|
||||
"@babel/helper-split-export-declaration": {
|
||||
"version": "7.0.0-beta.44",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.0.0-beta.44.tgz",
|
||||
"integrity": "sha512-aQ7QowtkgKKzPGf0j6u77kBMdUFVBKNHw2p/3HX/POt5/oz8ec5cs0GwlgM8Hz7ui5EwJnzyfRmkNF1Nx1N7aA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/types": "7.0.0-beta.44"
|
||||
}
|
||||
},
|
||||
"@babel/highlight": {
|
||||
"version": "7.0.0-beta.44",
|
||||
"resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.0.0-beta.44.tgz",
|
||||
"integrity": "sha512-Il19yJvy7vMFm8AVAh6OZzaFoAd0hbkeMZiX3P5HGD+z7dyI7RzndHB0dg6Urh/VAFfHtpOIzDUSxmY6coyZWQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"chalk": "^2.0.0",
|
||||
"esutils": "^2.0.2",
|
||||
"js-tokens": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"@babel/template": {
|
||||
"version": "7.0.0-beta.44",
|
||||
"resolved": "https://registry.npmjs.org/@babel/template/-/template-7.0.0-beta.44.tgz",
|
||||
"integrity": "sha512-w750Sloq0UNifLx1rUqwfbnC6uSUk0mfwwgGRfdLiaUzfAOiH0tHJE6ILQIUi3KYkjiCDTskoIsnfqZvWLBDng==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/code-frame": "7.0.0-beta.44",
|
||||
"@babel/types": "7.0.0-beta.44",
|
||||
"babylon": "7.0.0-beta.44",
|
||||
"lodash": "^4.2.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"babylon": {
|
||||
"version": "7.0.0-beta.44",
|
||||
"resolved": "https://registry.npmjs.org/babylon/-/babylon-7.0.0-beta.44.tgz",
|
||||
"integrity": "sha512-5Hlm13BJVAioCHpImtFqNOF2H3ieTOHd0fmFGMxOJ9jgeFqeAwsv3u5P5cR7CSeFrkgHsT19DgFJkHV0/Mcd8g==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"@babel/traverse": {
|
||||
"version": "7.0.0-beta.44",
|
||||
"resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.0.0-beta.44.tgz",
|
||||
"integrity": "sha512-UHuDz8ukQkJCDASKHf+oDt3FVUzFd+QYfuBIsiNu/4+/ix6pP/C+uQZJ6K1oEfbCMv/IKWbgDEh7fcsnIE5AtA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/code-frame": "7.0.0-beta.44",
|
||||
"@babel/generator": "7.0.0-beta.44",
|
||||
"@babel/helper-function-name": "7.0.0-beta.44",
|
||||
"@babel/helper-split-export-declaration": "7.0.0-beta.44",
|
||||
"@babel/types": "7.0.0-beta.44",
|
||||
"babylon": "7.0.0-beta.44",
|
||||
"debug": "^3.1.0",
|
||||
"globals": "^11.1.0",
|
||||
"invariant": "^2.2.0",
|
||||
"lodash": "^4.2.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"babylon": {
|
||||
"version": "7.0.0-beta.44",
|
||||
"resolved": "https://registry.npmjs.org/babylon/-/babylon-7.0.0-beta.44.tgz",
|
||||
"integrity": "sha512-5Hlm13BJVAioCHpImtFqNOF2H3ieTOHd0fmFGMxOJ9jgeFqeAwsv3u5P5cR7CSeFrkgHsT19DgFJkHV0/Mcd8g==",
|
||||
"dev": true
|
||||
},
|
||||
"debug": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
|
||||
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"globals": {
|
||||
"version": "11.7.0",
|
||||
"resolved": "https://registry.npmjs.org/globals/-/globals-11.7.0.tgz",
|
||||
"integrity": "sha512-K8BNSPySfeShBQXsahYB/AbbWruVOTyVpgoIDnl8odPpeSfP2J5QO2oLFFdl2j7GfDCtZj2bMKar2T49itTPCg==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"@babel/types": {
|
||||
"version": "7.0.0-beta.44",
|
||||
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.0.0-beta.44.tgz",
|
||||
"integrity": "sha512-5eTV4WRmqbaFM3v9gHAIljEQJU4Ssc6fxL61JN+Oe2ga/BwyjzjamwkCVVAQjHGuAX8i0BWo42dshL8eO5KfLQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"esutils": "^2.0.2",
|
||||
"lodash": "^4.2.0",
|
||||
"to-fast-properties": "^2.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"to-fast-properties": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",
|
||||
"integrity": "sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"@mrmlnc/readdir-enhanced": {
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz",
|
||||
@ -294,20 +444,12 @@
|
||||
}
|
||||
},
|
||||
"acorn-jsx": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-3.0.1.tgz",
|
||||
"integrity": "sha1-r9+UiPsezvyDSPb7IvRk4ypYs2s=",
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-4.1.1.tgz",
|
||||
"integrity": "sha512-JY+iV6r+cO21KtntVvFkD+iqjtdpRUpGqKWgfkCdZq1R+kbreEl8EcdcJR4SmiIgsIQT33s6QzheQ9a275Q8xw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"acorn": "^3.0.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"acorn": {
|
||||
"version": "3.3.0",
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-3.3.0.tgz",
|
||||
"integrity": "sha1-ReN/s56No/JbruP/U2niu18iAXo=",
|
||||
"dev": true
|
||||
}
|
||||
"acorn": "^5.0.3"
|
||||
}
|
||||
},
|
||||
"ajv": {
|
||||
@ -586,6 +728,28 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"babel-eslint": {
|
||||
"version": "8.2.5",
|
||||
"resolved": "https://registry.npmjs.org/babel-eslint/-/babel-eslint-8.2.5.tgz",
|
||||
"integrity": "sha512-TcdEGCHHquOPQOlH6Fe6MLwPWWWJLdeKhcGoLfOTShETpoH8XYWhjWJw38KCKaTca7c/EdxLolnbakixKxnXDg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/code-frame": "7.0.0-beta.44",
|
||||
"@babel/traverse": "7.0.0-beta.44",
|
||||
"@babel/types": "7.0.0-beta.44",
|
||||
"babylon": "7.0.0-beta.44",
|
||||
"eslint-scope": "~3.7.1",
|
||||
"eslint-visitor-keys": "^1.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"babylon": {
|
||||
"version": "7.0.0-beta.44",
|
||||
"resolved": "https://registry.npmjs.org/babylon/-/babylon-7.0.0-beta.44.tgz",
|
||||
"integrity": "sha512-5Hlm13BJVAioCHpImtFqNOF2H3ieTOHd0fmFGMxOJ9jgeFqeAwsv3u5P5cR7CSeFrkgHsT19DgFJkHV0/Mcd8g==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"babel-generator": {
|
||||
"version": "6.26.1",
|
||||
"resolved": "https://registry.npmjs.org/babel-generator/-/babel-generator-6.26.1.tgz",
|
||||
@ -1920,12 +2084,6 @@
|
||||
"readable-stream": "^2.3.5"
|
||||
}
|
||||
},
|
||||
"co": {
|
||||
"version": "4.6.0",
|
||||
"resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz",
|
||||
"integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=",
|
||||
"dev": true
|
||||
},
|
||||
"code-point-at": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz",
|
||||
@ -2193,6 +2351,16 @@
|
||||
"integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=",
|
||||
"dev": true
|
||||
},
|
||||
"define-properties": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.2.tgz",
|
||||
"integrity": "sha1-g6c/L+pWmJj7c3GTyPhzyvbUXJQ=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"foreach": "^2.0.5",
|
||||
"object-keys": "^1.0.8"
|
||||
}
|
||||
},
|
||||
"define-property": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/define-property/-/define-property-2.0.2.tgz",
|
||||
@ -2449,6 +2617,30 @@
|
||||
"is-arrayish": "^0.2.1"
|
||||
}
|
||||
},
|
||||
"es-abstract": {
|
||||
"version": "1.12.0",
|
||||
"resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.12.0.tgz",
|
||||
"integrity": "sha512-C8Fx/0jFmV5IPoMOFPA9P9G5NtqW+4cOPit3MIuvR2t7Ag2K15EJTpxnHAYTzL+aYQJIESYeXZmDBfOBE1HcpA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"es-to-primitive": "^1.1.1",
|
||||
"function-bind": "^1.1.1",
|
||||
"has": "^1.0.1",
|
||||
"is-callable": "^1.1.3",
|
||||
"is-regex": "^1.0.4"
|
||||
}
|
||||
},
|
||||
"es-to-primitive": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.1.1.tgz",
|
||||
"integrity": "sha1-RTVSSKiJeQNLZ5Lhm7gfK3l13Q0=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"is-callable": "^1.1.1",
|
||||
"is-date-object": "^1.0.1",
|
||||
"is-symbol": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"escape-string-regexp": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
|
||||
@ -2456,74 +2648,51 @@
|
||||
"dev": true
|
||||
},
|
||||
"eslint": {
|
||||
"version": "4.19.1",
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-4.19.1.tgz",
|
||||
"integrity": "sha512-bT3/1x1EbZB7phzYu7vCr1v3ONuzDtX8WjuM9c0iYxe+cq+pwcKEoQjl7zd3RpC6YOLgnSy3cTN58M2jcoPDIQ==",
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-5.0.1.tgz",
|
||||
"integrity": "sha512-D5nG2rErquLUstgUaxJlWB5+gu+U/3VDY0fk/Iuq8y9CUFy/7Y6oF4N2cR1tV8knzQvciIbfqfohd359xTLIKQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ajv": "^5.3.0",
|
||||
"babel-code-frame": "^6.22.0",
|
||||
"ajv": "^6.5.0",
|
||||
"babel-code-frame": "^6.26.0",
|
||||
"chalk": "^2.1.0",
|
||||
"concat-stream": "^1.6.0",
|
||||
"cross-spawn": "^5.1.0",
|
||||
"cross-spawn": "^6.0.5",
|
||||
"debug": "^3.1.0",
|
||||
"doctrine": "^2.1.0",
|
||||
"eslint-scope": "^3.7.1",
|
||||
"eslint-scope": "^4.0.0",
|
||||
"eslint-visitor-keys": "^1.0.0",
|
||||
"espree": "^3.5.4",
|
||||
"esquery": "^1.0.0",
|
||||
"espree": "^4.0.0",
|
||||
"esquery": "^1.0.1",
|
||||
"esutils": "^2.0.2",
|
||||
"file-entry-cache": "^2.0.0",
|
||||
"functional-red-black-tree": "^1.0.1",
|
||||
"glob": "^7.1.2",
|
||||
"globals": "^11.0.1",
|
||||
"globals": "^11.5.0",
|
||||
"ignore": "^3.3.3",
|
||||
"imurmurhash": "^0.1.4",
|
||||
"inquirer": "^3.0.6",
|
||||
"is-resolvable": "^1.0.0",
|
||||
"js-yaml": "^3.9.1",
|
||||
"inquirer": "^5.2.0",
|
||||
"is-resolvable": "^1.1.0",
|
||||
"js-yaml": "^3.11.0",
|
||||
"json-stable-stringify-without-jsonify": "^1.0.1",
|
||||
"levn": "^0.3.0",
|
||||
"lodash": "^4.17.4",
|
||||
"minimatch": "^3.0.2",
|
||||
"lodash": "^4.17.5",
|
||||
"minimatch": "^3.0.4",
|
||||
"mkdirp": "^0.5.1",
|
||||
"natural-compare": "^1.4.0",
|
||||
"optionator": "^0.8.2",
|
||||
"path-is-inside": "^1.0.2",
|
||||
"pluralize": "^7.0.0",
|
||||
"progress": "^2.0.0",
|
||||
"regexpp": "^1.0.1",
|
||||
"regexpp": "^1.1.0",
|
||||
"require-uncached": "^1.0.3",
|
||||
"semver": "^5.3.0",
|
||||
"semver": "^5.5.0",
|
||||
"string.prototype.matchall": "^2.0.0",
|
||||
"strip-ansi": "^4.0.0",
|
||||
"strip-json-comments": "~2.0.1",
|
||||
"table": "4.0.2",
|
||||
"text-table": "~0.2.0"
|
||||
"strip-json-comments": "^2.0.1",
|
||||
"table": "^4.0.3",
|
||||
"text-table": "^0.2.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"ajv": {
|
||||
"version": "5.5.2",
|
||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz",
|
||||
"integrity": "sha1-c7Xuyj+rZT49P5Qis0GtQiBdyWU=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"co": "^4.6.0",
|
||||
"fast-deep-equal": "^1.0.0",
|
||||
"fast-json-stable-stringify": "^2.0.0",
|
||||
"json-schema-traverse": "^0.3.0"
|
||||
}
|
||||
},
|
||||
"cross-spawn": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz",
|
||||
"integrity": "sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"lru-cache": "^4.0.1",
|
||||
"shebang-command": "^1.2.0",
|
||||
"which": "^1.2.9"
|
||||
}
|
||||
},
|
||||
"debug": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
|
||||
@ -2533,39 +2702,21 @@
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"fast-deep-equal": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz",
|
||||
"integrity": "sha1-wFNHeBfIa1HaqFPIHgWbcz0CNhQ=",
|
||||
"dev": true
|
||||
},
|
||||
"globals": {
|
||||
"version": "11.5.0",
|
||||
"resolved": "https://registry.npmjs.org/globals/-/globals-11.5.0.tgz",
|
||||
"integrity": "sha512-hYyf+kI8dm3nORsiiXUQigOU62hDLfJ9G01uyGMxhc6BKsircrUhC4uJPQPUSuq2GrTmiiEt7ewxlMdBewfmKQ==",
|
||||
"dev": true
|
||||
},
|
||||
"inquirer": {
|
||||
"version": "3.3.0",
|
||||
"resolved": "https://registry.npmjs.org/inquirer/-/inquirer-3.3.0.tgz",
|
||||
"integrity": "sha512-h+xtnyk4EwKvFWHrUYsWErEVR+igKtLdchu+o0Z1RL7VU/jVMFbYir2bp6bAj8efFNxWqHX0dIss6fJQ+/+qeQ==",
|
||||
"eslint-scope": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.0.tgz",
|
||||
"integrity": "sha512-1G6UTDi7Jc1ELFwnR58HV4fK9OQK4S6N985f166xqXxpjU6plxFISJa2Ba9KCQuFa8RCnj/lSFJbHo7UFDBnUA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ansi-escapes": "^3.0.0",
|
||||
"chalk": "^2.0.0",
|
||||
"cli-cursor": "^2.1.0",
|
||||
"cli-width": "^2.0.0",
|
||||
"external-editor": "^2.0.4",
|
||||
"figures": "^2.0.0",
|
||||
"lodash": "^4.3.0",
|
||||
"mute-stream": "0.0.7",
|
||||
"run-async": "^2.2.0",
|
||||
"rx-lite": "^4.0.8",
|
||||
"rx-lite-aggregates": "^4.0.8",
|
||||
"string-width": "^2.1.0",
|
||||
"strip-ansi": "^4.0.0",
|
||||
"through": "^2.3.6"
|
||||
"esrecurse": "^4.1.0",
|
||||
"estraverse": "^4.1.1"
|
||||
}
|
||||
},
|
||||
"globals": {
|
||||
"version": "11.7.0",
|
||||
"resolved": "https://registry.npmjs.org/globals/-/globals-11.7.0.tgz",
|
||||
"integrity": "sha512-K8BNSPySfeShBQXsahYB/AbbWruVOTyVpgoIDnl8odPpeSfP2J5QO2oLFFdl2j7GfDCtZj2bMKar2T49itTPCg==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -2586,13 +2737,13 @@
|
||||
"dev": true
|
||||
},
|
||||
"espree": {
|
||||
"version": "3.5.4",
|
||||
"resolved": "https://registry.npmjs.org/espree/-/espree-3.5.4.tgz",
|
||||
"integrity": "sha512-yAcIQxtmMiB/jL32dzEp2enBeidsB7xWPLNiw3IIkpVds1P+h7qF9YwJq1yUNzp2OKXgAprs4F61ih66UsoD1A==",
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/espree/-/espree-4.0.0.tgz",
|
||||
"integrity": "sha512-kapdTCt1bjmspxStVKX6huolXVV5ZfyZguY1lcfhVVZstce3bqxH9mcLzNn3/mlgW6wQ732+0fuG9v7h0ZQoKg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"acorn": "^5.5.0",
|
||||
"acorn-jsx": "^3.0.0"
|
||||
"acorn": "^5.6.0",
|
||||
"acorn-jsx": "^4.1.1"
|
||||
}
|
||||
},
|
||||
"esprima": {
|
||||
@ -3025,6 +3176,12 @@
|
||||
"for-in": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"foreach": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/foreach/-/foreach-2.0.5.tgz",
|
||||
"integrity": "sha1-C+4AUBiusmDQo6865ljdATbsG5k=",
|
||||
"dev": true
|
||||
},
|
||||
"fragment-cache": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/fragment-cache/-/fragment-cache-0.2.1.tgz",
|
||||
@ -3082,7 +3239,8 @@
|
||||
"ansi-regex": {
|
||||
"version": "2.1.1",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"aproba": {
|
||||
"version": "1.2.0",
|
||||
@ -3103,12 +3261,14 @@
|
||||
"balanced-match": {
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"brace-expansion": {
|
||||
"version": "1.1.11",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"balanced-match": "^1.0.0",
|
||||
"concat-map": "0.0.1"
|
||||
@ -3123,17 +3283,20 @@
|
||||
"code-point-at": {
|
||||
"version": "1.1.0",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"concat-map": {
|
||||
"version": "0.0.1",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"console-control-strings": {
|
||||
"version": "1.1.0",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"core-util-is": {
|
||||
"version": "1.0.2",
|
||||
@ -3250,7 +3413,8 @@
|
||||
"inherits": {
|
||||
"version": "2.0.3",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"ini": {
|
||||
"version": "1.3.5",
|
||||
@ -3262,6 +3426,7 @@
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"number-is-nan": "^1.0.0"
|
||||
}
|
||||
@ -3276,6 +3441,7 @@
|
||||
"version": "3.0.4",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"brace-expansion": "^1.1.7"
|
||||
}
|
||||
@ -3283,12 +3449,14 @@
|
||||
"minimist": {
|
||||
"version": "0.0.8",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"minipass": {
|
||||
"version": "2.2.4",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"safe-buffer": "^5.1.1",
|
||||
"yallist": "^3.0.0"
|
||||
@ -3307,6 +3475,7 @@
|
||||
"version": "0.5.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"minimist": "0.0.8"
|
||||
}
|
||||
@ -3387,7 +3556,8 @@
|
||||
"number-is-nan": {
|
||||
"version": "1.0.1",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"object-assign": {
|
||||
"version": "4.1.1",
|
||||
@ -3399,6 +3569,7 @@
|
||||
"version": "1.4.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"wrappy": "1"
|
||||
}
|
||||
@ -3484,7 +3655,8 @@
|
||||
"safe-buffer": {
|
||||
"version": "5.1.1",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"safer-buffer": {
|
||||
"version": "2.1.2",
|
||||
@ -3520,6 +3692,7 @@
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"code-point-at": "^1.0.0",
|
||||
"is-fullwidth-code-point": "^1.0.0",
|
||||
@ -3539,6 +3712,7 @@
|
||||
"version": "3.0.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"ansi-regex": "^2.0.0"
|
||||
}
|
||||
@ -3582,15 +3756,23 @@
|
||||
"wrappy": {
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"yallist": {
|
||||
"version": "3.0.2",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"function-bind": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
|
||||
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==",
|
||||
"dev": true
|
||||
},
|
||||
"functional-red-black-tree": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz",
|
||||
@ -3877,6 +4059,15 @@
|
||||
"lodash": "^4.17.2"
|
||||
}
|
||||
},
|
||||
"has": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
|
||||
"integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"function-bind": "^1.1.1"
|
||||
}
|
||||
},
|
||||
"has-ansi": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz",
|
||||
@ -3912,6 +4103,12 @@
|
||||
"integrity": "sha512-3ToOva++HaW+eCpgqZrCfN51IPB+7bJNVT6CUATzueB5Heb8o6Nam0V3HG5dlDvZU1Gn5QLcbahiKw/XVk5JJw==",
|
||||
"dev": true
|
||||
},
|
||||
"has-symbols": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.0.tgz",
|
||||
"integrity": "sha1-uhqPGvKg/DllD1yFA2dwQSIGO0Q=",
|
||||
"dev": true
|
||||
},
|
||||
"has-to-string-tag-x": {
|
||||
"version": "1.4.1",
|
||||
"resolved": "https://registry.npmjs.org/has-to-string-tag-x/-/has-to-string-tag-x-1.4.1.tgz",
|
||||
@ -4203,6 +4400,12 @@
|
||||
"builtin-modules": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"is-callable": {
|
||||
"version": "1.1.4",
|
||||
"resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.4.tgz",
|
||||
"integrity": "sha512-r5p9sxJjYnArLjObpjA4xu5EKI3CuKHkJXMhT7kwbpUyIFD1n5PMAsoPvWnvtZiNz7LjkYDRZhd7FlI0eMijEA==",
|
||||
"dev": true
|
||||
},
|
||||
"is-data-descriptor": {
|
||||
"version": "0.1.4",
|
||||
"resolved": "https://registry.npmjs.org/is-data-descriptor/-/is-data-descriptor-0.1.4.tgz",
|
||||
@ -4223,6 +4426,12 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"is-date-object": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.1.tgz",
|
||||
"integrity": "sha1-mqIOtq7rv/d/vTPnTKAbM1gdOhY=",
|
||||
"dev": true
|
||||
},
|
||||
"is-descriptor": {
|
||||
"version": "0.1.6",
|
||||
"resolved": "https://registry.npmjs.org/is-descriptor/-/is-descriptor-0.1.6.tgz",
|
||||
@ -4410,6 +4619,15 @@
|
||||
"integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=",
|
||||
"dev": true
|
||||
},
|
||||
"is-regex": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.0.4.tgz",
|
||||
"integrity": "sha1-VRdIm1RwkbCTDglWVM7SXul+lJE=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"has": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"is-resolvable": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/is-resolvable/-/is-resolvable-1.1.0.tgz",
|
||||
@ -4437,6 +4655,12 @@
|
||||
"integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=",
|
||||
"dev": true
|
||||
},
|
||||
"is-symbol": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.1.tgz",
|
||||
"integrity": "sha1-PMWfAAJRlLarLjjbrmaJJWtmBXI=",
|
||||
"dev": true
|
||||
},
|
||||
"is-utf8": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/is-utf8/-/is-utf8-0.2.1.tgz",
|
||||
@ -5608,6 +5832,12 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"object-keys": {
|
||||
"version": "1.0.12",
|
||||
"resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.0.12.tgz",
|
||||
"integrity": "sha512-FTMyFUm2wBcGHnH2eXmz7tC6IwlqQZ6mVZ+6dm6vZ4IQIHjs6FdNsQBuKGPuUUUY6NfJw2PshC08Tn6LzLDOag==",
|
||||
"dev": true
|
||||
},
|
||||
"object-visit": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/object-visit/-/object-visit-1.0.1.tgz",
|
||||
@ -6343,6 +6573,15 @@
|
||||
"safe-regex": "^1.1.0"
|
||||
}
|
||||
},
|
||||
"regexp.prototype.flags": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.2.0.tgz",
|
||||
"integrity": "sha512-ztaw4M1VqgMwl9HlPpOuiYgItcHlunW0He2fE6eNfT6E/CF2FtYi9ofOYe4mKntstYk0Fyh/rDRBdS3AnxjlrA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"define-properties": "^1.1.2"
|
||||
}
|
||||
},
|
||||
"regexpp": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/regexpp/-/regexpp-1.1.0.tgz",
|
||||
@ -6540,21 +6779,6 @@
|
||||
"aproba": "^1.1.1"
|
||||
}
|
||||
},
|
||||
"rx-lite": {
|
||||
"version": "4.0.8",
|
||||
"resolved": "https://registry.npmjs.org/rx-lite/-/rx-lite-4.0.8.tgz",
|
||||
"integrity": "sha1-Cx4Rr4vESDbwSmQH6S2kJGe3lEQ=",
|
||||
"dev": true
|
||||
},
|
||||
"rx-lite-aggregates": {
|
||||
"version": "4.0.8",
|
||||
"resolved": "https://registry.npmjs.org/rx-lite-aggregates/-/rx-lite-aggregates-4.0.8.tgz",
|
||||
"integrity": "sha1-dTuHqJoRyVRnxKwWJsTvxOBcZ74=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"rx-lite": "*"
|
||||
}
|
||||
},
|
||||
"rxjs": {
|
||||
"version": "5.5.11",
|
||||
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-5.5.11.tgz",
|
||||
@ -7008,6 +7232,19 @@
|
||||
"strip-ansi": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"string.prototype.matchall": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/string.prototype.matchall/-/string.prototype.matchall-2.0.0.tgz",
|
||||
"integrity": "sha512-WoZ+B2ypng1dp4iFLF2kmZlwwlE19gmjgKuhL1FJfDgCREWb3ye3SDVHSzLH6bxfnvYmkCxbzkmWcQZHA4P//Q==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"define-properties": "^1.1.2",
|
||||
"es-abstract": "^1.10.0",
|
||||
"function-bind": "^1.1.1",
|
||||
"has-symbols": "^1.0.0",
|
||||
"regexp.prototype.flags": "^1.2.0"
|
||||
}
|
||||
},
|
||||
"string_decoder": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
|
||||
@ -7073,43 +7310,19 @@
|
||||
"dev": true
|
||||
},
|
||||
"table": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/table/-/table-4.0.2.tgz",
|
||||
"integrity": "sha512-UUkEAPdSGxtRpiV9ozJ5cMTtYiqz7Ni1OGqLXRCynrvzdtR1p+cfOWe2RJLwvUG8hNanaSRjecIqwOjqeatDsA==",
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/table/-/table-4.0.3.tgz",
|
||||
"integrity": "sha512-S7rnFITmBH1EnyKcvxBh1LjYeQMmnZtCXSEbHcH6S0NoKit24ZuFO/T1vDcLdYsLQkM188PVVhQmzKIuThNkKg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ajv": "^5.2.3",
|
||||
"ajv-keywords": "^2.1.0",
|
||||
"ajv": "^6.0.1",
|
||||
"ajv-keywords": "^3.0.0",
|
||||
"chalk": "^2.1.0",
|
||||
"lodash": "^4.17.4",
|
||||
"slice-ansi": "1.0.0",
|
||||
"string-width": "^2.1.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"ajv": {
|
||||
"version": "5.5.2",
|
||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz",
|
||||
"integrity": "sha1-c7Xuyj+rZT49P5Qis0GtQiBdyWU=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"co": "^4.6.0",
|
||||
"fast-deep-equal": "^1.0.0",
|
||||
"fast-json-stable-stringify": "^2.0.0",
|
||||
"json-schema-traverse": "^0.3.0"
|
||||
}
|
||||
},
|
||||
"ajv-keywords": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-2.1.1.tgz",
|
||||
"integrity": "sha1-YXmX/F9gV2iUxDX5QNgZ4TW4B2I=",
|
||||
"dev": true
|
||||
},
|
||||
"fast-deep-equal": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz",
|
||||
"integrity": "sha1-wFNHeBfIa1HaqFPIHgWbcz0CNhQ=",
|
||||
"dev": true
|
||||
},
|
||||
"slice-ansi": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-1.0.0.tgz",
|
||||
|
@ -9,6 +9,7 @@
|
||||
"typescript": "^2.7.2",
|
||||
"webpack": "^4.11.1",
|
||||
"webpack-cli": "^2.0.10",
|
||||
"eslint": "^4.19.1"
|
||||
"babel-eslint": "^8.2.5",
|
||||
"eslint": "^5.0.1"
|
||||
}
|
||||
}
|
||||
|
248
tests/all/api.rs
248
tests/all/api.rs
@ -6,144 +6,144 @@ fn works() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn foo() -> JsValue {
|
||||
JsValue::from("foo")
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn foo() -> JsValue {
|
||||
JsValue::from("foo")
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn bar(s: &str) -> JsValue {
|
||||
JsValue::from(s)
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn bar(s: &str) -> JsValue {
|
||||
JsValue::from(s)
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn baz() -> JsValue {
|
||||
JsValue::from(1.0)
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn baz() -> JsValue {
|
||||
JsValue::from(1.0)
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn baz2(a: &JsValue, b: &JsValue) {
|
||||
assert_eq!(a.as_f64(), Some(2.0));
|
||||
assert_eq!(b.as_f64(), None);
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn baz2(a: &JsValue, b: &JsValue) {
|
||||
assert_eq!(a.as_f64(), Some(2.0));
|
||||
assert_eq!(b.as_f64(), None);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn js_null() -> JsValue {
|
||||
JsValue::null()
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn js_null() -> JsValue {
|
||||
JsValue::null()
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn js_undefined() -> JsValue {
|
||||
JsValue::undefined()
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn js_undefined() -> JsValue {
|
||||
JsValue::undefined()
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn test_is_null_undefined(
|
||||
a: &JsValue,
|
||||
b: &JsValue,
|
||||
c: &JsValue,
|
||||
) {
|
||||
assert!(a.is_null());
|
||||
assert!(!a.is_undefined());
|
||||
#[wasm_bindgen]
|
||||
pub fn test_is_null_undefined(
|
||||
a: &JsValue,
|
||||
b: &JsValue,
|
||||
c: &JsValue,
|
||||
) {
|
||||
assert!(a.is_null());
|
||||
assert!(!a.is_undefined());
|
||||
|
||||
assert!(!b.is_null());
|
||||
assert!(b.is_undefined());
|
||||
assert!(!b.is_null());
|
||||
assert!(b.is_undefined());
|
||||
|
||||
assert!(!c.is_null());
|
||||
assert!(!c.is_undefined());
|
||||
}
|
||||
assert!(!c.is_null());
|
||||
assert!(!c.is_undefined());
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_true() -> JsValue {
|
||||
JsValue::from(true)
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn get_true() -> JsValue {
|
||||
JsValue::from(true)
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_false() -> JsValue {
|
||||
JsValue::from(false)
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn get_false() -> JsValue {
|
||||
JsValue::from(false)
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn test_bool(
|
||||
a: &JsValue,
|
||||
b: &JsValue,
|
||||
c: &JsValue,
|
||||
) {
|
||||
assert_eq!(a.as_bool(), Some(true));
|
||||
assert_eq!(b.as_bool(), Some(false));
|
||||
assert_eq!(c.as_bool(), None);
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn test_bool(
|
||||
a: &JsValue,
|
||||
b: &JsValue,
|
||||
c: &JsValue,
|
||||
) {
|
||||
assert_eq!(a.as_bool(), Some(true));
|
||||
assert_eq!(b.as_bool(), Some(false));
|
||||
assert_eq!(c.as_bool(), None);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn mk_symbol() -> JsValue {
|
||||
let a = JsValue::symbol(None);
|
||||
assert!(a.is_symbol());
|
||||
return a
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn mk_symbol() -> JsValue {
|
||||
let a = JsValue::symbol(None);
|
||||
assert!(a.is_symbol());
|
||||
return a
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn mk_symbol2(s: &str) -> JsValue {
|
||||
let a = JsValue::symbol(Some(s));
|
||||
assert!(a.is_symbol());
|
||||
return a
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn mk_symbol2(s: &str) -> JsValue {
|
||||
let a = JsValue::symbol(Some(s));
|
||||
assert!(a.is_symbol());
|
||||
return a
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn assert_symbols(a: &JsValue, b: &JsValue) {
|
||||
assert!(a.is_symbol());
|
||||
assert!(!b.is_symbol());
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn assert_symbols(a: &JsValue, b: &JsValue) {
|
||||
assert!(a.is_symbol());
|
||||
assert!(!b.is_symbol());
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn acquire_string(a: &JsValue, b: &JsValue) {
|
||||
assert_eq!(a.as_string().unwrap(), "foo");
|
||||
assert_eq!(b.as_string(), None);
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn acquire_string(a: &JsValue, b: &JsValue) {
|
||||
assert_eq!(a.as_string().unwrap(), "foo");
|
||||
assert_eq!(b.as_string(), None);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn acquire_string2(a: &JsValue) -> String {
|
||||
a.as_string().unwrap_or("wrong".to_string())
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn acquire_string2(a: &JsValue) -> String {
|
||||
a.as_string().unwrap_or("wrong".to_string())
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
assert.strictEqual(wasm.foo(), 'foo');
|
||||
assert.strictEqual(wasm.bar('a'), 'a');
|
||||
assert.strictEqual(wasm.baz(), 1);
|
||||
wasm.baz2(2, 'a');
|
||||
export function test() {
|
||||
assert.strictEqual(wasm.foo(), 'foo');
|
||||
assert.strictEqual(wasm.bar('a'), 'a');
|
||||
assert.strictEqual(wasm.baz(), 1);
|
||||
wasm.baz2(2, 'a');
|
||||
|
||||
assert.strictEqual(wasm.js_null(), null);
|
||||
assert.strictEqual(wasm.js_undefined(), undefined);
|
||||
assert.strictEqual(wasm.js_null(), null);
|
||||
assert.strictEqual(wasm.js_undefined(), undefined);
|
||||
|
||||
wasm.test_is_null_undefined(null, undefined, 1.0);
|
||||
wasm.test_is_null_undefined(null, undefined, 1.0);
|
||||
|
||||
assert.strictEqual(wasm.get_true(), true);
|
||||
assert.strictEqual(wasm.get_false(), false);
|
||||
wasm.test_bool(true, false, 1.0);
|
||||
assert.strictEqual(wasm.get_true(), true);
|
||||
assert.strictEqual(wasm.get_false(), false);
|
||||
wasm.test_bool(true, false, 1.0);
|
||||
|
||||
assert.strictEqual(typeof(wasm.mk_symbol()), 'symbol');
|
||||
assert.strictEqual(typeof(wasm.mk_symbol2('a')), 'symbol');
|
||||
assert.strictEqual((Symbol as any).keyFor(wasm.mk_symbol()), undefined);
|
||||
assert.strictEqual((Symbol as any).keyFor(wasm.mk_symbol2('b')), undefined);
|
||||
assert.strictEqual(typeof(wasm.mk_symbol()), 'symbol');
|
||||
assert.strictEqual(typeof(wasm.mk_symbol2('a')), 'symbol');
|
||||
assert.strictEqual(Symbol.keyFor(wasm.mk_symbol()), undefined);
|
||||
assert.strictEqual(Symbol.keyFor(wasm.mk_symbol2('b')), undefined);
|
||||
|
||||
wasm.assert_symbols((Symbol as any)(), 'a');
|
||||
wasm.acquire_string('foo', null)
|
||||
assert.strictEqual(wasm.acquire_string2(''), '');
|
||||
assert.strictEqual(wasm.acquire_string2('a'), 'a');
|
||||
}
|
||||
"#,
|
||||
wasm.assert_symbols(Symbol(), 'a');
|
||||
wasm.acquire_string('foo', null)
|
||||
assert.strictEqual(wasm.acquire_string2(''), '');
|
||||
assert.strictEqual(wasm.acquire_string2('a'), 'a');
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -172,22 +172,22 @@ fn eq_works() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
assert.strictEqual(wasm.test('a', 'a'), true);
|
||||
assert.strictEqual(wasm.test('a', 'b'), false);
|
||||
assert.strictEqual(wasm.test(NaN, NaN), false);
|
||||
assert.strictEqual(wasm.test({a: 'a'}, {a: 'a'}), false);
|
||||
assert.strictEqual(wasm.test1(NaN), false);
|
||||
let x = {a: 'a'};
|
||||
assert.strictEqual(wasm.test(x, x), true);
|
||||
assert.strictEqual(wasm.test1(x), true);
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
assert.strictEqual(wasm.test('a', 'a'), true);
|
||||
assert.strictEqual(wasm.test('a', 'b'), false);
|
||||
assert.strictEqual(wasm.test(NaN, NaN), false);
|
||||
assert.strictEqual(wasm.test({a: 'a'}, {a: 'a'}), false);
|
||||
assert.strictEqual(wasm.test1(NaN), false);
|
||||
let x = {a: 'a'};
|
||||
assert.strictEqual(wasm.test(x, x), true);
|
||||
assert.strictEqual(wasm.test1(x), true);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ fn simple() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import { Foo } from "./out";
|
||||
@ -115,7 +115,7 @@ fn strings() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import { Foo } from "./out";
|
||||
@ -139,70 +139,64 @@ fn exceptions() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub struct A {
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl A {
|
||||
pub fn new() -> A {
|
||||
A {}
|
||||
#[wasm_bindgen]
|
||||
pub struct A {
|
||||
}
|
||||
|
||||
pub fn foo(&self, _: &A) {
|
||||
#[wasm_bindgen]
|
||||
impl A {
|
||||
pub fn new() -> A {
|
||||
A {}
|
||||
}
|
||||
|
||||
pub fn foo(&self, _: &A) {
|
||||
}
|
||||
|
||||
pub fn bar(&mut self, _: &mut A) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bar(&mut self, _: &mut A) {
|
||||
#[wasm_bindgen]
|
||||
pub struct B {
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub struct B {
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl B {
|
||||
pub fn new() -> B {
|
||||
B {}
|
||||
#[wasm_bindgen]
|
||||
impl B {
|
||||
pub fn new() -> B {
|
||||
B {}
|
||||
}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import { A, B } from "./out";
|
||||
import * as assert from "assert";
|
||||
import { A, B } from "./out";
|
||||
|
||||
export function test() {
|
||||
assert.throws(() => new A(), /cannot invoke `new` directly/);
|
||||
let a = A.new();
|
||||
a.free();
|
||||
assert.throws(() => a.free(), /null pointer passed to rust/);
|
||||
export function test() {
|
||||
assert.throws(() => new A(), /cannot invoke `new` directly/);
|
||||
let a = A.new();
|
||||
a.free();
|
||||
assert.throws(() => a.free(), /null pointer passed to rust/);
|
||||
|
||||
let b = A.new();
|
||||
b.foo(b);
|
||||
assert.throws(() => b.bar(b), /recursive use of an object/);
|
||||
let b = A.new();
|
||||
b.foo(b);
|
||||
assert.throws(() => b.bar(b), /recursive use of an object/);
|
||||
|
||||
let c = A.new();
|
||||
let d = B.new();
|
||||
assert.throws(() => c.foo(d), /expected instance of A/);
|
||||
d.free();
|
||||
c.free();
|
||||
};
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.d.ts",
|
||||
r#"
|
||||
export function test(): void;
|
||||
"#,
|
||||
let c = A.new();
|
||||
let d = B.new();
|
||||
assert.throws(() => c.foo(d), /expected instance of A/);
|
||||
d.free();
|
||||
c.free();
|
||||
};
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -247,7 +241,7 @@ fn pass_one_to_another() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { A, B } from "./out";
|
||||
|
||||
@ -269,49 +263,49 @@ fn pass_into_js() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub struct Foo(i32);
|
||||
#[wasm_bindgen]
|
||||
pub struct Foo(i32);
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl Foo {
|
||||
pub fn inner(&self) -> i32 {
|
||||
self.0
|
||||
#[wasm_bindgen]
|
||||
impl Foo {
|
||||
pub fn inner(&self) -> i32 {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn take_foo(foo: Foo);
|
||||
}
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn take_foo(foo: Foo);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
take_foo(Foo(13));
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
take_foo(Foo(13));
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { run, Foo } from "./out";
|
||||
import * as assert from "assert";
|
||||
import { run, Foo } from "./out";
|
||||
import * as assert from "assert";
|
||||
|
||||
export function take_foo(foo: Foo) {
|
||||
assert.strictEqual(foo.inner(), 13);
|
||||
foo.free();
|
||||
assert.throws(() => foo.free(), /null pointer passed to rust/);
|
||||
}
|
||||
export function take_foo(foo) {
|
||||
assert.strictEqual(foo.inner(), 13);
|
||||
foo.free();
|
||||
assert.throws(() => foo.free(), /null pointer passed to rust/);
|
||||
}
|
||||
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -353,7 +347,7 @@ fn issue_27() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { context } from "./out";
|
||||
|
||||
@ -399,21 +393,21 @@ fn pass_into_js_as_js_class() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { run, Foo } from "./out";
|
||||
import * as assert from "assert";
|
||||
import { run, Foo } from "./out";
|
||||
import * as assert from "assert";
|
||||
|
||||
export function take_foo(foo: any) {
|
||||
assert(foo instanceof Foo);
|
||||
assert.strictEqual(foo.inner(), 13);
|
||||
foo.free();
|
||||
}
|
||||
export function take_foo(foo) {
|
||||
assert.ok(foo instanceof Foo);
|
||||
assert.strictEqual(foo.inner(), 13);
|
||||
foo.free();
|
||||
}
|
||||
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -472,31 +466,31 @@ fn constructors() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import { Foo, Bar, cross_item_construction } from "./out";
|
||||
import * as assert from "assert";
|
||||
import { Foo, Bar, cross_item_construction } from "./out";
|
||||
|
||||
export function test() {
|
||||
const foo = new Foo(1);
|
||||
assert.strictEqual(foo.get_number(), 1);
|
||||
foo.free();
|
||||
export function test() {
|
||||
const foo = new Foo(1);
|
||||
assert.strictEqual(foo.get_number(), 1);
|
||||
foo.free();
|
||||
|
||||
const foo2 = Foo.new(2);
|
||||
assert.strictEqual(foo2.get_number(), 2);
|
||||
foo2.free();
|
||||
const foo2 = Foo.new(2);
|
||||
assert.strictEqual(foo2.get_number(), 2);
|
||||
foo2.free();
|
||||
|
||||
const bar = new Bar(3, 4);
|
||||
assert.strictEqual(bar.get_sum(), 7);
|
||||
bar.free();
|
||||
const bar = new Bar(3, 4);
|
||||
assert.strictEqual(bar.get_sum(), 7);
|
||||
bar.free();
|
||||
|
||||
const bar2 = Bar.other_name(5, 6);
|
||||
assert.strictEqual(bar2.get_sum(), 11);
|
||||
bar2.free();
|
||||
const bar2 = Bar.other_name(5, 6);
|
||||
assert.strictEqual(bar2.get_sum(), 11);
|
||||
bar2.free();
|
||||
|
||||
assert.strictEqual(cross_item_construction().get_sum(), 15);
|
||||
}
|
||||
"#,
|
||||
assert.strictEqual(cross_item_construction().get_sum(), 15);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -525,14 +519,14 @@ fn empty_structs() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { Other } from "./out";
|
||||
import { Other } from "./out";
|
||||
|
||||
export function test() {
|
||||
Other.return_a_value();
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
Other.return_a_value();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -568,7 +562,7 @@ fn public_fields() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { Foo } from "./out";
|
||||
import * as assert from "assert";
|
||||
@ -622,7 +616,7 @@ fn using_self() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { Foo } from "./out";
|
||||
|
||||
@ -641,40 +635,40 @@ fn readonly_fields() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
#[derive(Default)]
|
||||
pub struct Foo {
|
||||
#[wasm_bindgen(readonly)]
|
||||
pub a: u32,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl Foo {
|
||||
pub fn new() -> Foo {
|
||||
Foo::default()
|
||||
#[wasm_bindgen]
|
||||
#[derive(Default)]
|
||||
pub struct Foo {
|
||||
#[wasm_bindgen(readonly)]
|
||||
pub a: u32,
|
||||
}
|
||||
}
|
||||
"#,
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl Foo {
|
||||
pub fn new() -> Foo {
|
||||
Foo::default()
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { Foo } from "./out";
|
||||
import * as assert from "assert";
|
||||
import { Foo } from "./out";
|
||||
import * as assert from "assert";
|
||||
|
||||
export function test() {
|
||||
const a = Foo.new();
|
||||
assert.strictEqual(a.a, 0);
|
||||
assert.throws(() => (a as any).a = 3, /has only a getter/);
|
||||
a.free();
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
const a = Foo.new();
|
||||
assert.strictEqual(a.a, 0);
|
||||
assert.throws(() => a.a = 3, /has only a getter/);
|
||||
a.free();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -704,7 +698,7 @@ fn double_consume() {
|
||||
}
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import { Foo } from "./out";
|
||||
|
||||
|
@ -6,46 +6,46 @@ fn works() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use std::cell::Cell;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use std::cell::Cell;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn call(a: &Fn());
|
||||
fn thread(a: &Fn(u32) -> u32) -> u32;
|
||||
}
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn call(a: &Fn());
|
||||
fn thread(a: &Fn(u32) -> u32) -> u32;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
let a = Cell::new(false);
|
||||
call(&|| a.set(true));
|
||||
assert!(a.get());
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
let a = Cell::new(false);
|
||||
call(&|| a.set(true));
|
||||
assert!(a.get());
|
||||
|
||||
assert_eq!(thread(&|a| a + 1), 3);
|
||||
}
|
||||
"#,
|
||||
assert_eq!(thread(&|a| a + 1), 3);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { run } from "./out";
|
||||
import { run } from "./out";
|
||||
|
||||
export function call(a: any) {
|
||||
a();
|
||||
}
|
||||
export function call(a) {
|
||||
a();
|
||||
}
|
||||
|
||||
export function thread(a: any) {
|
||||
return a(2);
|
||||
}
|
||||
export function thread(a) {
|
||||
return a(2);
|
||||
}
|
||||
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -56,34 +56,34 @@ fn cannot_reuse() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn call(a: &Fn());
|
||||
#[wasm_bindgen(catch)]
|
||||
fn call_again() -> Result<(), JsValue>;
|
||||
}
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn call(a: &Fn());
|
||||
#[wasm_bindgen(catch)]
|
||||
fn call_again() -> Result<(), JsValue>;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
call(&|| {});
|
||||
assert!(call_again().is_err());
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
call(&|| {});
|
||||
assert!(call_again().is_err());
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { run } from "./out";
|
||||
|
||||
let CACHE: any = null;
|
||||
let CACHE = null;
|
||||
|
||||
export function call(a: any) {
|
||||
export function call(a) {
|
||||
CACHE = a;
|
||||
}
|
||||
|
||||
@ -142,15 +142,15 @@ fn long_lived() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { run } from "./out";
|
||||
|
||||
export function call1(a: any) {
|
||||
export function call1(a) {
|
||||
a();
|
||||
}
|
||||
|
||||
export function call2(a: any) {
|
||||
export function call2(a) {
|
||||
return a(2);
|
||||
}
|
||||
|
||||
@ -242,18 +242,18 @@ fn many_arity() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { run } from "./out";
|
||||
|
||||
export function call1(a: any) { a() }
|
||||
export function call2(a: any) { a(1) }
|
||||
export function call3(a: any) { a(1, 2) }
|
||||
export function call4(a: any) { a(1, 2, 3) }
|
||||
export function call5(a: any) { a(1, 2, 3, 4) }
|
||||
export function call6(a: any) { a(1, 2, 3, 4, 5) }
|
||||
export function call7(a: any) { a(1, 2, 3, 4, 5, 6) }
|
||||
export function call8(a: any) { a(1, 2, 3, 4, 5, 6, 7) }
|
||||
export function call1(a) { a() }
|
||||
export function call2(a) { a(1) }
|
||||
export function call3(a) { a(1, 2) }
|
||||
export function call4(a) { a(1, 2, 3) }
|
||||
export function call5(a) { a(1, 2, 3, 4) }
|
||||
export function call6(a) { a(1, 2, 3, 4, 5) }
|
||||
export function call7(a) { a(1, 2, 3, 4, 5, 6) }
|
||||
export function call8(a) { a(1, 2, 3, 4, 5, 6, 7) }
|
||||
|
||||
export function test() {
|
||||
run();
|
||||
@ -299,13 +299,13 @@ fn long_lived_dropping() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { run } from "./out";
|
||||
|
||||
let CACHE: any = null;
|
||||
let CACHE = null;
|
||||
|
||||
export function cache(a: any) { CACHE = a; }
|
||||
export function cache(a) { CACHE = a; }
|
||||
export function call() { CACHE() }
|
||||
|
||||
export function test() {
|
||||
@ -346,13 +346,13 @@ fn long_fnmut_recursive() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { run } from "./out";
|
||||
|
||||
let CACHE: any = null;
|
||||
let CACHE = null;
|
||||
|
||||
export function cache(a: any) { CACHE = a; }
|
||||
export function cache(a) { CACHE = a; }
|
||||
export function call() { CACHE() }
|
||||
|
||||
export function test() {
|
||||
@ -397,15 +397,15 @@ fn fnmut() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { run } from "./out";
|
||||
|
||||
export function call(a: any) {
|
||||
export function call(a) {
|
||||
a();
|
||||
}
|
||||
|
||||
export function thread(a: any) {
|
||||
export function thread(a) {
|
||||
return a(2);
|
||||
}
|
||||
|
||||
@ -455,18 +455,18 @@ fn fnmut_bad() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { run } from "./out";
|
||||
|
||||
let F: any = null;
|
||||
let F = null;
|
||||
|
||||
export function call(a: any) {
|
||||
export function call(a) {
|
||||
F = a;
|
||||
a();
|
||||
}
|
||||
|
||||
export function again(x: boolean) {
|
||||
export function again(x) {
|
||||
if (x) F();
|
||||
}
|
||||
|
||||
@ -507,18 +507,18 @@ fn string_arguments() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { run } from "./out";
|
||||
import { run } from "./out";
|
||||
|
||||
export function call(a: any) {
|
||||
a("foo")
|
||||
}
|
||||
export function call(a) {
|
||||
a("foo")
|
||||
}
|
||||
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -529,45 +529,45 @@ fn string_ret() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn call(a: &mut FnMut(String) -> String);
|
||||
}
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn call(a: &mut FnMut(String) -> String);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
let mut x = false;
|
||||
call(&mut |mut s| {
|
||||
assert_eq!(s, "foo");
|
||||
s.push_str("bar");
|
||||
x = true;
|
||||
s
|
||||
});
|
||||
assert!(x);
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
let mut x = false;
|
||||
call(&mut |mut s| {
|
||||
assert_eq!(s, "foo");
|
||||
s.push_str("bar");
|
||||
x = true;
|
||||
s
|
||||
});
|
||||
assert!(x);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { run } from "./out";
|
||||
import * as assert from "assert";
|
||||
import { run } from "./out";
|
||||
import * as assert from "assert";
|
||||
|
||||
export function call(a: any) {
|
||||
const s = a("foo");
|
||||
assert.strictEqual(s, "foobar");
|
||||
}
|
||||
export function call(a) {
|
||||
const s = a("foo");
|
||||
assert.strictEqual(s, "foobar");
|
||||
}
|
||||
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
@ -38,12 +38,12 @@ fn works() {
|
||||
"#,
|
||||
);
|
||||
|
||||
let (root, target) = p.cargo_build();
|
||||
p.gen_bindings(&root, &target);
|
||||
p.gen_bindings();
|
||||
let js = p.read_js();
|
||||
let comments = extract_doc_comments(&js);
|
||||
assert!(comments.iter().all(|c| c == "This comment should exist"));
|
||||
}
|
||||
|
||||
/// Pull out all lines in a js string that start with
|
||||
/// '* ', all other lines will either be comment start, comment
|
||||
/// end or actual js lines.
|
||||
|
@ -6,87 +6,87 @@ fn dependencies_work() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
extern crate wasm_bindgen;
|
||||
extern crate dependency;
|
||||
use wasm_bindgen::prelude::*;
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
extern crate wasm_bindgen;
|
||||
extern crate dependency;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn return_dep_ty(x: f64) -> dependency::Foo {
|
||||
dependency::Foo(x)
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn return_dep_ty(x: f64) -> dependency::Foo {
|
||||
dependency::Foo(x)
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn takes_own_dep_ty(foo: dependency::Foo) -> f64 {
|
||||
foo.0
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn takes_own_dep_ty(foo: dependency::Foo) -> f64 {
|
||||
foo.0
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn takes_ref_dep_ty(foo: &dependency::Foo) -> f64 {
|
||||
foo.0
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn takes_ref_dep_ty(foo: &dependency::Foo) -> f64 {
|
||||
foo.0
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn takes_mut_dep_ty(foo: &mut dependency::Foo, x: f64) {
|
||||
foo.0 = x;
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn takes_mut_dep_ty(foo: &mut dependency::Foo, x: f64) {
|
||||
foo.0 = x;
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.add_local_dependency("dependency", "vendor/dependency")
|
||||
.file(
|
||||
"vendor/dependency/Cargo.toml",
|
||||
&format!(
|
||||
r#"
|
||||
[package]
|
||||
name = "dependency"
|
||||
version = "0.0.1"
|
||||
authors = []
|
||||
[package]
|
||||
name = "dependency"
|
||||
version = "0.0.1"
|
||||
authors = []
|
||||
|
||||
[dependencies]
|
||||
wasm-bindgen = {{ path = '{}' }}
|
||||
"#,
|
||||
[dependencies]
|
||||
wasm-bindgen = {{ path = '{}' }}
|
||||
"#,
|
||||
env!("CARGO_MANIFEST_DIR")
|
||||
),
|
||||
)
|
||||
.file(
|
||||
"vendor/dependency/src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub struct Foo(pub f64);
|
||||
#[wasm_bindgen]
|
||||
pub struct Foo(pub f64);
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl Foo {
|
||||
pub fn new(x: f64) -> Foo { Foo(x) }
|
||||
pub fn get(&self) -> f64 { self.0 }
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
impl Foo {
|
||||
pub fn new(x: f64) -> Foo { Foo(x) }
|
||||
pub fn get(&self) -> f64 { self.0 }
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
const foo = wasm.return_dep_ty(42);
|
||||
assert.strictEqual(foo.get(), 42);
|
||||
export function test() {
|
||||
const foo = wasm.return_dep_ty(42);
|
||||
assert.strictEqual(foo.get(), 42);
|
||||
|
||||
const x = wasm.takes_ref_dep_ty(foo);
|
||||
assert.strictEqual(x, 42);
|
||||
const x = wasm.takes_ref_dep_ty(foo);
|
||||
assert.strictEqual(x, 42);
|
||||
|
||||
const y = 1337;
|
||||
wasm.takes_mut_dep_ty(foo, y);
|
||||
assert.strictEqual(foo.get(), y);
|
||||
const y = 1337;
|
||||
wasm.takes_mut_dep_ty(foo, y);
|
||||
assert.strictEqual(foo.get(), y);
|
||||
|
||||
const z = wasm.takes_own_dep_ty(foo);
|
||||
assert.strictEqual(z, y);
|
||||
assert.strictEqual((foo as any).ptr, 0);
|
||||
}
|
||||
"#,
|
||||
const z = wasm.takes_own_dep_ty(foo);
|
||||
assert.strictEqual(z, y);
|
||||
assert.strictEqual(foo.ptr, 0);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
@ -6,44 +6,44 @@ fn c_style_enum() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub enum Color {
|
||||
Green,
|
||||
Yellow,
|
||||
Red,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn cycle(color: Color) -> Color {
|
||||
match color {
|
||||
Color::Green => Color::Yellow,
|
||||
Color::Yellow => Color::Red,
|
||||
Color::Red => Color::Green,
|
||||
#[wasm_bindgen]
|
||||
pub enum Color {
|
||||
Green,
|
||||
Yellow,
|
||||
Red,
|
||||
}
|
||||
}
|
||||
"#,
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn cycle(color: Color) -> Color {
|
||||
match color {
|
||||
Color::Green => Color::Yellow,
|
||||
Color::Yellow => Color::Red,
|
||||
Color::Red => Color::Green,
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
assert.strictEqual(wasm.Color.Green, 0);
|
||||
assert.strictEqual(wasm.Color.Yellow, 1);
|
||||
assert.strictEqual(wasm.Color.Red, 2);
|
||||
assert.strictEqual(Object.keys(wasm.Color).length, 3);
|
||||
export function test() {
|
||||
assert.strictEqual(wasm.Color.Green, 0);
|
||||
assert.strictEqual(wasm.Color.Yellow, 1);
|
||||
assert.strictEqual(wasm.Color.Red, 2);
|
||||
assert.strictEqual(Object.keys(wasm.Color).length, 3);
|
||||
|
||||
assert.strictEqual(wasm.cycle(wasm.Color.Green), wasm.Color.Yellow);
|
||||
}
|
||||
"#,
|
||||
assert.strictEqual(wasm.cycle(wasm.Color.Green), wasm.Color.Yellow);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -54,50 +54,50 @@ fn c_style_enum_with_custom_values() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
pub mod inner {
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
pub mod inner {
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub enum Color {
|
||||
Green = 21,
|
||||
Yellow = 34,
|
||||
Red,
|
||||
}
|
||||
}
|
||||
|
||||
use inner::Color;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub enum Color {
|
||||
Green = 21,
|
||||
Yellow = 34,
|
||||
Red,
|
||||
pub fn cycle(color: Color) -> Color {
|
||||
match color {
|
||||
Color::Green => Color::Yellow,
|
||||
Color::Yellow => Color::Red,
|
||||
Color::Red => Color::Green,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
use inner::Color;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn cycle(color: Color) -> Color {
|
||||
match color {
|
||||
Color::Green => Color::Yellow,
|
||||
Color::Yellow => Color::Red,
|
||||
Color::Red => Color::Green,
|
||||
}
|
||||
}
|
||||
"#,
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
assert.strictEqual(wasm.Color.Green, 21);
|
||||
assert.strictEqual(wasm.Color.Yellow, 34);
|
||||
assert.strictEqual(wasm.Color.Red, 2);
|
||||
assert.strictEqual(Object.keys(wasm.Color).length, 3);
|
||||
export function test() {
|
||||
assert.strictEqual(wasm.Color.Green, 21);
|
||||
assert.strictEqual(wasm.Color.Yellow, 34);
|
||||
assert.strictEqual(wasm.Color.Red, 2);
|
||||
assert.strictEqual(Object.keys(wasm.Color).length, 3);
|
||||
|
||||
assert.strictEqual(wasm.cycle(wasm.Color.Green), wasm.Color.Yellow);
|
||||
}
|
||||
"#,
|
||||
assert.strictEqual(wasm.cycle(wasm.Color.Green), wasm.Color.Yellow);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
@ -6,42 +6,42 @@ fn simple() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_random() -> f64 {
|
||||
random()
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn get_random() -> f64 {
|
||||
random()
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn do_log(a: f64) -> f64 {
|
||||
log(a)
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn do_log(a: f64) -> f64 {
|
||||
log(a)
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
#[wasm_bindgen(js_namespace = Math)]
|
||||
fn random() -> f64;
|
||||
#[wasm_bindgen(js_namespace = Math)]
|
||||
fn log(a: f64) -> f64;
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
#[wasm_bindgen(js_namespace = Math)]
|
||||
fn random() -> f64;
|
||||
#[wasm_bindgen(js_namespace = Math)]
|
||||
fn log(a: f64) -> f64;
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
|
||||
export function test() {
|
||||
wasm.get_random();
|
||||
assert.strictEqual(wasm.do_log(1.0), Math.log(1.0));
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
wasm.get_random();
|
||||
assert.strictEqual(wasm.do_log(1.0), Math.log(1.0));
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -52,48 +52,48 @@ fn import_class() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./another")]
|
||||
extern {
|
||||
#[wasm_bindgen(js_namespace = Foo)]
|
||||
fn bar();
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn baz() {
|
||||
bar();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
r#"
|
||||
import { baz } from "./out";
|
||||
import { called } from "./another";
|
||||
import * as assert from "assert";
|
||||
|
||||
export function test() {
|
||||
baz();
|
||||
assert.strictEqual(called, true);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"another.ts",
|
||||
r#"
|
||||
export let called = false;
|
||||
|
||||
export class Foo {
|
||||
static bar() {
|
||||
called = true;
|
||||
#[wasm_bindgen(module = "./another")]
|
||||
extern {
|
||||
#[wasm_bindgen(js_namespace = Foo)]
|
||||
fn bar();
|
||||
}
|
||||
}
|
||||
"#,
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn baz() {
|
||||
bar();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.js",
|
||||
r#"
|
||||
import { baz } from "./out";
|
||||
import { called } from "./another";
|
||||
import * as assert from "assert";
|
||||
|
||||
export function test() {
|
||||
baz();
|
||||
assert.strictEqual(called, true);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"another.js",
|
||||
r#"
|
||||
export let called = false;
|
||||
|
||||
export class Foo {
|
||||
static bar() {
|
||||
called = true;
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -104,77 +104,77 @@ fn construct() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./another")]
|
||||
extern {
|
||||
type Foo;
|
||||
#[wasm_bindgen(js_namespace = Foo)]
|
||||
fn create() -> Foo;
|
||||
#[wasm_bindgen(method)]
|
||||
fn get_internal_string(this: &Foo) -> String;
|
||||
#[wasm_bindgen(method)]
|
||||
fn append_to_internal_string(this: &Foo, s: &str);
|
||||
#[wasm_bindgen(method)]
|
||||
fn assert_internal_string(this: &Foo, s: &str);
|
||||
}
|
||||
#[wasm_bindgen(module = "./another")]
|
||||
extern {
|
||||
type Foo;
|
||||
#[wasm_bindgen(js_namespace = Foo)]
|
||||
fn create() -> Foo;
|
||||
#[wasm_bindgen(method)]
|
||||
fn get_internal_string(this: &Foo) -> String;
|
||||
#[wasm_bindgen(method)]
|
||||
fn append_to_internal_string(this: &Foo, s: &str);
|
||||
#[wasm_bindgen(method)]
|
||||
fn assert_internal_string(this: &Foo, s: &str);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
let f = Foo::create();
|
||||
assert_eq!(f.get_internal_string(), "this");
|
||||
f.append_to_internal_string(" foo");
|
||||
f.assert_internal_string("this foo");
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
let f = Foo::create();
|
||||
assert_eq!(f.get_internal_string(), "this");
|
||||
f.append_to_internal_string(" foo");
|
||||
f.assert_internal_string("this foo");
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { run } from "./out";
|
||||
import { called } from "./another";
|
||||
import * as assert from "assert";
|
||||
import { run } from "./out";
|
||||
import { called } from "./another";
|
||||
import * as assert from "assert";
|
||||
|
||||
export function test() {
|
||||
run();
|
||||
assert.strictEqual(called, true);
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
run();
|
||||
assert.strictEqual(called, true);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"another.ts",
|
||||
"another.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as assert from "assert";
|
||||
|
||||
export let called = false;
|
||||
export let called = false;
|
||||
|
||||
export class Foo {
|
||||
private internal_string: string = '';
|
||||
export class Foo {
|
||||
static create() {
|
||||
const ret = new Foo();
|
||||
ret.internal_string = 'this';
|
||||
return ret;
|
||||
}
|
||||
|
||||
static create() {
|
||||
const ret = new Foo();
|
||||
ret.internal_string = 'this';
|
||||
return ret;
|
||||
get_internal_string() {
|
||||
return this.internal_string;
|
||||
}
|
||||
|
||||
append_to_internal_string(s) {
|
||||
this.internal_string += s;
|
||||
}
|
||||
|
||||
assert_internal_string(s) {
|
||||
assert.strictEqual(this.internal_string, s);
|
||||
called = true;
|
||||
}
|
||||
}
|
||||
|
||||
get_internal_string() {
|
||||
return this.internal_string;
|
||||
}
|
||||
|
||||
append_to_internal_string(s: string) {
|
||||
this.internal_string += s;
|
||||
}
|
||||
|
||||
assert_internal_string(s: string) {
|
||||
assert.strictEqual(this.internal_string, s);
|
||||
called = true;
|
||||
}
|
||||
}
|
||||
"#,
|
||||
Foo.internal_string = '';
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -185,50 +185,51 @@ fn new_constructors() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./another")]
|
||||
extern {
|
||||
type Foo;
|
||||
#[wasm_bindgen(constructor)]
|
||||
fn new(arg: i32) -> Foo;
|
||||
#[wasm_bindgen(method)]
|
||||
fn get(this: &Foo) -> i32;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
let f = Foo::new(1);
|
||||
assert_eq!(f.get(), 2);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
r#"
|
||||
import { run } from "./out";
|
||||
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"another.ts",
|
||||
r#"
|
||||
export class Foo {
|
||||
constructor(private field: number) {
|
||||
#[wasm_bindgen(module = "./another")]
|
||||
extern {
|
||||
type Foo;
|
||||
#[wasm_bindgen(constructor)]
|
||||
fn new(arg: i32) -> Foo;
|
||||
#[wasm_bindgen(method)]
|
||||
fn get(this: &Foo) -> i32;
|
||||
}
|
||||
|
||||
get() {
|
||||
return this.field + 1;
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
let f = Foo::new(1);
|
||||
assert_eq!(f.get(), 2);
|
||||
}
|
||||
}
|
||||
"#,
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.js",
|
||||
r#"
|
||||
import { run } from "./out";
|
||||
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"another.js",
|
||||
r#"
|
||||
export class Foo {
|
||||
constructor(field) {
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
get() {
|
||||
return this.field + 1;
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -239,84 +240,84 @@ fn switch_methods() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./another")]
|
||||
extern {
|
||||
type Foo;
|
||||
#[wasm_bindgen(module = "./another")]
|
||||
extern {
|
||||
type Foo;
|
||||
|
||||
#[wasm_bindgen(constructor)]
|
||||
fn new() -> Foo;
|
||||
#[wasm_bindgen(constructor)]
|
||||
fn new() -> Foo;
|
||||
|
||||
#[wasm_bindgen(js_namespace = Foo)]
|
||||
fn a();
|
||||
#[wasm_bindgen(js_namespace = Foo)]
|
||||
fn a();
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
fn b(this: &Foo);
|
||||
}
|
||||
#[wasm_bindgen(method)]
|
||||
fn b(this: &Foo);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn a() {
|
||||
Foo::a();
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn a() {
|
||||
Foo::a();
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn b() {
|
||||
Foo::new().b();
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn b() {
|
||||
Foo::new().b();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { a, b } from "./out";
|
||||
import { Foo, called } from "./another";
|
||||
import * as assert from "assert";
|
||||
import { a, b } from "./out";
|
||||
import { Foo, called } from "./another";
|
||||
import * as assert from "assert";
|
||||
|
||||
export function test() {
|
||||
assert.strictEqual(called.a, false);
|
||||
a();
|
||||
assert.strictEqual(called.a, true);
|
||||
called.a = false;
|
||||
Foo.a = function() {};
|
||||
assert.strictEqual(called.a, false);
|
||||
a();
|
||||
assert.strictEqual(called.a, true);
|
||||
export function test() {
|
||||
assert.strictEqual(called.a, false);
|
||||
a();
|
||||
assert.strictEqual(called.a, true);
|
||||
called.a = false;
|
||||
Foo.a = function() {};
|
||||
assert.strictEqual(called.a, false);
|
||||
a();
|
||||
assert.strictEqual(called.a, true);
|
||||
|
||||
called.a = false;
|
||||
assert.strictEqual(called.a, false);
|
||||
b();
|
||||
assert.strictEqual(called.a, true);
|
||||
called.a = false;
|
||||
Foo.prototype.b = function() {};
|
||||
assert.strictEqual(called.a, false);
|
||||
b();
|
||||
assert.strictEqual(called.a, true);
|
||||
}
|
||||
"#,
|
||||
called.a = false;
|
||||
assert.strictEqual(called.a, false);
|
||||
b();
|
||||
assert.strictEqual(called.a, true);
|
||||
called.a = false;
|
||||
Foo.prototype.b = function() {};
|
||||
assert.strictEqual(called.a, false);
|
||||
b();
|
||||
assert.strictEqual(called.a, true);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"another.ts",
|
||||
"another.js",
|
||||
r#"
|
||||
export let called = { a: false };
|
||||
export let called = { a: false };
|
||||
|
||||
export class Foo {
|
||||
constructor() {
|
||||
}
|
||||
export class Foo {
|
||||
constructor() {
|
||||
}
|
||||
|
||||
static a() {
|
||||
called.a = true;
|
||||
}
|
||||
static a() {
|
||||
called.a = true;
|
||||
}
|
||||
|
||||
b() {
|
||||
called.a = true;
|
||||
b() {
|
||||
called.a = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -327,62 +328,62 @@ fn properties() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./another")]
|
||||
extern {
|
||||
type Foo;
|
||||
#[wasm_bindgen(module = "./another")]
|
||||
extern {
|
||||
type Foo;
|
||||
|
||||
#[wasm_bindgen(constructor)]
|
||||
fn new() -> Foo;
|
||||
#[wasm_bindgen(constructor)]
|
||||
fn new() -> Foo;
|
||||
|
||||
#[wasm_bindgen(getter, method)]
|
||||
fn a(this: &Foo) -> i32;
|
||||
#[wasm_bindgen(getter, method)]
|
||||
fn a(this: &Foo) -> i32;
|
||||
|
||||
#[wasm_bindgen(setter, method)]
|
||||
fn set_a(this: &Foo, a: i32);
|
||||
}
|
||||
#[wasm_bindgen(setter, method)]
|
||||
fn set_a(this: &Foo, a: i32);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
let a = Foo::new();
|
||||
assert_eq!(a.a(), 1);
|
||||
a.set_a(2);
|
||||
assert_eq!(a.a(), 2);
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
let a = Foo::new();
|
||||
assert_eq!(a.a(), 1);
|
||||
a.set_a(2);
|
||||
assert_eq!(a.a(), 2);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { run } from "./out";
|
||||
import { run } from "./out";
|
||||
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"another.ts",
|
||||
"another.js",
|
||||
r#"
|
||||
export class Foo {
|
||||
constructor(private num: number) {
|
||||
this.num = 1;
|
||||
}
|
||||
export class Foo {
|
||||
constructor() {
|
||||
this.num = 1;
|
||||
}
|
||||
|
||||
get a() {
|
||||
return this.num;
|
||||
}
|
||||
get a() {
|
||||
return this.num;
|
||||
}
|
||||
|
||||
set a(val) {
|
||||
this.num = val;
|
||||
set a(val) {
|
||||
this.num = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -393,62 +394,62 @@ fn rename_setter_getter() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./another")]
|
||||
extern {
|
||||
type Foo;
|
||||
#[wasm_bindgen(module = "./another")]
|
||||
extern {
|
||||
type Foo;
|
||||
|
||||
#[wasm_bindgen(constructor)]
|
||||
fn new() -> Foo;
|
||||
#[wasm_bindgen(constructor)]
|
||||
fn new() -> Foo;
|
||||
|
||||
#[wasm_bindgen(getter = a, method)]
|
||||
fn test(this: &Foo) -> i32;
|
||||
#[wasm_bindgen(getter = a, method)]
|
||||
fn test(this: &Foo) -> i32;
|
||||
|
||||
#[wasm_bindgen(setter = a, method)]
|
||||
fn another(this: &Foo, a: i32);
|
||||
}
|
||||
#[wasm_bindgen(setter = a, method)]
|
||||
fn another(this: &Foo, a: i32);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
let a = Foo::new();
|
||||
assert_eq!(a.test(), 1);
|
||||
a.another(2);
|
||||
assert_eq!(a.test(), 2);
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
let a = Foo::new();
|
||||
assert_eq!(a.test(), 1);
|
||||
a.another(2);
|
||||
assert_eq!(a.test(), 2);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { run } from "./out";
|
||||
import { run } from "./out";
|
||||
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"another.ts",
|
||||
"another.js",
|
||||
r#"
|
||||
export class Foo {
|
||||
constructor(private num: number) {
|
||||
this.num = 1;
|
||||
}
|
||||
export class Foo {
|
||||
constructor() {
|
||||
this.num = 1;
|
||||
}
|
||||
|
||||
get a() {
|
||||
return this.num;
|
||||
}
|
||||
get a() {
|
||||
return this.num;
|
||||
}
|
||||
|
||||
set a(val) {
|
||||
this.num = val;
|
||||
set a(val) {
|
||||
this.num = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
@ -6,84 +6,84 @@ fn simple() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn foo(s: &str);
|
||||
fn another(a: u32) -> i32;
|
||||
fn take_and_return_bool(a: bool) -> bool;
|
||||
fn return_object() -> JsValue;
|
||||
}
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn foo(s: &str);
|
||||
fn another(a: u32) -> i32;
|
||||
fn take_and_return_bool(a: bool) -> bool;
|
||||
fn return_object() -> JsValue;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn bar(s: &str) {
|
||||
foo(s);
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn bar(s: &str) {
|
||||
foo(s);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn another_thunk(a: u32) -> i32 {
|
||||
another(a)
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn another_thunk(a: u32) -> i32 {
|
||||
another(a)
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn bool_thunk(a: bool) -> bool {
|
||||
take_and_return_bool(a)
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn bool_thunk(a: bool) -> bool {
|
||||
take_and_return_bool(a)
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_the_object() -> JsValue {
|
||||
return_object()
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn get_the_object() -> JsValue {
|
||||
return_object()
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
|
||||
let ARG: string | null = null;
|
||||
let ANOTHER_ARG: number | null = null;
|
||||
let SYM = (Symbol as any)('a');
|
||||
let ARG = null;
|
||||
let ANOTHER_ARG = null;
|
||||
let SYM = Symbol('a');
|
||||
|
||||
export function foo(s: string): void {
|
||||
assert.strictEqual(ARG, null);
|
||||
assert.strictEqual(s, "foo");
|
||||
ARG = s;
|
||||
}
|
||||
export function another(s: number): number {
|
||||
assert.strictEqual(ANOTHER_ARG, null);
|
||||
assert.strictEqual(s, 21);
|
||||
ANOTHER_ARG = s;
|
||||
return 35;
|
||||
}
|
||||
export function take_and_return_bool(s: boolean): boolean {
|
||||
return s;
|
||||
}
|
||||
export function return_object(): any {
|
||||
return SYM;
|
||||
}
|
||||
export function foo(s) {
|
||||
assert.strictEqual(ARG, null);
|
||||
assert.strictEqual(s, "foo");
|
||||
ARG = s;
|
||||
}
|
||||
export function another(s) {
|
||||
assert.strictEqual(ANOTHER_ARG, null);
|
||||
assert.strictEqual(s, 21);
|
||||
ANOTHER_ARG = s;
|
||||
return 35;
|
||||
}
|
||||
export function take_and_return_bool(s) {
|
||||
return s;
|
||||
}
|
||||
export function return_object() {
|
||||
return SYM;
|
||||
}
|
||||
|
||||
export function test() {
|
||||
assert.strictEqual(ARG, null);
|
||||
wasm.bar("foo");
|
||||
assert.strictEqual(ARG, "foo");
|
||||
export function test() {
|
||||
assert.strictEqual(ARG, null);
|
||||
wasm.bar("foo");
|
||||
assert.strictEqual(ARG, "foo");
|
||||
|
||||
assert.strictEqual(ANOTHER_ARG, null);
|
||||
assert.strictEqual(wasm.another_thunk(21), 35);
|
||||
assert.strictEqual(ANOTHER_ARG, 21);
|
||||
assert.strictEqual(ANOTHER_ARG, null);
|
||||
assert.strictEqual(wasm.another_thunk(21), 35);
|
||||
assert.strictEqual(ANOTHER_ARG, 21);
|
||||
|
||||
assert.strictEqual(wasm.bool_thunk(true), true);
|
||||
assert.strictEqual(wasm.bool_thunk(false), false);
|
||||
assert.strictEqual(wasm.bool_thunk(true), true);
|
||||
assert.strictEqual(wasm.bool_thunk(false), false);
|
||||
|
||||
assert.strictEqual(wasm.get_the_object(), SYM);
|
||||
}
|
||||
"#,
|
||||
assert.strictEqual(wasm.get_the_object(), SYM);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -94,33 +94,33 @@ fn unused() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![allow(dead_code)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn debug_print(s: &str);
|
||||
}
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn debug_print(s: &str);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn bar() {}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn bar() {}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as wasm from "./out";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function debug_print() {}
|
||||
export function debug_print() {}
|
||||
|
||||
export function test() {
|
||||
wasm.bar();
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
wasm.bar();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -131,36 +131,36 @@ fn string_ret() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn foo() -> String;
|
||||
}
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn foo() -> String;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
assert_eq!(foo(), "bar");
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
assert_eq!(foo(), "bar");
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as wasm from "./out";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function foo(): string {
|
||||
return 'bar';
|
||||
}
|
||||
export function foo() {
|
||||
return 'bar';
|
||||
}
|
||||
|
||||
export function test() {
|
||||
wasm.run();
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
wasm.run();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -171,43 +171,43 @@ fn strings() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn foo(a: String) -> String;
|
||||
}
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn foo(a: String) -> String;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn bar(a: &str) -> String {
|
||||
foo(a.to_string())
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn bar(a: &str) -> String {
|
||||
foo(a.to_string())
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn bar2(a: String) -> String {
|
||||
foo(a)
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn bar2(a: String) -> String {
|
||||
foo(a)
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
|
||||
export function foo(a: string): string {
|
||||
return a + 'b';
|
||||
}
|
||||
export function foo(a) {
|
||||
return a + 'b';
|
||||
}
|
||||
|
||||
export function test() {
|
||||
assert.strictEqual(wasm.bar('a'), 'ab');
|
||||
assert.strictEqual(wasm.bar2('a'), 'ab');
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
assert.strictEqual(wasm.bar('a'), 'ab');
|
||||
assert.strictEqual(wasm.bar2('a'), 'ab');
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -218,60 +218,60 @@ fn exceptions() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn foo();
|
||||
fn bar();
|
||||
#[wasm_bindgen(catch)]
|
||||
fn baz() -> Result<(), JsValue>;
|
||||
}
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn foo();
|
||||
fn bar();
|
||||
#[wasm_bindgen(catch)]
|
||||
fn baz() -> Result<(), JsValue>;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
foo();
|
||||
bar();
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
foo();
|
||||
bar();
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run2() {
|
||||
assert!(baz().is_err());
|
||||
bar();
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn run2() {
|
||||
assert!(baz().is_err());
|
||||
bar();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { run, run2 } from "./out";
|
||||
import * as assert from "assert";
|
||||
import { run, run2 } from "./out";
|
||||
import * as assert from "assert";
|
||||
|
||||
let called = false;
|
||||
let called = false;
|
||||
|
||||
export function foo() {
|
||||
throw new Error('error!');
|
||||
}
|
||||
export function foo() {
|
||||
throw new Error('error!');
|
||||
}
|
||||
|
||||
export function baz() {
|
||||
throw new Error('error2');
|
||||
}
|
||||
export function baz() {
|
||||
throw new Error('error2');
|
||||
}
|
||||
|
||||
export function bar() {
|
||||
called = true;
|
||||
}
|
||||
export function bar() {
|
||||
called = true;
|
||||
}
|
||||
|
||||
export function test() {
|
||||
assert.throws(run, /error!/);
|
||||
assert.strictEqual(called, false);
|
||||
run2();
|
||||
assert.strictEqual(called, true);
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
assert.throws(run, /error!/);
|
||||
assert.strictEqual(called, false);
|
||||
run2();
|
||||
assert.strictEqual(called, true);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -282,40 +282,40 @@ fn exn_caught() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
#[wasm_bindgen(catch)]
|
||||
fn foo() -> Result<(), JsValue>;
|
||||
}
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
#[wasm_bindgen(catch)]
|
||||
fn foo() -> Result<(), JsValue>;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() -> JsValue {
|
||||
foo().unwrap_err()
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn run() -> JsValue {
|
||||
foo().unwrap_err()
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { run } from "./out";
|
||||
import * as assert from "assert";
|
||||
import { run } from "./out";
|
||||
import * as assert from "assert";
|
||||
|
||||
export function foo() {
|
||||
throw new Error('error!');
|
||||
}
|
||||
export function foo() {
|
||||
throw new Error('error!');
|
||||
}
|
||||
|
||||
export function test() {
|
||||
const obj = run();
|
||||
assert.strictEqual(obj instanceof Error, true);
|
||||
assert.strictEqual(obj.message, 'error!');
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
const obj = run();
|
||||
assert.strictEqual(obj instanceof Error, true);
|
||||
assert.strictEqual(obj.message, 'error!');
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -326,32 +326,32 @@ fn free_imports() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
fn parseInt(a: &str) -> u32;
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
fn parseInt(a: &str) -> u32;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
assert_eq!(parseInt("3"), 3);
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
assert_eq!(parseInt("3"), 3);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { run } from "./out";
|
||||
import { run } from "./out";
|
||||
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -363,34 +363,34 @@ fn import_a_field() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
static IMPORT: JsValue;
|
||||
}
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
static IMPORT: JsValue;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
assert_eq!(IMPORT.as_f64(), Some(1.0));
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
assert_eq!(IMPORT.as_f64(), Some(1.0));
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { run } from "./out";
|
||||
import { run } from "./out";
|
||||
|
||||
export const IMPORT = 1.0;
|
||||
export const IMPORT = 1.0;
|
||||
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -401,41 +401,41 @@ fn rename() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
#[wasm_bindgen(js_name = baz)]
|
||||
fn foo();
|
||||
}
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
#[wasm_bindgen(js_name = baz)]
|
||||
fn foo();
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
foo();
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
foo();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
|
||||
let called = false;
|
||||
let called = false;
|
||||
|
||||
export function baz() {
|
||||
called = true;
|
||||
}
|
||||
export function baz() {
|
||||
called = true;
|
||||
}
|
||||
|
||||
export function test() {
|
||||
wasm.run();
|
||||
assert.strictEqual(called, true);
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
wasm.run();
|
||||
assert.strictEqual(called, true);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -443,49 +443,50 @@ fn rename() {
|
||||
#[test]
|
||||
fn versions() {
|
||||
project()
|
||||
.debug(false)
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "webpack", version = "^0.2.0")]
|
||||
extern {
|
||||
fn foo();
|
||||
}
|
||||
#[wasm_bindgen(module = "webpack", version = "^0.2.0")]
|
||||
extern {
|
||||
fn foo();
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
foo();
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
foo();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.js",
|
||||
r#"
|
||||
const fs = require("fs");
|
||||
const assert = require("assert");
|
||||
import * as fs from 'fs';
|
||||
import * as assert from 'assert';
|
||||
|
||||
exports.test = function() {
|
||||
const bytes = fs.readFileSync('out_bg.wasm');
|
||||
const m = new WebAssembly.Module(bytes);
|
||||
const name = '__wasm_pack_unstable';
|
||||
const sections = WebAssembly.Module.customSections(m, name);
|
||||
assert.strictEqual(sections.length, 1);
|
||||
const b = new Uint8Array(sections[0]);
|
||||
const buf = new Buffer(b);
|
||||
const map = JSON.parse(buf.toString());
|
||||
assert.deepStrictEqual(map, {
|
||||
version: '0.0.1',
|
||||
modules: [
|
||||
['webpack', '^0.2.0']
|
||||
]
|
||||
});
|
||||
};
|
||||
"#,
|
||||
export function test() {
|
||||
const bytes = fs.readFileSync('out_bg.wasm');
|
||||
const m = new WebAssembly.Module(bytes);
|
||||
const name = '__wasm_pack_unstable';
|
||||
const sections = WebAssembly.Module.customSections(m, name);
|
||||
assert.strictEqual(sections.length, 1);
|
||||
const b = new Uint8Array(sections[0]);
|
||||
const buf = new Buffer(b);
|
||||
const map = JSON.parse(buf.toString());
|
||||
assert.deepStrictEqual(map, {
|
||||
version: '0.0.1',
|
||||
modules: [
|
||||
['webpack', '^0.2.0']
|
||||
]
|
||||
});
|
||||
};
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -511,10 +512,10 @@ fn underscore_pattern() {
|
||||
foo(1);
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import { run } from "./out";
|
||||
|
||||
export function foo(_a: number) {
|
||||
export function foo(_a) {
|
||||
}
|
||||
|
||||
export function test() {
|
||||
@ -530,37 +531,37 @@ fn rust_keyword() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
#[wasm_bindgen(js_name = self)]
|
||||
fn foo() -> u32;
|
||||
}
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
#[wasm_bindgen(js_name = self)]
|
||||
fn foo() -> u32;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
assert_eq!(foo(), 2);
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
assert_eq!(foo(), 2);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { run } from "./out";
|
||||
import { run } from "./out";
|
||||
|
||||
export function self() {
|
||||
return 2;
|
||||
}
|
||||
export function self() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -572,38 +573,38 @@ fn rust_keyword2() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
pub type bar;
|
||||
#[wasm_bindgen(js_namespace = bar, js_name = foo)]
|
||||
static FOO: JsValue;
|
||||
}
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
pub type bar;
|
||||
#[wasm_bindgen(js_namespace = bar, js_name = foo)]
|
||||
static FOO: JsValue;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
assert_eq!(FOO.as_f64(), Some(3.0));
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
assert_eq!(FOO.as_f64(), Some(3.0));
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { run } from "./out";
|
||||
import { run } from "./out";
|
||||
|
||||
export const bar = {
|
||||
foo: 3,
|
||||
};
|
||||
export const bar = {
|
||||
foo: 3,
|
||||
};
|
||||
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
run();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -645,18 +646,18 @@ fn custom_type() {
|
||||
bad2();
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import { run, Foo, bad } from "./out";
|
||||
|
||||
let VAL: any = null;
|
||||
let VAL = null;
|
||||
|
||||
export function foo(f: Foo): Foo {
|
||||
export function foo(f) {
|
||||
VAL = f;
|
||||
return f;
|
||||
}
|
||||
|
||||
export function bad2(): number {
|
||||
export function bad2() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@ -691,7 +692,7 @@ fn unused_imports_not_generated() {
|
||||
pub fn run() {
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import { run } from "./out";
|
||||
|
||||
export function test() {
|
||||
|
@ -22,7 +22,7 @@ fn filter() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -61,7 +61,7 @@ fn index_of() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -104,27 +104,27 @@ fn is_array() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
assert(wasm.is_array([]));
|
||||
assert(wasm.is_array([1]));
|
||||
assert(wasm.is_array(new Array()));
|
||||
assert(wasm.is_array(new Array('a', 'b', 'c', 'd')));
|
||||
assert(wasm.is_array(new Array(3)));
|
||||
assert(wasm.is_array(Array.prototype));
|
||||
assert.ok(wasm.is_array([]));
|
||||
assert.ok(wasm.is_array([1]));
|
||||
assert.ok(wasm.is_array(new Array()));
|
||||
assert.ok(wasm.is_array(new Array('a', 'b', 'c', 'd')));
|
||||
assert.ok(wasm.is_array(new Array(3)));
|
||||
assert.ok(wasm.is_array(Array.prototype));
|
||||
|
||||
assert(!wasm.is_array({}));
|
||||
assert(!wasm.is_array(null));
|
||||
assert(!wasm.is_array(undefined));
|
||||
assert(!wasm.is_array(17));
|
||||
assert(!wasm.is_array('Array'));
|
||||
assert(!wasm.is_array(true));
|
||||
assert(!wasm.is_array(false));
|
||||
assert(!wasm.is_array({ __proto__: Array.prototype }));
|
||||
assert.ok(!wasm.is_array({}));
|
||||
assert.ok(!wasm.is_array(null));
|
||||
assert.ok(!wasm.is_array(undefined));
|
||||
assert.ok(!wasm.is_array(17));
|
||||
assert.ok(!wasm.is_array('Array'));
|
||||
assert.ok(!wasm.is_array(true));
|
||||
assert.ok(!wasm.is_array(false));
|
||||
assert.ok(!wasm.is_array({ __proto__: Array.prototype }));
|
||||
}
|
||||
"#,
|
||||
)
|
||||
@ -151,7 +151,7 @@ fn sort() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -183,7 +183,7 @@ fn some() {
|
||||
}
|
||||
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -218,7 +218,7 @@ fn last_index_of() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -262,7 +262,7 @@ fn join() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -299,7 +299,7 @@ fn slice() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -335,7 +335,7 @@ fn fill() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -368,7 +368,7 @@ fn copy_within() {
|
||||
}
|
||||
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -406,7 +406,7 @@ fn pop() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -442,7 +442,7 @@ fn push() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -478,7 +478,7 @@ fn reverse() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -514,7 +514,7 @@ fn shift() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -551,7 +551,7 @@ fn unshift() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -588,7 +588,7 @@ fn to_string() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -624,7 +624,7 @@ fn includes() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -665,7 +665,7 @@ fn concat() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -702,20 +702,20 @@ fn length() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
let characters = [8, 5, 4, 3, 1, 2]
|
||||
let charactersLength = wasm.array_length(characters);
|
||||
assert.equal(charactersLength, 6);
|
||||
export function test() {
|
||||
let characters = [8, 5, 4, 3, 1, 2]
|
||||
let charactersLength = wasm.array_length(characters);
|
||||
assert.equal(charactersLength, 6);
|
||||
|
||||
var empty : number[] = [];
|
||||
let emptyLength = wasm.array_length(empty);
|
||||
assert.equal(emptyLength, 0);
|
||||
}
|
||||
var empty = [];
|
||||
let emptyLength = wasm.array_length(empty);
|
||||
assert.equal(emptyLength, 0);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test()
|
||||
@ -727,34 +727,34 @@ fn every() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::js;
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::js;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn array_every_number_is_even(array: &js::Array) -> bool {
|
||||
array.every(&mut |el, _, _| el.as_f64().unwrap() % 2f64 == 0f64)
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn array_every_number_is_even(array: &js::Array) -> bool {
|
||||
array.every(&mut |el, _, _| el.as_f64().unwrap() % 2f64 == 0f64)
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
const arrayEven = [2, 4, 6, 8];
|
||||
const arrayOdd = [1, 3, 5, 7];
|
||||
const arrayMixed = [2, 3, 4, 5];
|
||||
export function test() {
|
||||
const arrayEven = [2, 4, 6, 8];
|
||||
const arrayOdd = [1, 3, 5, 7];
|
||||
const arrayMixed = [2, 3, 4, 5];
|
||||
|
||||
assert(wasm.array_every_number_is_even(arrayEven));
|
||||
assert(!wasm.array_every_number_is_even(arrayOdd));
|
||||
assert(!wasm.array_every_number_is_even(arrayMixed));
|
||||
}
|
||||
"#,
|
||||
assert.ok(wasm.array_every_number_is_even(arrayEven));
|
||||
assert.ok(!wasm.array_every_number_is_even(arrayOdd));
|
||||
assert.ok(!wasm.array_every_number_is_even(arrayMixed));
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test()
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ fn new() {
|
||||
ArrayBuffer::new(42)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -44,7 +44,7 @@ fn is_view() {
|
||||
ArrayBuffer::is_view(value)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -70,7 +70,7 @@ fn slice() {
|
||||
arraybuffer.slice(begin)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -97,7 +97,7 @@ fn slice_with_end() {
|
||||
arraybuffer.slice_with_end(begin, end)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
|
@ -22,7 +22,7 @@ fn keys() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -60,7 +60,7 @@ fn entries() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
@ -21,7 +21,7 @@ fn new_undefined() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -53,7 +53,7 @@ fn new_truely() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
@ -21,7 +21,7 @@ fn get_day() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -55,7 +55,7 @@ fn get_full_year() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -91,7 +91,7 @@ fn new() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -119,7 +119,7 @@ fn now() {
|
||||
Date::now()
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -149,7 +149,7 @@ fn to_date_string() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -183,7 +183,7 @@ fn to_iso_string() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -217,7 +217,7 @@ fn to_json() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -248,7 +248,7 @@ fn to_locale_date_string() {
|
||||
this.to_locale_date_string(locale, options)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -280,7 +280,7 @@ fn to_locale_string() {
|
||||
this.to_locale_string(locale, options)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -313,7 +313,7 @@ fn to_locale_time_string() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -346,7 +346,7 @@ fn to_string() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -379,7 +379,7 @@ fn to_time_string() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -412,7 +412,7 @@ fn to_utc_string() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -441,7 +441,7 @@ fn utc() {
|
||||
Date::utc(2018f64, 6f64)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -471,7 +471,7 @@ fn value_of() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
@ -18,7 +18,7 @@ fn new() {
|
||||
Error::new(message)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -48,7 +48,7 @@ fn message() {
|
||||
this.message()
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -78,7 +78,7 @@ fn set_message() {
|
||||
this.set_message(message);
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -109,7 +109,7 @@ fn name() {
|
||||
this.name()
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -140,7 +140,7 @@ fn set_name() {
|
||||
this.set_name(name);
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -171,7 +171,7 @@ fn to_string() {
|
||||
this.to_string()
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -180,13 +180,13 @@ fn to_string() {
|
||||
|
||||
assert.equal(wasm.error_to_string(error), 'Error: error message 1');
|
||||
|
||||
(error.name as any) = undefined;
|
||||
error.name = undefined;
|
||||
assert.equal(wasm.error_to_string(error), 'Error: error message 1');
|
||||
|
||||
error.name = 'error_name_1';
|
||||
assert.equal(wasm.error_to_string(error), 'error_name_1: error message 1');
|
||||
|
||||
(error.message as any) = undefined;
|
||||
error.message = undefined;
|
||||
assert.equal(wasm.error_to_string(error), 'error_name_1');
|
||||
|
||||
error.name = 'error_name_2';
|
||||
|
@ -21,7 +21,7 @@ fn apply() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -57,7 +57,7 @@ fn bind() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -97,21 +97,21 @@ fn length() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
assert.equal(wasm.fn_length(() => {}), 0);
|
||||
assert.equal(wasm.fn_length((a: string) => console.log(a)), 1);
|
||||
assert.equal(wasm.fn_length((a: string, b: string) => console.log({ a, b })), 2);
|
||||
assert.equal(wasm.fn_length(a => console.log(a)), 1);
|
||||
assert.equal(wasm.fn_length((a, b) => console.log({ a, b })), 2);
|
||||
|
||||
function fn0() {}
|
||||
function fn1(a: string) {
|
||||
function fn1(a) {
|
||||
console.log(a);
|
||||
}
|
||||
function fn2(a: string, b: string) {
|
||||
function fn2(a, b) {
|
||||
console.log({ a, b });
|
||||
}
|
||||
|
||||
@ -143,7 +143,7 @@ fn name() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -190,17 +190,17 @@ fn to_string() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
function fn1(a: any, b: any) { return a + b }
|
||||
const fn2 = (a: number) => console.log(a);
|
||||
function fn1(a, b) { return a + b; }
|
||||
const fn2 = a => console.log(a);
|
||||
|
||||
assert.equal(wasm.get_source_code(fn1), 'function fn1(a, b) { return a + b; }');
|
||||
assert.equal(wasm.get_source_code(fn2), 'function (a) { return console.log(a); }');
|
||||
assert.equal(wasm.get_source_code(fn2), 'a => console.log(a)');
|
||||
}
|
||||
"#,
|
||||
)
|
||||
|
@ -8,40 +8,40 @@ fn return_() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::js;
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::js;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn gen_return(this: &js::Generator, value: &JsValue) -> JsValue {
|
||||
this.return_(value)
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn gen_return(this: &js::Generator, value: &JsValue) -> JsValue {
|
||||
this.return_(value)
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
function* generator() {
|
||||
yield 1;
|
||||
yield 2;
|
||||
export function test() {
|
||||
function* generator() {
|
||||
yield 1;
|
||||
yield 2;
|
||||
}
|
||||
|
||||
const gen = generator();
|
||||
gen.next();
|
||||
|
||||
const res = wasm.gen_return(gen, 42);
|
||||
assert.deepEqual(res, { value: 42, done: true });
|
||||
|
||||
const next = gen.next();
|
||||
assert.deepEqual(next, { value: undefined, done: true });
|
||||
}
|
||||
|
||||
const gen = generator();
|
||||
gen.next();
|
||||
|
||||
const res = wasm.gen_return(gen, 42);
|
||||
assert.deepEqual(res, { value: 42, done: true });
|
||||
|
||||
const next = gen.next();
|
||||
assert.deepEqual(next, { value: undefined, done: true });
|
||||
}
|
||||
"#,
|
||||
"#,
|
||||
)
|
||||
.test()
|
||||
}
|
||||
@ -52,54 +52,54 @@ fn next() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::js;
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::js;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn next(this: &js::Generator, value: &JsValue) -> JsValue {
|
||||
this.next(value)
|
||||
.ok()
|
||||
.expect("generator throws an error")
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn next(this: &js::Generator, value: &JsValue) -> JsValue {
|
||||
this.next(value)
|
||||
.ok()
|
||||
.expect("generator throws an error")
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn next_throws_error(this: &js::Generator, value: &JsValue) -> bool {
|
||||
this.next(value).is_err()
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn next_throws_error(this: &js::Generator, value: &JsValue) -> bool {
|
||||
this.next(value).is_err()
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
function* generator() {
|
||||
const reply = yield '2 * 2';
|
||||
export function test() {
|
||||
function* generator() {
|
||||
const reply = yield '2 * 2';
|
||||
|
||||
return reply === 4;
|
||||
return reply === 4;
|
||||
}
|
||||
|
||||
const gen = generator();
|
||||
|
||||
const q = wasm.next(gen, undefined);
|
||||
assert.deepEqual(q, { value: '2 * 2', done: false });
|
||||
|
||||
const a = wasm.next(gen, 4);
|
||||
assert.deepEqual(a, { value: true, done: true });
|
||||
|
||||
function* brokenGenerator() {
|
||||
throw new Error('Something went wrong');
|
||||
yield 1;
|
||||
}
|
||||
|
||||
assert.ok(wasm.next_throws_error(brokenGenerator(), undefined));
|
||||
}
|
||||
|
||||
const gen = generator();
|
||||
|
||||
const q = wasm.next(gen, undefined);
|
||||
assert.deepEqual(q, { value: '2 * 2', done: false });
|
||||
|
||||
const a = wasm.next(gen, 4);
|
||||
assert.deepEqual(a, { value: true, done: true });
|
||||
|
||||
function* brokenGenerator() {
|
||||
throw new Error('Something went wrong');
|
||||
yield 1;
|
||||
}
|
||||
|
||||
assert(wasm.next_throws_error(brokenGenerator(), undefined));
|
||||
}
|
||||
"#,
|
||||
"#,
|
||||
)
|
||||
.test()
|
||||
}
|
||||
@ -110,37 +110,37 @@ fn throw() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::js;
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::js;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn gen_throws_error(this: &js::Generator, error: &js::Error) -> bool {
|
||||
this.throw(error).is_err()
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn gen_throws_error(this: &js::Generator, error: &js::Error) -> bool {
|
||||
this.throw(error).is_err()
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
function* generator() {
|
||||
yield 1;
|
||||
yield 2;
|
||||
export function test() {
|
||||
function* generator() {
|
||||
yield 1;
|
||||
yield 2;
|
||||
}
|
||||
|
||||
const gen = generator();
|
||||
gen.next();
|
||||
|
||||
assert.ok(wasm.gen_throws_error(gen, new Error('Something went wrong')));
|
||||
assert.deepEqual(gen.next(), { value: undefined, done: true });
|
||||
}
|
||||
|
||||
const gen = generator();
|
||||
gen.next();
|
||||
|
||||
assert(wasm.gen_throws_error(gen, new Error('Something went wrong')));
|
||||
assert.deepEqual(gen.next(), { value: undefined, done: true });
|
||||
}
|
||||
"#,
|
||||
"#,
|
||||
)
|
||||
.test()
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ fn length() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -58,7 +58,7 @@ fn char_at() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -93,7 +93,7 @@ fn char_code_at() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -128,7 +128,7 @@ fn code_point_at() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -162,7 +162,7 @@ fn concat() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -196,7 +196,7 @@ fn includes() {
|
||||
this.includes(search_value, position)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -231,7 +231,7 @@ fn index_of() {
|
||||
this.index_of(search_value, from_index)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -274,7 +274,7 @@ fn slice() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -305,7 +305,7 @@ fn starts_with() {
|
||||
this.starts_with(search_string, position)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -336,7 +336,7 @@ fn substring() {
|
||||
this.substring(index_start, index_end)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -375,7 +375,7 @@ fn substr() {
|
||||
this.substr(start, length)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -411,7 +411,7 @@ fn to_lower_case() {
|
||||
this.to_lower_case()
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -441,7 +441,7 @@ fn to_string() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -470,7 +470,7 @@ fn to_upper_case() {
|
||||
this.to_upper_case()
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -500,7 +500,7 @@ fn trim() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -539,7 +539,7 @@ fn trim_end_and_trim_right() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -579,7 +579,7 @@ fn trim_start_and_trim_left() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -614,7 +614,7 @@ fn value_of() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
@ -17,7 +17,7 @@ fn clear() {
|
||||
this.clear();
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -49,7 +49,7 @@ fn delete() {
|
||||
this.delete(key)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -81,7 +81,7 @@ fn get() {
|
||||
this.get(key)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -112,7 +112,7 @@ fn has() {
|
||||
this.has(key)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -141,7 +141,7 @@ fn new() {
|
||||
js::Map::new()
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -169,7 +169,7 @@ fn set() {
|
||||
this.set(key, value)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -198,7 +198,7 @@ fn size() {
|
||||
this.size()
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -210,4 +210,4 @@ fn size() {
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ fn entries() {
|
||||
this.entries()
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -50,7 +50,7 @@ fn keys() {
|
||||
this.keys()
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -82,7 +82,7 @@ fn values() {
|
||||
this.values()
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -97,4 +97,4 @@ fn values() {
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ fn abs() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -55,7 +55,7 @@ fn acos() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -63,7 +63,7 @@ fn acos() {
|
||||
export function test() {
|
||||
assert.equal(wasm.acos(-1), Math.PI);
|
||||
assert.equal(wasm.acos(0.5), 1.0471975511965979);
|
||||
assert(Number.isNaN(wasm.acos(2)));
|
||||
assert.ok(Number.isNaN(wasm.acos(2)));
|
||||
}
|
||||
"#,
|
||||
)
|
||||
@ -89,7 +89,7 @@ fn acosh() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -97,7 +97,7 @@ fn acosh() {
|
||||
export function test() {
|
||||
assert.equal(wasm.acosh(1), 0);
|
||||
assert.equal(wasm.acosh(2), Math.acosh(2));
|
||||
assert(Number.isNaN(wasm.acosh(0.5)));
|
||||
assert.ok(Number.isNaN(wasm.acosh(0.5)));
|
||||
}
|
||||
"#,
|
||||
)
|
||||
@ -123,7 +123,7 @@ fn asin() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -131,7 +131,7 @@ fn asin() {
|
||||
export function test() {
|
||||
assert.equal(wasm.asin(1), Math.asin(1));
|
||||
assert.equal(wasm.asin(0.5), Math.asin(0.5));
|
||||
assert(Number.isNaN(wasm.asin(2)));
|
||||
assert.ok(Number.isNaN(wasm.asin(2)));
|
||||
}
|
||||
"#,
|
||||
)
|
||||
@ -157,7 +157,7 @@ fn asinh() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -190,7 +190,7 @@ fn atan() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -223,7 +223,7 @@ fn atan2() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -256,7 +256,7 @@ fn atanh() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -264,7 +264,7 @@ fn atanh() {
|
||||
export function test() {
|
||||
assert.equal(wasm.atanh(1), Math.atanh(1));
|
||||
assert.equal(wasm.atanh(0.5), Math.atanh(0.5));
|
||||
assert(Number.isNaN(wasm.atanh(2)));
|
||||
assert.ok(Number.isNaN(wasm.atanh(2)));
|
||||
}
|
||||
"#,
|
||||
)
|
||||
@ -290,7 +290,7 @@ fn cbrt() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -323,7 +323,7 @@ fn ceil() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -356,7 +356,7 @@ fn clz32() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -385,7 +385,7 @@ fn cos() {
|
||||
js::Math::cos(x)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -412,7 +412,7 @@ fn cosh() {
|
||||
js::Math::cosh(x)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -439,7 +439,7 @@ fn exp() {
|
||||
js::Math::exp(x)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -467,7 +467,7 @@ fn expm1() {
|
||||
js::Math::expm1(x)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -500,7 +500,7 @@ fn floor() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -529,7 +529,7 @@ fn fround() {
|
||||
js::Math::fround(x)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -558,7 +558,7 @@ fn imul() {
|
||||
js::Math::imul(x, y)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -586,7 +586,7 @@ fn log() {
|
||||
js::Math::log(x)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -613,7 +613,7 @@ fn log10() {
|
||||
js::Math::log10(x)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -641,7 +641,7 @@ fn log1p() {
|
||||
js::Math::log1p(x)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -649,7 +649,7 @@ fn log1p() {
|
||||
assert.equal(wasm.log1p(1), 0.6931471805599453);
|
||||
assert.equal(wasm.log1p(0), 0);
|
||||
assert.equal(wasm.log1p(-1), -Infinity);
|
||||
assert(isNaN(wasm.log1p(-2)));
|
||||
assert.ok(isNaN(wasm.log1p(-2)));
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
@ -670,7 +670,7 @@ fn log2() {
|
||||
js::Math::log2(x)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -699,14 +699,14 @@ fn pow() {
|
||||
js::Math::pow(base, exponent)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
assert.equal(wasm.pow(7, 2), 49);
|
||||
assert.equal(wasm.pow(3.8, 0.5), Math.pow(3.8, 0.5));
|
||||
assert(Number.isNaN(wasm.pow(-2, 0.5)));
|
||||
assert.ok(Number.isNaN(wasm.pow(-2, 0.5)));
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
@ -727,7 +727,7 @@ fn round() {
|
||||
js::Math::round(x)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -757,7 +757,7 @@ fn sign() {
|
||||
js::Math::sign(x)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -766,7 +766,7 @@ fn sign() {
|
||||
assert.equal(wasm.sign(-3), -1);
|
||||
assert.equal(wasm.sign(2.3), 1);
|
||||
assert.equal(wasm.sign(0), 0);
|
||||
assert(Number.isNaN(wasm.sign(NaN)));
|
||||
assert.ok(Number.isNaN(wasm.sign(NaN)));
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
@ -787,7 +787,7 @@ fn sin() {
|
||||
js::Math::sin(x)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -815,7 +815,7 @@ fn sinh() {
|
||||
js::Math::sinh(x)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -843,7 +843,7 @@ fn sqrt() {
|
||||
js::Math::sqrt(x)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -852,7 +852,7 @@ fn sqrt() {
|
||||
assert.equal(wasm.sqrt(2), Math.sqrt(2));
|
||||
assert.equal(wasm.sqrt(42.42), Math.sqrt(42.42));
|
||||
assert.equal(wasm.sqrt(1), 1);
|
||||
assert(Number.isNaN(wasm.sqrt(-1)));
|
||||
assert.ok(Number.isNaN(wasm.sqrt(-1)));
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
@ -873,7 +873,7 @@ fn tan() {
|
||||
js::Math::tan(x)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -901,7 +901,7 @@ fn tanh() {
|
||||
js::Math::tanh(x)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -929,7 +929,7 @@ fn trunc() {
|
||||
js::Math::trunc(x)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -941,4 +941,4 @@ fn trunc() {
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ fn new() {
|
||||
Number::new(JsValue::from(42))
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -44,7 +44,7 @@ fn to_locale_string() {
|
||||
this.to_locale_string(locale)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -83,7 +83,7 @@ fn to_precision() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -121,7 +121,7 @@ fn to_string() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -156,7 +156,7 @@ fn value_of() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -195,7 +195,7 @@ fn to_fixed() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -233,7 +233,7 @@ fn to_exponential() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
@ -21,7 +21,7 @@ fn new() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -53,18 +53,18 @@ fn has_own_property() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
assert(wasm.has_own_foo_property({ foo: 42 }, "foo"));
|
||||
assert(wasm.has_own_foo_property({ 42: "foo" }, 42));
|
||||
assert(!wasm.has_own_foo_property({ foo: 42 }, "bar"));
|
||||
assert.ok(wasm.has_own_foo_property({ foo: 42 }, "foo"));
|
||||
assert.ok(wasm.has_own_foo_property({ 42: "foo" }, 42));
|
||||
assert.ok(!wasm.has_own_foo_property({ foo: 42 }, "bar"));
|
||||
|
||||
const s = Symbol();
|
||||
assert(wasm.has_own_foo_property({ [s]: "foo" }, s));
|
||||
assert.ok(wasm.has_own_foo_property({ [s]: "foo" }, s));
|
||||
}
|
||||
"#,
|
||||
)
|
||||
@ -96,7 +96,7 @@ fn to_string() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -125,16 +125,16 @@ fn is_extensible() {
|
||||
js::Object::is_extensible(&obj)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
const object = {};
|
||||
assert(wasm.is_extensible(object));
|
||||
assert.ok(wasm.is_extensible(object));
|
||||
|
||||
Object.preventExtensions(object);
|
||||
assert(!wasm.is_extensible(object));
|
||||
assert.ok(!wasm.is_extensible(object));
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
@ -155,16 +155,16 @@ fn is_frozen() {
|
||||
js::Object::is_frozen(&obj)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
const object = {};
|
||||
assert(!wasm.is_frozen(object));
|
||||
assert.ok(!wasm.is_frozen(object));
|
||||
|
||||
Object.freeze(object);
|
||||
assert(wasm.is_frozen(object));
|
||||
assert.ok(wasm.is_frozen(object));
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
@ -185,16 +185,16 @@ fn is_sealed() {
|
||||
js::Object::is_sealed(&obj)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
const object = {};
|
||||
assert(!wasm.is_sealed(object));
|
||||
assert.ok(!wasm.is_sealed(object));
|
||||
|
||||
Object.seal(object);
|
||||
assert(wasm.is_sealed(object));
|
||||
assert.ok(wasm.is_sealed(object));
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
@ -219,7 +219,7 @@ fn is_prototype_of() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -229,8 +229,8 @@ fn is_prototype_of() {
|
||||
|
||||
export function test() {
|
||||
const foo = new Foo();
|
||||
assert(wasm.obj_is_prototype_of_value(Foo.prototype, foo));
|
||||
assert(!wasm.obj_is_prototype_of_value(Bar.prototype, foo));
|
||||
assert.ok(wasm.obj_is_prototype_of_value(Foo.prototype, foo));
|
||||
assert.ok(!wasm.obj_is_prototype_of_value(Bar.prototype, foo));
|
||||
}
|
||||
"#,
|
||||
)
|
||||
@ -256,7 +256,7 @@ fn keys() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -285,7 +285,7 @@ fn prevent_extensions() {
|
||||
js::Object::prevent_extensions(obj);
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -293,7 +293,7 @@ fn prevent_extensions() {
|
||||
const object = {};
|
||||
wasm.prevent_extensions(object);
|
||||
|
||||
assert(!Object.isExtensible(object));
|
||||
assert.ok(!Object.isExtensible(object));
|
||||
assert.throws(() => {
|
||||
'use strict';
|
||||
Object.defineProperty(object, 'foo', { value: 42 });
|
||||
@ -322,19 +322,19 @@ fn property_is_enumerable() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
assert(wasm.property_is_enumerable({ foo: 42 }, "foo"));
|
||||
assert(wasm.property_is_enumerable({ 42: "foo" }, 42));
|
||||
assert(!wasm.property_is_enumerable({}, 42));
|
||||
assert.ok(wasm.property_is_enumerable({ foo: 42 }, "foo"));
|
||||
assert.ok(wasm.property_is_enumerable({ 42: "foo" }, 42));
|
||||
assert.ok(!wasm.property_is_enumerable({}, 42));
|
||||
|
||||
const obj = {};
|
||||
Object.defineProperty(obj, "foo", { enumerable: false });
|
||||
assert(!wasm.property_is_enumerable(obj, "foo"));
|
||||
assert.ok(!wasm.property_is_enumerable(obj, "foo"));
|
||||
|
||||
const s = Symbol();
|
||||
assert.ok(wasm.property_is_enumerable({ [s]: true }, s));
|
||||
@ -359,12 +359,12 @@ fn seal() {
|
||||
js::Object::seal(&value)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
const object: any = { foo: 'bar' };
|
||||
const object = { foo: 'bar' };
|
||||
const sealedObject = wasm.seal(object);
|
||||
assert.strictEqual(object, sealedObject);
|
||||
assert.throws(() => {
|
||||
@ -410,7 +410,7 @@ fn set_prototype_of() {
|
||||
js::Object::set_prototype_of(&object, &prototype)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -419,7 +419,7 @@ fn set_prototype_of() {
|
||||
const newPrototype = { bar: 'baz' };
|
||||
|
||||
const modifiedObject = wasm.set_prototype_of(object, newPrototype);
|
||||
assert(newPrototype.isPrototypeOf(modifiedObject));
|
||||
assert.ok(newPrototype.isPrototypeOf(modifiedObject));
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
@ -445,7 +445,7 @@ fn to_locale_string() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -477,7 +477,7 @@ fn value_of() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -507,7 +507,7 @@ fn values() {
|
||||
js::Object::values(&obj)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
|
@ -18,7 +18,7 @@ fn add() {
|
||||
}
|
||||
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -51,7 +51,7 @@ fn clear() {
|
||||
}
|
||||
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -81,7 +81,7 @@ fn delete() {
|
||||
this.delete(value)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -110,7 +110,7 @@ fn has() {
|
||||
this.has(value)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -139,7 +139,7 @@ fn new() {
|
||||
js::Set::new()
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -168,7 +168,7 @@ fn size() {
|
||||
}
|
||||
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -179,4 +179,4 @@ fn size() {
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ fn entries() {
|
||||
}
|
||||
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -50,7 +50,7 @@ fn keys() {
|
||||
}
|
||||
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -81,7 +81,7 @@ fn values() {
|
||||
}
|
||||
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
@ -94,4 +94,4 @@ fn values() {
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ fn new_undefined() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -53,7 +53,7 @@ fn new_length() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -81,7 +81,7 @@ fn fill() {
|
||||
this.fill(value, start, end)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
|
@ -21,7 +21,7 @@ fn new() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -53,7 +53,7 @@ fn get() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -91,7 +91,7 @@ fn set() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -126,7 +126,7 @@ fn has() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -164,7 +164,7 @@ fn delete() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
@ -21,7 +21,7 @@ fn new() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -53,7 +53,7 @@ fn has() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -91,7 +91,7 @@ fn add() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
@ -132,7 +132,7 @@ fn delete() {
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
@ -29,22 +29,22 @@ fn decode_uri() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::js;
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::js;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
let x = js::decode_uri("https://mozilla.org/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B")
|
||||
.ok()
|
||||
.expect("should decode URI OK");
|
||||
assert_eq!(String::from(x), "https://mozilla.org/?x=шеллы");
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
let x = js::decode_uri("https://mozilla.org/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B")
|
||||
.ok()
|
||||
.expect("should decode URI OK");
|
||||
assert_eq!(String::from(x), "https://mozilla.org/?x=шеллы");
|
||||
|
||||
assert!(js::decode_uri("%E0%A4%A").is_err());
|
||||
}
|
||||
"#,
|
||||
assert!(js::decode_uri("%E0%A4%A").is_err());
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -55,22 +55,22 @@ fn decode_uri_component() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::js;
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::js;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
let x = js::decode_uri_component("%3Fx%3Dtest")
|
||||
.ok()
|
||||
.expect("should decode URI OK");
|
||||
assert_eq!(String::from(x), "?x=test");
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
let x = js::decode_uri_component("%3Fx%3Dtest")
|
||||
.ok()
|
||||
.expect("should decode URI OK");
|
||||
assert_eq!(String::from(x), "?x=test");
|
||||
|
||||
assert!(js::decode_uri_component("%E0%A4%A").is_err());
|
||||
}
|
||||
"#,
|
||||
assert!(js::decode_uri_component("%E0%A4%A").is_err());
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -82,18 +82,18 @@ fn encode_uri() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::js;
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::js;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
let x = js::encode_uri("ABC abc 123");
|
||||
assert_eq!(String::from(x), "ABC%20abc%20123");
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
let x = js::encode_uri("ABC abc 123");
|
||||
assert_eq!(String::from(x), "ABC%20abc%20123");
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -104,18 +104,18 @@ fn encode_uri_component() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::js;
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::js;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
let x = js::encode_uri_component("?x=шеллы");
|
||||
assert_eq!(String::from(x), "%3Fx%3D%D1%88%D0%B5%D0%BB%D0%BB%D1%8B");
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
let x = js::encode_uri_component("?x=шеллы");
|
||||
assert_eq!(String::from(x), "%3Fx%3D%D1%88%D0%B5%D0%BB%D0%BB%D1%8B");
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -126,23 +126,23 @@ fn eval() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::js;
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::js;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
let x = js::eval("42").ok().expect("should eval OK");
|
||||
assert_eq!(x.as_f64().unwrap(), 42.0);
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
let x = js::eval("42").ok().expect("should eval OK");
|
||||
assert_eq!(x.as_f64().unwrap(), 42.0);
|
||||
|
||||
let err = js::eval("(function () { throw 42; }())")
|
||||
.err()
|
||||
.expect("eval should throw");
|
||||
assert_eq!(err.as_f64().unwrap(), 42.0);
|
||||
}
|
||||
"#,
|
||||
let err = js::eval("(function () { throw 42; }())")
|
||||
.err()
|
||||
.expect("eval should throw");
|
||||
assert_eq!(err.as_f64().unwrap(), 42.0);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
@ -6,43 +6,43 @@ fn simple() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn foo(s: &JsValue);
|
||||
}
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn foo(s: &JsValue);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn bar(s: &JsValue) {
|
||||
foo(s);
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn bar(s: &JsValue) {
|
||||
foo(s);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
|
||||
let ARG: string | null = null;
|
||||
let ARG = null;
|
||||
|
||||
export function foo(s: any): void {
|
||||
assert.strictEqual(ARG, null);
|
||||
ARG = s;
|
||||
}
|
||||
export function foo(s) {
|
||||
assert.strictEqual(ARG, null);
|
||||
ARG = s;
|
||||
}
|
||||
|
||||
export function test() {
|
||||
assert.strictEqual(ARG, null);
|
||||
let sym = (Symbol as any)('test');
|
||||
wasm.bar(sym);
|
||||
assert.strictEqual(ARG, sym);
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
assert.strictEqual(ARG, null);
|
||||
let sym = Symbol('test');
|
||||
wasm.bar(sym);
|
||||
assert.strictEqual(ARG, sym);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -53,43 +53,43 @@ fn owned() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn foo(s: JsValue);
|
||||
}
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn foo(s: JsValue);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn bar(s: JsValue) {
|
||||
foo(s);
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn bar(s: JsValue) {
|
||||
foo(s);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
|
||||
let ARG: any = null;
|
||||
let ARG = null;
|
||||
|
||||
export function foo(s: any): void {
|
||||
assert.strictEqual(ARG, null);
|
||||
ARG = s;
|
||||
}
|
||||
export function foo(s) {
|
||||
assert.strictEqual(ARG, null);
|
||||
ARG = s;
|
||||
}
|
||||
|
||||
export function test() {
|
||||
assert.strictEqual(ARG, null);
|
||||
let sym = (Symbol as any)('test');
|
||||
wasm.bar(sym);
|
||||
assert.strictEqual(ARG, sym);
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
assert.strictEqual(ARG, null);
|
||||
let sym = Symbol('test');
|
||||
wasm.bar(sym);
|
||||
assert.strictEqual(ARG, sym);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -100,49 +100,49 @@ fn clone() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn foo1(s: JsValue);
|
||||
fn foo2(s: &JsValue);
|
||||
fn foo3(s: JsValue);
|
||||
fn foo4(s: &JsValue);
|
||||
fn foo5(s: JsValue);
|
||||
}
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn foo1(s: JsValue);
|
||||
fn foo2(s: &JsValue);
|
||||
fn foo3(s: JsValue);
|
||||
fn foo4(s: &JsValue);
|
||||
fn foo5(s: JsValue);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn bar(s: JsValue) {
|
||||
foo1(s.clone());
|
||||
foo2(&s);
|
||||
foo3(s.clone());
|
||||
foo4(&s);
|
||||
foo5(s);
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn bar(s: JsValue) {
|
||||
foo1(s.clone());
|
||||
foo2(&s);
|
||||
foo3(s.clone());
|
||||
foo4(&s);
|
||||
foo5(s);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
|
||||
let ARG = (Symbol as any)('test');
|
||||
let ARG = Symbol('test');
|
||||
|
||||
export function foo1(s: any): void { assert.strictEqual(s, ARG); }
|
||||
export function foo2(s: any): void { assert.strictEqual(s, ARG); }
|
||||
export function foo3(s: any): void { assert.strictEqual(s, ARG); }
|
||||
export function foo4(s: any): void { assert.strictEqual(s, ARG); }
|
||||
export function foo5(s: any): void { assert.strictEqual(s, ARG); }
|
||||
export function foo1(s) { assert.strictEqual(s, ARG); }
|
||||
export function foo2(s) { assert.strictEqual(s, ARG); }
|
||||
export function foo3(s) { assert.strictEqual(s, ARG); }
|
||||
export function foo4(s) { assert.strictEqual(s, ARG); }
|
||||
export function foo5(s) { assert.strictEqual(s, ARG); }
|
||||
|
||||
export function test() {
|
||||
wasm.bar(ARG);
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
wasm.bar(ARG);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -153,46 +153,46 @@ fn promote() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn foo1(s: &JsValue);
|
||||
fn foo2(s: JsValue);
|
||||
fn foo3(s: &JsValue);
|
||||
fn foo4(s: JsValue);
|
||||
}
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn foo1(s: &JsValue);
|
||||
fn foo2(s: JsValue);
|
||||
fn foo3(s: &JsValue);
|
||||
fn foo4(s: JsValue);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn bar(s: &JsValue) {
|
||||
foo1(s);
|
||||
foo2(s.clone());
|
||||
foo3(s);
|
||||
foo4(s.clone());
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn bar(s: &JsValue) {
|
||||
foo1(s);
|
||||
foo2(s.clone());
|
||||
foo3(s);
|
||||
foo4(s.clone());
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
|
||||
let ARG = (Symbol as any)('test');
|
||||
let ARG = Symbol('test');
|
||||
|
||||
export function foo1(s: any): void { assert.strictEqual(s, ARG); }
|
||||
export function foo2(s: any): void { assert.strictEqual(s, ARG); }
|
||||
export function foo3(s: any): void { assert.strictEqual(s, ARG); }
|
||||
export function foo4(s: any): void { assert.strictEqual(s, ARG); }
|
||||
export function foo1(s) { assert.strictEqual(s, ARG); }
|
||||
export function foo2(s) { assert.strictEqual(s, ARG); }
|
||||
export function foo3(s) { assert.strictEqual(s, ARG); }
|
||||
export function foo4(s) { assert.strictEqual(s, ARG); }
|
||||
|
||||
export function test() {
|
||||
wasm.bar(ARG);
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
wasm.bar(ARG);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -203,40 +203,40 @@ fn returning_vector() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn foo() -> JsValue;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn bar() -> Vec<JsValue> {
|
||||
let mut res = Vec::new();
|
||||
for _ in 0..10 {
|
||||
res.push(foo())
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn foo() -> JsValue;
|
||||
}
|
||||
res
|
||||
}
|
||||
"#,
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn bar() -> Vec<JsValue> {
|
||||
let mut res = Vec::new();
|
||||
for _ in 0..10 {
|
||||
res.push(foo())
|
||||
}
|
||||
res
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
|
||||
export function foo(): any { return { "foo": "bar" }; }
|
||||
export function foo() { return { "foo": "bar" }; }
|
||||
|
||||
export function test() {
|
||||
const result = wasm.bar();
|
||||
assert.strictEqual(result.length, 10);
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
const result = wasm.bar();
|
||||
assert.strictEqual(result.length, 10);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -247,36 +247,36 @@ fn another_vector_return() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_array() -> Vec<JsValue> {
|
||||
vec![
|
||||
JsValue::from(1),
|
||||
JsValue::from(2),
|
||||
JsValue::from(3),
|
||||
JsValue::from(4),
|
||||
JsValue::from(5),
|
||||
JsValue::from(6),
|
||||
]
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn get_array() -> Vec<JsValue> {
|
||||
vec![
|
||||
JsValue::from(1),
|
||||
JsValue::from(2),
|
||||
JsValue::from(3),
|
||||
JsValue::from(4),
|
||||
JsValue::from(5),
|
||||
JsValue::from(6),
|
||||
]
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { get_array } from "./out";
|
||||
import * as assert from "assert";
|
||||
import { get_array } from "./out";
|
||||
import * as assert from "assert";
|
||||
|
||||
export function test() {
|
||||
assert.deepStrictEqual(get_array(), [1, 2, 3, 4, 5, 6]);
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
assert.deepStrictEqual(get_array(), [1, 2, 3, 4, 5, 6]);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -290,86 +290,86 @@ fn serde() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
extern crate wasm_bindgen;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct Foo {
|
||||
a: u32,
|
||||
b: String,
|
||||
c: Option<Bar>,
|
||||
d: Bar,
|
||||
}
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct Foo {
|
||||
a: u32,
|
||||
b: String,
|
||||
c: Option<Bar>,
|
||||
d: Bar,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct Bar {
|
||||
a: u32,
|
||||
}
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct Bar {
|
||||
a: u32,
|
||||
}
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn verify(a: JsValue) -> JsValue;
|
||||
}
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn verify(a: JsValue) -> JsValue;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
let js = JsValue::from_serde("foo").unwrap();
|
||||
assert_eq!(js.as_string(), Some("foo".to_string()));
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
let js = JsValue::from_serde("foo").unwrap();
|
||||
assert_eq!(js.as_string(), Some("foo".to_string()));
|
||||
|
||||
let ret = verify(JsValue::from_serde(&Foo {
|
||||
a: 0,
|
||||
b: "foo".to_string(),
|
||||
c: None,
|
||||
d: Bar { a: 1 },
|
||||
}).unwrap());
|
||||
let ret = verify(JsValue::from_serde(&Foo {
|
||||
a: 0,
|
||||
b: "foo".to_string(),
|
||||
c: None,
|
||||
d: Bar { a: 1 },
|
||||
}).unwrap());
|
||||
|
||||
let foo = ret.into_serde::<Foo>().unwrap();
|
||||
assert_eq!(foo.a, 2);
|
||||
assert_eq!(foo.b, "bar");
|
||||
assert!(foo.c.is_some());
|
||||
assert_eq!(foo.c.as_ref().unwrap().a, 3);
|
||||
assert_eq!(foo.d.a, 4);
|
||||
}
|
||||
let foo = ret.into_serde::<Foo>().unwrap();
|
||||
assert_eq!(foo.a, 2);
|
||||
assert_eq!(foo.b, "bar");
|
||||
assert!(foo.c.is_some());
|
||||
assert_eq!(foo.c.as_ref().unwrap().a, 3);
|
||||
assert_eq!(foo.d.a, 4);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn parse(j: &JsValue) {
|
||||
let s = j.into_serde::<String>().unwrap();
|
||||
assert_eq!(s, "bar");
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn parse(j: &JsValue) {
|
||||
let s = j.into_serde::<String>().unwrap();
|
||||
assert_eq!(s, "bar");
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { run, parse } from "./out";
|
||||
import * as assert from "assert";
|
||||
import { run, parse } from "./out";
|
||||
import * as assert from "assert";
|
||||
|
||||
export function verify(a: any) {
|
||||
assert.deepStrictEqual(a, {
|
||||
a: 0,
|
||||
b: 'foo',
|
||||
c: null,
|
||||
d: { a: 1 }
|
||||
});
|
||||
export function verify(a) {
|
||||
assert.deepStrictEqual(a, {
|
||||
a: 0,
|
||||
b: 'foo',
|
||||
c: null,
|
||||
d: { a: 1 }
|
||||
});
|
||||
|
||||
return {
|
||||
a: 2,
|
||||
b: 'bar',
|
||||
c: { a: 3 },
|
||||
d: { a: 4 },
|
||||
return {
|
||||
a: 2,
|
||||
b: 'bar',
|
||||
c: { a: 3 },
|
||||
d: { a: 4 },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function test() {
|
||||
run();
|
||||
parse('bar');
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
run();
|
||||
parse('bar');
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
@ -1,544 +1,7 @@
|
||||
extern crate wasm_bindgen_cli_support as cli;
|
||||
extern crate wasm_bindgen_cli_support;
|
||||
|
||||
use std::env;
|
||||
use std::fs::{self, File};
|
||||
use std::io::{self, Read, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Stdio};
|
||||
use std::sync::atomic::*;
|
||||
use std::sync::{Once, ONCE_INIT};
|
||||
use std::time::Instant;
|
||||
|
||||
static CNT: AtomicUsize = ATOMIC_USIZE_INIT;
|
||||
thread_local!(static IDX: usize = CNT.fetch_add(1, Ordering::SeqCst));
|
||||
|
||||
struct Project {
|
||||
files: Vec<(String, String)>,
|
||||
debug: bool,
|
||||
node: bool,
|
||||
no_std: bool,
|
||||
serde: bool,
|
||||
rlib: bool,
|
||||
node_args: Vec<String>,
|
||||
deps: Vec<String>,
|
||||
}
|
||||
|
||||
fn project() -> Project {
|
||||
let dir = Path::new(env!("CARGO_MANIFEST_DIR"));
|
||||
let mut lockfile = String::new();
|
||||
fs::File::open(&dir.join("Cargo.lock"))
|
||||
.unwrap()
|
||||
.read_to_string(&mut lockfile)
|
||||
.unwrap();
|
||||
Project {
|
||||
debug: true,
|
||||
node: false,
|
||||
no_std: false,
|
||||
serde: false,
|
||||
rlib: false,
|
||||
deps: Vec::new(),
|
||||
node_args: Vec::new(),
|
||||
files: vec![
|
||||
("Cargo.lock".to_string(), lockfile),
|
||||
(
|
||||
"run-node.js".to_string(),
|
||||
r#"require("./test").test();"#.to_string(),
|
||||
),
|
||||
(
|
||||
"webpack.config.js".to_string(),
|
||||
r#"
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
let nodeModules = {};
|
||||
|
||||
// Webpack bundles the modules from node_modules.
|
||||
// For node target, we will not have `fs` module
|
||||
// inside the `node_modules` folder.
|
||||
// This reads the directories in `node_modules`
|
||||
// and give that to externals and webpack ignores
|
||||
// to bundle the modules listed as external.
|
||||
fs.readdirSync('node_modules')
|
||||
.filter(module => module !== '.bin')
|
||||
.forEach(mod => {
|
||||
// External however,expects browser environment.
|
||||
// To make it work in `node` target we
|
||||
// prefix commonjs here.
|
||||
nodeModules[mod] = 'commonjs ' + mod;
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
entry: './run.js',
|
||||
mode: "development",
|
||||
devtool: "source-map",
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.ts$/,
|
||||
use: 'ts-loader',
|
||||
exclude: /node_modules/
|
||||
}
|
||||
]
|
||||
},
|
||||
resolve: {
|
||||
extensions: [ '.ts', '.js', '.wasm' ]
|
||||
},
|
||||
output: {
|
||||
filename: 'bundle.js',
|
||||
path: path.resolve(__dirname, '.')
|
||||
},
|
||||
target: 'node',
|
||||
externals: nodeModules
|
||||
};
|
||||
"#.to_string(),
|
||||
),
|
||||
(
|
||||
"tsconfig.json".to_string(),
|
||||
r#"
|
||||
{
|
||||
"compilerOptions": {
|
||||
"noEmitOnError": true,
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"noUnusedParameters": true,
|
||||
"noUnusedLocals": true,
|
||||
"noImplicitReturns": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"alwaysStrict": true,
|
||||
"strict": true,
|
||||
"target": "es5",
|
||||
"lib": ["es2015"]
|
||||
}
|
||||
}
|
||||
"#.to_string(),
|
||||
),
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
fn root() -> PathBuf {
|
||||
let idx = IDX.with(|x| *x);
|
||||
|
||||
let mut me = env::current_exe().unwrap();
|
||||
me.pop(); // chop off exe name
|
||||
me.pop(); // chop off `deps`
|
||||
me.pop(); // chop off `debug` / `release`
|
||||
me.push("generated-tests");
|
||||
me.push(&format!("test{}", idx));
|
||||
return me;
|
||||
}
|
||||
|
||||
fn assert_bigint_support() -> Option<&'static str> {
|
||||
static BIGINT_SUPPORED: AtomicUsize = ATOMIC_USIZE_INIT;
|
||||
static INIT: Once = ONCE_INIT;
|
||||
|
||||
INIT.call_once(|| {
|
||||
let mut cmd = Command::new("node");
|
||||
cmd.arg("-e").arg("BigInt");
|
||||
cmd.stdin(Stdio::null())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped());
|
||||
if cmd.status().unwrap().success() {
|
||||
BIGINT_SUPPORED.store(1, Ordering::SeqCst);
|
||||
return;
|
||||
}
|
||||
|
||||
cmd.arg("--harmony-bigint");
|
||||
if cmd.status().unwrap().success() {
|
||||
BIGINT_SUPPORED.store(2, Ordering::SeqCst);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
match BIGINT_SUPPORED.load(Ordering::SeqCst) {
|
||||
1 => return None,
|
||||
2 => return Some("--harmony-bigint"),
|
||||
_ => panic!(
|
||||
"the version of node.js that is installed for these tests \
|
||||
does not support `BigInt`, you may wish to try installing \
|
||||
node 10 to fix this"
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
impl Project {
|
||||
fn file(&mut self, name: &str, contents: &str) -> &mut Project {
|
||||
self.files.push((name.to_string(), contents.to_string()));
|
||||
self
|
||||
}
|
||||
|
||||
fn debug(&mut self, debug: bool) -> &mut Project {
|
||||
self.debug = debug;
|
||||
self
|
||||
}
|
||||
|
||||
fn node(&mut self, node: bool) -> &mut Project {
|
||||
self.node = node;
|
||||
self
|
||||
}
|
||||
|
||||
fn no_std(&mut self, no_std: bool) -> &mut Project {
|
||||
self.no_std = no_std;
|
||||
self
|
||||
}
|
||||
|
||||
fn serde(&mut self, serde: bool) -> &mut Project {
|
||||
self.serde = serde;
|
||||
self
|
||||
}
|
||||
|
||||
fn rlib(&mut self, rlib: bool) -> &mut Project {
|
||||
self.rlib = rlib;
|
||||
self
|
||||
}
|
||||
|
||||
fn depend(&mut self, dep: &str) -> &mut Project {
|
||||
self.deps.push(dep.to_string());
|
||||
self
|
||||
}
|
||||
|
||||
fn add_local_dependency(&mut self, name: &str, path: &str) -> &mut Project {
|
||||
self.deps
|
||||
.push(format!("{} = {{ path = '{}' }}", name, path));
|
||||
self
|
||||
}
|
||||
|
||||
fn crate_name(&self) -> String {
|
||||
format!("test{}", IDX.with(|x| *x))
|
||||
}
|
||||
|
||||
fn requires_bigint(&mut self) -> &mut Project {
|
||||
if let Some(arg) = assert_bigint_support() {
|
||||
self.node_args.push(arg.to_string());
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
fn generate_webidl_bindings(&mut self) -> Vec<PathBuf> {
|
||||
let mut res = Vec::new();
|
||||
let mut origpaths = Vec::new();
|
||||
|
||||
for (path, _) in &self.files {
|
||||
let path = Path::new(&path);
|
||||
let extension = path.extension().map(|x| x.to_str().unwrap());
|
||||
|
||||
if extension != Some("webidl") {
|
||||
continue;
|
||||
}
|
||||
|
||||
res.push(path.with_extension("rs"));
|
||||
origpaths.push(path.to_owned());
|
||||
}
|
||||
|
||||
if res.is_empty() {
|
||||
return res;
|
||||
}
|
||||
|
||||
let mut buildrs = r#"
|
||||
extern crate wasm_bindgen_webidl;
|
||||
|
||||
use wasm_bindgen_webidl::compile_file;
|
||||
use std::env;
|
||||
use std::fs::{self, File};
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
|
||||
fn main() {
|
||||
let dest = env::var("OUT_DIR").unwrap();
|
||||
"#.to_string();
|
||||
|
||||
for (path, origpath) in res.iter().zip(origpaths.iter()) {
|
||||
buildrs.push_str(&format!(
|
||||
r#"
|
||||
fs::create_dir_all("{}").unwrap();
|
||||
File::create(&Path::new(&dest).join("{}"))
|
||||
.unwrap()
|
||||
.write_all(
|
||||
compile_file(Path::new("{}"))
|
||||
.unwrap()
|
||||
.as_bytes()
|
||||
)
|
||||
.unwrap();
|
||||
"#,
|
||||
path.parent().unwrap().to_str().unwrap(),
|
||||
path.to_str().unwrap(),
|
||||
origpath.to_str().unwrap(),
|
||||
));
|
||||
|
||||
self.files.push((
|
||||
Path::new("src").join(path).to_str().unwrap().to_string(),
|
||||
format!(
|
||||
r#"include!(concat!(env!("OUT_DIR"), "/{}"));"#,
|
||||
path.display()
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
buildrs.push('}');
|
||||
|
||||
self.files.push(("build.rs".to_string(), buildrs));
|
||||
|
||||
res
|
||||
}
|
||||
|
||||
fn generate_js_entry(&mut self, modules: Vec<PathBuf>) {
|
||||
let mut runjs = r#"
|
||||
import * as process from "process";
|
||||
"#.to_string();
|
||||
|
||||
if !modules.is_empty() {
|
||||
runjs.push_str(r#"Promise.all(["#);
|
||||
for module in &modules {
|
||||
runjs.push_str(&format!(
|
||||
r#"import('./{}'),"#,
|
||||
module.with_extension("").to_str().unwrap()
|
||||
));
|
||||
}
|
||||
runjs.push_str(
|
||||
r#"]).then(results => { results.map(module => Object.assign(global, module));"#,
|
||||
);
|
||||
}
|
||||
|
||||
runjs.push_str(
|
||||
r#"
|
||||
let wasm = import('./out');
|
||||
const test = import('./test');
|
||||
"#,
|
||||
);
|
||||
|
||||
if !modules.is_empty() {
|
||||
runjs.push_str("return ");
|
||||
}
|
||||
|
||||
runjs.push_str(r#"Promise.all([test, wasm])"#);
|
||||
|
||||
if !modules.is_empty() {
|
||||
runjs.push_str("})");
|
||||
}
|
||||
|
||||
runjs.push_str(
|
||||
r#"
|
||||
.then(results => {
|
||||
let [test, wasm] = results;
|
||||
test.test();
|
||||
|
||||
if (wasm.assertStackEmpty)
|
||||
wasm.assertStackEmpty();
|
||||
if (wasm.assertSlabEmpty)
|
||||
wasm.assertSlabEmpty();
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
"#,
|
||||
);
|
||||
self.files.push(("run.js".to_string(), runjs));
|
||||
}
|
||||
|
||||
fn ensure_test_entry(&mut self) {
|
||||
if !self
|
||||
.files
|
||||
.iter()
|
||||
.any(|(path, _)| path == "test.ts" || path == "test.js")
|
||||
{
|
||||
self.files.push((
|
||||
"test.ts".to_string(),
|
||||
r#"export {test} from './out';"#.to_string(),
|
||||
));
|
||||
}
|
||||
}
|
||||
/// build + cargo cmd execution
|
||||
fn cargo_build(&mut self) -> (PathBuf, PathBuf) {
|
||||
let (root, target_dir) = self.build();
|
||||
let mut cmd = Command::new("cargo");
|
||||
cmd.arg("build")
|
||||
.arg("--target")
|
||||
.arg("wasm32-unknown-unknown")
|
||||
.current_dir(&root)
|
||||
.env("CARGO_TARGET_DIR", &target_dir)
|
||||
// Catch any warnings in generated code because we don't want any
|
||||
.env("RUSTFLAGS", "-Dwarnings");
|
||||
run(&mut cmd, "cargo");
|
||||
(root, target_dir)
|
||||
}
|
||||
|
||||
fn build(&mut self) -> (PathBuf, PathBuf) {
|
||||
self.ensure_test_entry();
|
||||
|
||||
let webidl_modules = self.generate_webidl_bindings();
|
||||
self.generate_js_entry(webidl_modules);
|
||||
|
||||
let mut manifest = format!(
|
||||
r#"
|
||||
[package]
|
||||
name = "test{}"
|
||||
version = "0.0.1"
|
||||
authors = []
|
||||
|
||||
[workspace]
|
||||
|
||||
[lib]
|
||||
"#,
|
||||
IDX.with(|x| *x)
|
||||
);
|
||||
|
||||
if !self.rlib {
|
||||
manifest.push_str("crate-type = [\"cdylib\"]\n");
|
||||
}
|
||||
|
||||
manifest.push_str("[build-dependencies]\n");
|
||||
manifest.push_str("wasm-bindgen-webidl = { path = '");
|
||||
manifest.push_str(env!("CARGO_MANIFEST_DIR"));
|
||||
manifest.push_str("/crates/webidl' }\n");
|
||||
|
||||
manifest.push_str("[dependencies]\n");
|
||||
for dep in self.deps.iter() {
|
||||
manifest.push_str(dep);
|
||||
manifest.push_str("\n");
|
||||
}
|
||||
manifest.push_str("wasm-bindgen = { path = '");
|
||||
manifest.push_str(env!("CARGO_MANIFEST_DIR"));
|
||||
manifest.push_str("'");
|
||||
if self.no_std {
|
||||
manifest.push_str(", default-features = false");
|
||||
}
|
||||
if self.serde {
|
||||
manifest.push_str(", features = ['serde-serialize']");
|
||||
}
|
||||
manifest.push_str(" }\n");
|
||||
self.files.push(("Cargo.toml".to_string(), manifest));
|
||||
|
||||
let root = root();
|
||||
drop(fs::remove_dir_all(&root));
|
||||
for &(ref file, ref contents) in self.files.iter() {
|
||||
let dst = root.join(file);
|
||||
fs::create_dir_all(dst.parent().unwrap()).unwrap();
|
||||
fs::File::create(&dst)
|
||||
.unwrap()
|
||||
.write_all(contents.as_ref())
|
||||
.unwrap();
|
||||
}
|
||||
let target_dir = root.parent().unwrap() // chop off test name
|
||||
.parent().unwrap(); // chop off `generated-tests`
|
||||
(root.clone(), target_dir.to_path_buf())
|
||||
}
|
||||
|
||||
fn test(&mut self) {
|
||||
let (root, target_dir) = self.cargo_build();
|
||||
|
||||
self.gen_bindings(&root, &target_dir);
|
||||
let mut wasm = Vec::new();
|
||||
File::open(root.join("out_bg.wasm"))
|
||||
.unwrap()
|
||||
.read_to_end(&mut wasm)
|
||||
.unwrap();
|
||||
let obj = cli::wasm2es6js::Config::new()
|
||||
.base64(true)
|
||||
.generate(&wasm)
|
||||
.expect("failed to convert wasm to js");
|
||||
|
||||
File::create(root.join("out_bg.d.ts"))
|
||||
.unwrap()
|
||||
.write_all(obj.typescript().as_bytes())
|
||||
.unwrap();
|
||||
|
||||
// move files from the root into each test, it looks like this may be
|
||||
// needed for webpack to work well when invoked concurrently.
|
||||
fs::hard_link("package.json", root.join("package.json")).unwrap();
|
||||
if !Path::new("node_modules").exists() {
|
||||
panic!("\n\nfailed to find `node_modules`, have you run `npm install` yet?\n\n");
|
||||
}
|
||||
let cwd = env::current_dir().unwrap();
|
||||
symlink_dir(&cwd.join("node_modules"), &root.join("node_modules")).unwrap();
|
||||
|
||||
if self.node {
|
||||
let mut cmd = Command::new("node");
|
||||
cmd.args(&self.node_args);
|
||||
cmd.arg(root.join("run-node.js")).current_dir(&root);
|
||||
run(&mut cmd, "node");
|
||||
} else {
|
||||
let mut cmd = if cfg!(windows) {
|
||||
let mut c = Command::new("cmd");
|
||||
c.arg("/c");
|
||||
c.arg("npm");
|
||||
c
|
||||
} else {
|
||||
Command::new("npm")
|
||||
};
|
||||
cmd.arg("run").arg("run-webpack").current_dir(&root);
|
||||
run(&mut cmd, "npm");
|
||||
|
||||
let mut cmd = Command::new("node");
|
||||
cmd.args(&self.node_args);
|
||||
cmd.arg(root.join("bundle.js")).current_dir(&root);
|
||||
run(&mut cmd, "node");
|
||||
}
|
||||
}
|
||||
/// execute the cli against the current test .wasm
|
||||
fn gen_bindings(&self, root: &PathBuf, target_dir: &PathBuf) {
|
||||
let idx = IDX.with(|x| *x);
|
||||
let out = target_dir.join(&format!("wasm32-unknown-unknown/debug/test{}.wasm", idx));
|
||||
|
||||
let as_a_module = root.join("out.wasm");
|
||||
fs::copy(&out, &as_a_module).unwrap();
|
||||
|
||||
let res = cli::Bindgen::new()
|
||||
.input_path(&as_a_module)
|
||||
.typescript(true)
|
||||
.nodejs(self.node)
|
||||
.debug(self.debug)
|
||||
.generate(&root);
|
||||
if let Err(e) = res {
|
||||
for e in e.causes() {
|
||||
println!("- {}", e);
|
||||
}
|
||||
panic!("failed");
|
||||
}
|
||||
}
|
||||
fn read_js(&self) -> String {
|
||||
let path = root().join("out.js");
|
||||
println!("js, {:?}", &path);
|
||||
fs::read_to_string(path).expect("Unable to read js")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn symlink_dir(a: &Path, b: &Path) -> io::Result<()> {
|
||||
use std::os::unix::fs::symlink;
|
||||
symlink(a, b)
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn symlink_dir(a: &Path, b: &Path) -> io::Result<()> {
|
||||
use std::os::windows::fs::symlink_dir;
|
||||
symlink_dir(a, b)
|
||||
}
|
||||
|
||||
fn run(cmd: &mut Command, program: &str) {
|
||||
println!("···················································");
|
||||
println!("running {:?}", cmd);
|
||||
let start = Instant::now();
|
||||
let output = match cmd.output() {
|
||||
Ok(output) => output,
|
||||
Err(err) => panic!("failed to spawn `{}`: {}", program, err),
|
||||
};
|
||||
println!("exit: {}", output.status);
|
||||
let dur = start.elapsed();
|
||||
println!(
|
||||
"dur: {}.{:03}ms",
|
||||
dur.as_secs(),
|
||||
dur.subsec_nanos() / 1_000_000
|
||||
);
|
||||
if output.stdout.len() > 0 {
|
||||
println!("stdout ---\n{}", String::from_utf8_lossy(&output.stdout));
|
||||
}
|
||||
if output.stderr.len() > 0 {
|
||||
println!("stderr ---\n{}", String::from_utf8_lossy(&output.stderr));
|
||||
}
|
||||
assert!(output.status.success());
|
||||
}
|
||||
mod project_builder;
|
||||
use project_builder::{project, run};
|
||||
|
||||
mod api;
|
||||
mod char;
|
||||
@ -559,6 +22,7 @@ mod non_wasm;
|
||||
mod simple;
|
||||
mod slice;
|
||||
mod structural;
|
||||
mod typescript;
|
||||
mod u64;
|
||||
mod validate_prt;
|
||||
mod webidl;
|
||||
|
@ -6,77 +6,77 @@ fn auto_bind_math() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn math(a: f32, b: f64) -> f64 {
|
||||
b.acos() +
|
||||
b.asin() +
|
||||
b.atan() +
|
||||
b.atan2(b) +
|
||||
b.cbrt() +
|
||||
b.cosh() +
|
||||
b.exp_m1() +
|
||||
b.ln_1p() +
|
||||
b.sinh() +
|
||||
b.tan() +
|
||||
b.tanh() +
|
||||
b.hypot(b) +
|
||||
b.cos() +
|
||||
b.exp() +
|
||||
b.exp2() +
|
||||
b.mul_add(b, b) +
|
||||
b.ln() +
|
||||
b.log(b) +
|
||||
b.log10() +
|
||||
b.log2() +
|
||||
b.powi(8) +
|
||||
b.powf(b) +
|
||||
b.round() +
|
||||
b.sin() +
|
||||
b.abs() +
|
||||
b.signum() +
|
||||
b.floor() +
|
||||
b.ceil() +
|
||||
b.trunc() +
|
||||
b.sqrt() +
|
||||
(b % (a as f64)) +
|
||||
((a.cos() +
|
||||
a.exp() +
|
||||
a.exp2() +
|
||||
a.mul_add(a, a) +
|
||||
a.ln() +
|
||||
a.log(a) +
|
||||
a.log10() +
|
||||
a.log2() +
|
||||
a.powi(8) +
|
||||
a.powf(a) +
|
||||
a.round() +
|
||||
a.sin() +
|
||||
a.abs() +
|
||||
a.signum() +
|
||||
a.floor() +
|
||||
a.ceil() +
|
||||
a.trunc() +
|
||||
a.sqrt() +
|
||||
(a % (b as f32))) as f64) +
|
||||
(b + 2.0f64.powf(a as f64))
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn math(a: f32, b: f64) -> f64 {
|
||||
b.acos() +
|
||||
b.asin() +
|
||||
b.atan() +
|
||||
b.atan2(b) +
|
||||
b.cbrt() +
|
||||
b.cosh() +
|
||||
b.exp_m1() +
|
||||
b.ln_1p() +
|
||||
b.sinh() +
|
||||
b.tan() +
|
||||
b.tanh() +
|
||||
b.hypot(b) +
|
||||
b.cos() +
|
||||
b.exp() +
|
||||
b.exp2() +
|
||||
b.mul_add(b, b) +
|
||||
b.ln() +
|
||||
b.log(b) +
|
||||
b.log10() +
|
||||
b.log2() +
|
||||
b.powi(8) +
|
||||
b.powf(b) +
|
||||
b.round() +
|
||||
b.sin() +
|
||||
b.abs() +
|
||||
b.signum() +
|
||||
b.floor() +
|
||||
b.ceil() +
|
||||
b.trunc() +
|
||||
b.sqrt() +
|
||||
(b % (a as f64)) +
|
||||
((a.cos() +
|
||||
a.exp() +
|
||||
a.exp2() +
|
||||
a.mul_add(a, a) +
|
||||
a.ln() +
|
||||
a.log(a) +
|
||||
a.log10() +
|
||||
a.log2() +
|
||||
a.powi(8) +
|
||||
a.powf(a) +
|
||||
a.round() +
|
||||
a.sin() +
|
||||
a.abs() +
|
||||
a.signum() +
|
||||
a.floor() +
|
||||
a.ceil() +
|
||||
a.trunc() +
|
||||
a.sqrt() +
|
||||
(a % (b as f32))) as f64) +
|
||||
(b + 2.0f64.powf(a as f64))
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import { math } from "./out";
|
||||
import { math } from "./out";
|
||||
|
||||
export function test() {
|
||||
math(1.0, 2.0);
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
math(1.0, 2.0);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
@ -3,158 +3,159 @@ use super::project;
|
||||
#[test]
|
||||
fn works() {
|
||||
project()
|
||||
.node(true)
|
||||
.debug(false)
|
||||
.nodejs_experimental_modules(false)
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
static FOO: JsValue;
|
||||
fn hit();
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
hit();
|
||||
assert_eq!(FOO.as_f64(), Some(1.0));
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub struct Foo {
|
||||
contents: u32,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl Foo {
|
||||
pub fn new() -> Foo {
|
||||
Foo::with_contents(0)
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
static FOO: JsValue;
|
||||
fn hit();
|
||||
}
|
||||
pub fn with_contents(a: u32) -> Foo {
|
||||
Foo { contents: a }
|
||||
}
|
||||
pub fn add(&mut self, amt: u32) -> u32 {
|
||||
self.contents += amt;
|
||||
self.contents
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub enum Color {
|
||||
Green,
|
||||
Yellow,
|
||||
Red,
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn cycle(color: Color) -> Color {
|
||||
match color {
|
||||
Color::Green => Color::Yellow,
|
||||
Color::Yellow => Color::Red,
|
||||
Color::Red => Color::Green,
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
hit();
|
||||
assert_eq!(FOO.as_f64(), Some(1.0));
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn math(a: f32, b: f64) -> f64 {
|
||||
b.acos() +
|
||||
b.asin() +
|
||||
b.atan() +
|
||||
b.atan2(b) +
|
||||
b.cbrt() +
|
||||
b.cosh() +
|
||||
b.exp_m1() +
|
||||
b.ln_1p() +
|
||||
b.sinh() +
|
||||
b.tan() +
|
||||
b.tanh() +
|
||||
b.hypot(b) +
|
||||
b.cos() +
|
||||
b.exp() +
|
||||
b.exp2() +
|
||||
b.mul_add(b, b) +
|
||||
b.ln() +
|
||||
b.log(b) +
|
||||
b.log10() +
|
||||
b.log2() +
|
||||
b.powi(8) +
|
||||
b.powf(b) +
|
||||
b.round() +
|
||||
b.sin() +
|
||||
b.abs() +
|
||||
b.signum() +
|
||||
b.floor() +
|
||||
b.ceil() +
|
||||
b.trunc() +
|
||||
b.sqrt() +
|
||||
(b % (a as f64)) +
|
||||
((a.cos() +
|
||||
a.exp() +
|
||||
a.exp2() +
|
||||
a.mul_add(a, a) +
|
||||
a.ln() +
|
||||
a.log(a) +
|
||||
a.log10() +
|
||||
a.log2() +
|
||||
a.powi(8) +
|
||||
a.powf(a) +
|
||||
a.round() +
|
||||
a.sin() +
|
||||
a.abs() +
|
||||
a.signum() +
|
||||
a.floor() +
|
||||
a.ceil() +
|
||||
a.trunc() +
|
||||
a.sqrt() +
|
||||
(a % (b as f32))) as f64) +
|
||||
(b + 2.0f64.powf(a as f64))
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub struct Foo {
|
||||
contents: u32,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl Foo {
|
||||
pub fn new() -> Foo {
|
||||
Foo::with_contents(0)
|
||||
}
|
||||
pub fn with_contents(a: u32) -> Foo {
|
||||
Foo { contents: a }
|
||||
}
|
||||
pub fn add(&mut self, amt: u32) -> u32 {
|
||||
self.contents += amt;
|
||||
self.contents
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub enum Color {
|
||||
Green,
|
||||
Yellow,
|
||||
Red,
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn cycle(color: Color) -> Color {
|
||||
match color {
|
||||
Color::Green => Color::Yellow,
|
||||
Color::Yellow => Color::Red,
|
||||
Color::Red => Color::Green,
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn math(a: f32, b: f64) -> f64 {
|
||||
b.acos() +
|
||||
b.asin() +
|
||||
b.atan() +
|
||||
b.atan2(b) +
|
||||
b.cbrt() +
|
||||
b.cosh() +
|
||||
b.exp_m1() +
|
||||
b.ln_1p() +
|
||||
b.sinh() +
|
||||
b.tan() +
|
||||
b.tanh() +
|
||||
b.hypot(b) +
|
||||
b.cos() +
|
||||
b.exp() +
|
||||
b.exp2() +
|
||||
b.mul_add(b, b) +
|
||||
b.ln() +
|
||||
b.log(b) +
|
||||
b.log10() +
|
||||
b.log2() +
|
||||
b.powi(8) +
|
||||
b.powf(b) +
|
||||
b.round() +
|
||||
b.sin() +
|
||||
b.abs() +
|
||||
b.signum() +
|
||||
b.floor() +
|
||||
b.ceil() +
|
||||
b.trunc() +
|
||||
b.sqrt() +
|
||||
(b % (a as f64)) +
|
||||
((a.cos() +
|
||||
a.exp() +
|
||||
a.exp2() +
|
||||
a.mul_add(a, a) +
|
||||
a.ln() +
|
||||
a.log(a) +
|
||||
a.log10() +
|
||||
a.log2() +
|
||||
a.powi(8) +
|
||||
a.powf(a) +
|
||||
a.round() +
|
||||
a.sin() +
|
||||
a.abs() +
|
||||
a.signum() +
|
||||
a.floor() +
|
||||
a.ceil() +
|
||||
a.trunc() +
|
||||
a.sqrt() +
|
||||
(a % (b as f32))) as f64) +
|
||||
(b + 2.0f64.powf(a as f64))
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.js",
|
||||
r#"
|
||||
const assert = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
var called = false;
|
||||
var called = false;
|
||||
|
||||
module.exports.hit = function() {
|
||||
called = true;
|
||||
};
|
||||
module.exports.FOO = 1.0;
|
||||
module.exports.hit = function() {
|
||||
called = true;
|
||||
};
|
||||
|
||||
const { math, run, Foo, Color, cycle } = require('./out');
|
||||
module.exports.FOO = 1.0;
|
||||
|
||||
module.exports.test = function() {
|
||||
run();
|
||||
assert.strictEqual(called, true);
|
||||
const { math, run, Foo, Color, cycle } = require('./out');
|
||||
|
||||
var r = Foo.new();
|
||||
assert.strictEqual(r.add(0), 0);
|
||||
assert.strictEqual(r.add(1), 1);
|
||||
assert.strictEqual(r.add(2), 3);
|
||||
r.free();
|
||||
module.exports.test = function() {
|
||||
run();
|
||||
assert.strictEqual(called, true);
|
||||
|
||||
var r2 = Foo.with_contents(10);
|
||||
assert.strictEqual(r2.add(0), 10);
|
||||
assert.strictEqual(r2.add(1), 11);
|
||||
assert.strictEqual(r2.add(2), 13);
|
||||
r2.free();
|
||||
var r = Foo.new();
|
||||
assert.strictEqual(r.add(0), 0);
|
||||
assert.strictEqual(r.add(1), 1);
|
||||
assert.strictEqual(r.add(2), 3);
|
||||
r.free();
|
||||
|
||||
assert.strictEqual(Color.Green, 0);
|
||||
assert.strictEqual(Color.Yellow, 1);
|
||||
assert.strictEqual(Color.Red, 2);
|
||||
assert.strictEqual(Object.keys(Color).length, 3);
|
||||
assert.strictEqual(cycle(Color.Green), Color.Yellow);
|
||||
var r2 = Foo.with_contents(10);
|
||||
assert.strictEqual(r2.add(0), 10);
|
||||
assert.strictEqual(r2.add(1), 11);
|
||||
assert.strictEqual(r2.add(2), 13);
|
||||
r2.free();
|
||||
|
||||
math(1.0, 2.0);
|
||||
};
|
||||
assert.strictEqual(Color.Green, 0);
|
||||
assert.strictEqual(Color.Yellow, 1);
|
||||
assert.strictEqual(Color.Red, 2);
|
||||
assert.strictEqual(Object.keys(Color).length, 3);
|
||||
assert.strictEqual(cycle(Color.Green), Color.Yellow);
|
||||
|
||||
"#,
|
||||
math(1.0, 2.0);
|
||||
};
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
@ -7,42 +7,42 @@ fn works() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub struct A {}
|
||||
#[wasm_bindgen]
|
||||
pub struct A {}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl A {
|
||||
pub fn new() -> A {
|
||||
A {}
|
||||
#[wasm_bindgen]
|
||||
impl A {
|
||||
pub fn new() -> A {
|
||||
A {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn clone(a: &JsValue) -> JsValue {
|
||||
drop(a.clone());
|
||||
a.clone()
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn clone(a: &JsValue) -> JsValue {
|
||||
drop(a.clone());
|
||||
a.clone()
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
let sym = (Symbol as any)('a');
|
||||
assert.strictEqual(wasm.clone(sym), sym);
|
||||
let a = wasm.A.new();
|
||||
a.free();
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
let sym = Symbol('a');
|
||||
assert.strictEqual(wasm.clone(sym), sym);
|
||||
let a = wasm.A.new();
|
||||
a.free();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
640
tests/all/project_builder.rs
Normal file
640
tests/all/project_builder.rs
Normal file
@ -0,0 +1,640 @@
|
||||
use wasm_bindgen_cli_support as cli;
|
||||
|
||||
use std::env;
|
||||
use std::fs::{self, File};
|
||||
use std::io::{self, Read, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Stdio};
|
||||
use std::sync::atomic::*;
|
||||
use std::sync::{Once, ONCE_INIT};
|
||||
use std::time::Instant;
|
||||
|
||||
static CNT: AtomicUsize = ATOMIC_USIZE_INIT;
|
||||
thread_local!(static IDX: usize = CNT.fetch_add(1, Ordering::SeqCst));
|
||||
|
||||
pub struct Project {
|
||||
files: Vec<(String, String)>,
|
||||
debug: bool,
|
||||
node: bool,
|
||||
nodejs_experimental_modules: bool,
|
||||
no_std: bool,
|
||||
serde: bool,
|
||||
rlib: bool,
|
||||
webpack: bool,
|
||||
node_args: Vec<String>,
|
||||
deps: Vec<String>,
|
||||
}
|
||||
|
||||
pub fn project() -> Project {
|
||||
let dir = Path::new(env!("CARGO_MANIFEST_DIR"));
|
||||
let mut lockfile = String::new();
|
||||
fs::File::open(&dir.join("Cargo.lock"))
|
||||
.unwrap()
|
||||
.read_to_string(&mut lockfile)
|
||||
.unwrap();
|
||||
Project {
|
||||
debug: true,
|
||||
no_std: false,
|
||||
node: true,
|
||||
nodejs_experimental_modules: true,
|
||||
webpack: false,
|
||||
serde: false,
|
||||
rlib: false,
|
||||
deps: Vec::new(),
|
||||
node_args: Vec::new(),
|
||||
files: vec![
|
||||
("Cargo.lock".to_string(), lockfile),
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
fn root() -> PathBuf {
|
||||
let idx = IDX.with(|x| *x);
|
||||
|
||||
let mut me = env::current_exe().unwrap();
|
||||
me.pop(); // chop off exe name
|
||||
me.pop(); // chop off `deps`
|
||||
me.pop(); // chop off `debug` / `release`
|
||||
me.push("generated-tests");
|
||||
me.push(&format!("test{}", idx));
|
||||
return me;
|
||||
}
|
||||
|
||||
fn assert_bigint_support() -> Option<&'static str> {
|
||||
static BIGINT_SUPPORED: AtomicUsize = ATOMIC_USIZE_INIT;
|
||||
static INIT: Once = ONCE_INIT;
|
||||
|
||||
INIT.call_once(|| {
|
||||
let mut cmd = Command::new("node");
|
||||
cmd.arg("-e").arg("BigInt");
|
||||
cmd.stdin(Stdio::null())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped());
|
||||
if cmd.status().unwrap().success() {
|
||||
BIGINT_SUPPORED.store(1, Ordering::SeqCst);
|
||||
return;
|
||||
}
|
||||
|
||||
cmd.arg("--harmony-bigint");
|
||||
if cmd.status().unwrap().success() {
|
||||
BIGINT_SUPPORED.store(2, Ordering::SeqCst);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
match BIGINT_SUPPORED.load(Ordering::SeqCst) {
|
||||
1 => return None,
|
||||
2 => return Some("--harmony-bigint"),
|
||||
_ => panic!(
|
||||
"the version of node.js that is installed for these tests \
|
||||
does not support `BigInt`, you may wish to try installing \
|
||||
node 10 to fix this"
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
impl Project {
|
||||
/// Add a new file with the specified contents to this project, the `name`
|
||||
/// can have slahes for files in subdirectories.
|
||||
pub fn file(&mut self, name: &str, contents: &str) -> &mut Project {
|
||||
self.files.push((name.to_string(), contents.to_string()));
|
||||
self
|
||||
}
|
||||
|
||||
/// Enable debug mode in wasm-bindgen for this test
|
||||
pub fn debug(&mut self, debug: bool) -> &mut Project {
|
||||
self.debug = debug;
|
||||
self
|
||||
}
|
||||
|
||||
/// Depend on `wasm-bindgen` without the `std` feature enabled.
|
||||
pub fn no_std(&mut self, no_std: bool) -> &mut Project {
|
||||
self.no_std = no_std;
|
||||
self
|
||||
}
|
||||
|
||||
/// Depend on the `serde` feature of `wasm-bindgen`
|
||||
pub fn serde(&mut self, serde: bool) -> &mut Project {
|
||||
self.serde = serde;
|
||||
self
|
||||
}
|
||||
|
||||
/// Generate an rlib instead of a cdylib in the generated Cargo project
|
||||
pub fn rlib(&mut self, rlib: bool) -> &mut Project {
|
||||
self.rlib = rlib;
|
||||
self
|
||||
}
|
||||
|
||||
/// Depend on a crate from crates.io, like serde.
|
||||
pub fn depend(&mut self, dep: &str) -> &mut Project {
|
||||
self.deps.push(dep.to_string());
|
||||
self
|
||||
}
|
||||
|
||||
/// Enables or disables node.js experimental modules output
|
||||
pub fn nodejs_experimental_modules(&mut self, node: bool) -> &mut Project {
|
||||
self.nodejs_experimental_modules = node;
|
||||
self
|
||||
}
|
||||
|
||||
/// Enables or disables the usage of webpack for this project
|
||||
pub fn webpack(&mut self, webpack: bool) -> &mut Project {
|
||||
self.webpack = webpack;
|
||||
self
|
||||
}
|
||||
|
||||
/// Add a path dependency to the generated project
|
||||
pub fn add_local_dependency(&mut self, name: &str, path: &str) -> &mut Project {
|
||||
self.deps
|
||||
.push(format!("{} = {{ path = '{}' }}", name, path));
|
||||
self
|
||||
}
|
||||
|
||||
/// Returns the crate name that will be used for the generated crate, this
|
||||
/// name changes between test runs and is generated at runtime.
|
||||
pub fn crate_name(&self) -> String {
|
||||
format!("test{}", IDX.with(|x| *x))
|
||||
}
|
||||
|
||||
/// Flag this project as requiring bigint support in Node
|
||||
pub fn requires_bigint(&mut self) -> &mut Project {
|
||||
if let Some(arg) = assert_bigint_support() {
|
||||
self.node_args.push(arg.to_string());
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
/// Write this project to the filesystem, ensuring all files are ready to
|
||||
/// go.
|
||||
pub fn build(&mut self) -> (PathBuf, PathBuf) {
|
||||
if self.webpack {
|
||||
self.node = false;
|
||||
self.nodejs_experimental_modules = false;
|
||||
}
|
||||
|
||||
self.ensure_webpack_config();
|
||||
self.ensure_test_entry();
|
||||
|
||||
let webidl_modules = self.generate_webidl_bindings();
|
||||
self.generate_js_entry(webidl_modules);
|
||||
|
||||
let mut manifest = format!(
|
||||
r#"
|
||||
[package]
|
||||
name = "test{}"
|
||||
version = "0.0.1"
|
||||
authors = []
|
||||
|
||||
[workspace]
|
||||
|
||||
[lib]
|
||||
"#,
|
||||
IDX.with(|x| *x)
|
||||
);
|
||||
|
||||
if !self.rlib {
|
||||
manifest.push_str("crate-type = [\"cdylib\"]\n");
|
||||
}
|
||||
|
||||
manifest.push_str("[build-dependencies]\n");
|
||||
manifest.push_str("wasm-bindgen-webidl = { path = '");
|
||||
manifest.push_str(env!("CARGO_MANIFEST_DIR"));
|
||||
manifest.push_str("/crates/webidl' }\n");
|
||||
|
||||
manifest.push_str("[dependencies]\n");
|
||||
for dep in self.deps.iter() {
|
||||
manifest.push_str(dep);
|
||||
manifest.push_str("\n");
|
||||
}
|
||||
manifest.push_str("wasm-bindgen = { path = '");
|
||||
manifest.push_str(env!("CARGO_MANIFEST_DIR"));
|
||||
manifest.push_str("'");
|
||||
if self.no_std {
|
||||
manifest.push_str(", default-features = false");
|
||||
}
|
||||
if self.serde {
|
||||
manifest.push_str(", features = ['serde-serialize']");
|
||||
}
|
||||
manifest.push_str(" }\n");
|
||||
self.files.push(("Cargo.toml".to_string(), manifest));
|
||||
|
||||
let root = root();
|
||||
drop(fs::remove_dir_all(&root));
|
||||
for &(ref file, ref contents) in self.files.iter() {
|
||||
let mut dst = root.join(file);
|
||||
if self.nodejs_experimental_modules &&
|
||||
dst.extension().and_then(|s| s.to_str()) == Some("js")
|
||||
{
|
||||
dst = dst.with_extension("mjs");
|
||||
}
|
||||
if dst.extension().and_then(|s| s.to_str()) == Some("ts") &&
|
||||
!self.webpack
|
||||
{
|
||||
panic!("webpack needs to be enabled to use typescript");
|
||||
}
|
||||
fs::create_dir_all(dst.parent().unwrap()).unwrap();
|
||||
fs::File::create(&dst)
|
||||
.unwrap()
|
||||
.write_all(contents.as_ref())
|
||||
.unwrap();
|
||||
}
|
||||
let target_dir = root.parent().unwrap() // chop off test name
|
||||
.parent().unwrap(); // chop off `generated-tests`
|
||||
(root.clone(), target_dir.to_path_buf())
|
||||
}
|
||||
|
||||
fn ensure_webpack_config(&mut self) {
|
||||
if !self.webpack {
|
||||
return
|
||||
}
|
||||
|
||||
let needs_typescript = self.files.iter().any(|t| t.0.ends_with(".ts"));
|
||||
|
||||
let mut rules = String::new();
|
||||
let mut extensions = format!("'.js', '.wasm'");
|
||||
if needs_typescript {
|
||||
rules.push_str("
|
||||
{
|
||||
test: /.ts$/,
|
||||
use: 'ts-loader',
|
||||
exclude: /node_modules/,
|
||||
}
|
||||
");
|
||||
extensions.push_str(", '.ts'");
|
||||
}
|
||||
self.files.push((
|
||||
"webpack.config.js".to_string(),
|
||||
format!(r#"
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
let nodeModules = {{}};
|
||||
|
||||
// Webpack bundles the modules from node_modules.
|
||||
// For node target, we will not have `fs` module
|
||||
// inside the `node_modules` folder.
|
||||
// This reads the directories in `node_modules`
|
||||
// and give that to externals and webpack ignores
|
||||
// to bundle the modules listed as external.
|
||||
fs.readdirSync('node_modules')
|
||||
.filter(module => module !== '.bin')
|
||||
.forEach(mod => {{
|
||||
// External however,expects browser environment.
|
||||
// To make it work in `node` target we
|
||||
// prefix commonjs here.
|
||||
nodeModules[mod] = 'commonjs ' + mod;
|
||||
}});
|
||||
|
||||
module.exports = {{
|
||||
entry: './run.js',
|
||||
mode: "development",
|
||||
devtool: "source-map",
|
||||
module: {{
|
||||
rules: [{}]
|
||||
}},
|
||||
resolve: {{
|
||||
extensions: [{}]
|
||||
}},
|
||||
output: {{
|
||||
filename: 'bundle.js',
|
||||
path: path.resolve(__dirname, '.')
|
||||
}},
|
||||
target: 'node',
|
||||
externals: nodeModules
|
||||
}};
|
||||
"#, rules, extensions)
|
||||
));
|
||||
if needs_typescript {
|
||||
self.files.push((
|
||||
"tsconfig.json".to_string(),
|
||||
r#"
|
||||
{
|
||||
"compilerOptions": {
|
||||
"noEmitOnError": true,
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"noUnusedParameters": true,
|
||||
"noUnusedLocals": true,
|
||||
"noImplicitReturns": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"alwaysStrict": true,
|
||||
"strict": true,
|
||||
"target": "es5",
|
||||
"lib": ["es2015"]
|
||||
}
|
||||
}
|
||||
"#.to_string(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
fn ensure_test_entry(&mut self) {
|
||||
if !self
|
||||
.files
|
||||
.iter()
|
||||
.any(|(path, _)| path == "test.ts" || path == "test.js")
|
||||
{
|
||||
self.files.push((
|
||||
"test.js".to_string(),
|
||||
r#"export {test} from './out';"#.to_string(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_webidl_bindings(&mut self) -> Vec<PathBuf> {
|
||||
let mut res = Vec::new();
|
||||
let mut origpaths = Vec::new();
|
||||
|
||||
for (path, _) in &self.files {
|
||||
let path = Path::new(&path);
|
||||
let extension = path.extension().map(|x| x.to_str().unwrap());
|
||||
|
||||
if extension != Some("webidl") {
|
||||
continue;
|
||||
}
|
||||
|
||||
res.push(path.with_extension("rs"));
|
||||
origpaths.push(path.to_owned());
|
||||
}
|
||||
|
||||
if res.is_empty() {
|
||||
return res;
|
||||
}
|
||||
|
||||
let mut buildrs = r#"
|
||||
extern crate wasm_bindgen_webidl;
|
||||
|
||||
use wasm_bindgen_webidl::compile_file;
|
||||
use std::env;
|
||||
use std::fs::{self, File};
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
|
||||
fn main() {
|
||||
let dest = env::var("OUT_DIR").unwrap();
|
||||
"#.to_string();
|
||||
|
||||
for (path, origpath) in res.iter().zip(origpaths.iter()) {
|
||||
buildrs.push_str(&format!(
|
||||
r#"
|
||||
fs::create_dir_all("{}").unwrap();
|
||||
File::create(&Path::new(&dest).join("{}"))
|
||||
.unwrap()
|
||||
.write_all(
|
||||
compile_file(Path::new("{}"))
|
||||
.unwrap()
|
||||
.as_bytes()
|
||||
)
|
||||
.unwrap();
|
||||
"#,
|
||||
path.parent().unwrap().to_str().unwrap(),
|
||||
path.to_str().unwrap(),
|
||||
origpath.to_str().unwrap(),
|
||||
));
|
||||
|
||||
self.files.push((
|
||||
Path::new("src").join(path).to_str().unwrap().to_string(),
|
||||
format!(
|
||||
r#"include!(concat!(env!("OUT_DIR"), "/{}"));"#,
|
||||
path.display()
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
buildrs.push('}');
|
||||
|
||||
self.files.push(("build.rs".to_string(), buildrs));
|
||||
|
||||
res
|
||||
}
|
||||
|
||||
fn generate_js_entry(&mut self, modules: Vec<PathBuf>) {
|
||||
let mut runjs = String::new();
|
||||
let esm_imports = self.webpack || !self.node || self.nodejs_experimental_modules;
|
||||
|
||||
if esm_imports {
|
||||
runjs.push_str("import * as process from 'process';\n");
|
||||
} else {
|
||||
runjs.push_str("const process = require('process');\n");
|
||||
}
|
||||
|
||||
runjs.push_str("
|
||||
function run(test, wasm) {
|
||||
test.test();
|
||||
|
||||
if (wasm.assertStackEmpty)
|
||||
wasm.assertStackEmpty();
|
||||
if (wasm.assertSlabEmpty)
|
||||
wasm.assertSlabEmpty();
|
||||
}
|
||||
|
||||
function onerror(error) {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
}
|
||||
");
|
||||
|
||||
if esm_imports {
|
||||
runjs.push_str("const modules = [];\n");
|
||||
for module in modules.iter() {
|
||||
runjs.push_str(&format!("modules.push(import('./{}'))",
|
||||
module.with_extension("").display()));
|
||||
}
|
||||
let import_wasm = if self.debug {
|
||||
"import('./out')"
|
||||
} else {
|
||||
"new Promise((a, b) => a({}))"
|
||||
};
|
||||
runjs.push_str(&format!("
|
||||
Promise.all(modules)
|
||||
.then(results => {{
|
||||
results.map(module => Object.assign(global, module));
|
||||
return Promise.all([import('./test'), {}])
|
||||
}})
|
||||
.then(result => run(result[0], result[1]))
|
||||
.catch(onerror);
|
||||
", import_wasm));
|
||||
} else {
|
||||
assert!(!self.debug);
|
||||
assert!(modules.is_empty());
|
||||
runjs.push_str("
|
||||
const test = require('./test');
|
||||
try {
|
||||
run(test, {});
|
||||
} catch (e) {
|
||||
onerror(e);
|
||||
}
|
||||
");
|
||||
}
|
||||
self.files.push(("run.js".to_string(), runjs));
|
||||
}
|
||||
|
||||
/// Build the Cargo project for the wasm target, returning the root of the
|
||||
/// project and the target directory where output is located.
|
||||
pub fn cargo_build(&mut self) -> (PathBuf, PathBuf) {
|
||||
let (root, target_dir) = self.build();
|
||||
let mut cmd = Command::new("cargo");
|
||||
cmd.arg("build")
|
||||
.arg("--target")
|
||||
.arg("wasm32-unknown-unknown")
|
||||
.current_dir(&root)
|
||||
.env("CARGO_TARGET_DIR", &target_dir)
|
||||
// Catch any warnings in generated code because we don't want any
|
||||
.env("RUSTFLAGS", "-Dwarnings");
|
||||
run(&mut cmd, "cargo");
|
||||
(root, target_dir)
|
||||
}
|
||||
|
||||
/// Generate wasm-bindgen bindings for the compiled artifacts of this
|
||||
/// project, returning the root of the project as well as the target
|
||||
/// directory where output was generated.
|
||||
pub fn gen_bindings(&mut self) -> (PathBuf, PathBuf) {
|
||||
let (root, target_dir) = self.cargo_build();
|
||||
let idx = IDX.with(|x| *x);
|
||||
let out = target_dir.join(&format!("wasm32-unknown-unknown/debug/test{}.wasm", idx));
|
||||
|
||||
let as_a_module = root.join("out.wasm");
|
||||
fs::hard_link(&out, &as_a_module).unwrap();
|
||||
|
||||
let _x = wrap_step("running wasm-bindgen");
|
||||
let res = cli::Bindgen::new()
|
||||
.input_path(&as_a_module)
|
||||
.typescript(self.webpack)
|
||||
.debug(self.debug)
|
||||
.nodejs(self.node)
|
||||
.nodejs_experimental_modules(self.nodejs_experimental_modules)
|
||||
.generate(&root);
|
||||
|
||||
if let Err(e) = res {
|
||||
for e in e.causes() {
|
||||
println!("- {}", e);
|
||||
}
|
||||
panic!("failed");
|
||||
}
|
||||
|
||||
(root, target_dir)
|
||||
}
|
||||
|
||||
/// Execute this project's `run.js`, ensuring that everything runs through
|
||||
/// node or a browser correctly
|
||||
pub fn test(&mut self) {
|
||||
let (root, _target_dir) = self.gen_bindings();
|
||||
|
||||
if !self.webpack {
|
||||
let mut cmd = Command::new("node");
|
||||
cmd.args(&self.node_args);
|
||||
if self.nodejs_experimental_modules {
|
||||
cmd.arg("--experimental-modules").arg("run.mjs");
|
||||
} else {
|
||||
cmd.arg("run.js");
|
||||
}
|
||||
cmd.current_dir(&root);
|
||||
run(&mut cmd, "node");
|
||||
return
|
||||
}
|
||||
|
||||
// Generate typescript bindings for the wasm module
|
||||
{
|
||||
let _x = wrap_step("running wasm2es6js");
|
||||
let mut wasm = Vec::new();
|
||||
File::open(root.join("out_bg.wasm"))
|
||||
.unwrap()
|
||||
.read_to_end(&mut wasm)
|
||||
.unwrap();
|
||||
let obj = cli::wasm2es6js::Config::new()
|
||||
.base64(true)
|
||||
.generate(&wasm)
|
||||
.expect("failed to convert wasm to js");
|
||||
File::create(root.join("out_bg.d.ts"))
|
||||
.unwrap()
|
||||
.write_all(obj.typescript().as_bytes())
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
// move files from the root into each test, it looks like this may be
|
||||
// needed for webpack to work well when invoked concurrently.
|
||||
fs::hard_link("package.json", root.join("package.json")).unwrap();
|
||||
if !Path::new("node_modules").exists() {
|
||||
panic!("\n\nfailed to find `node_modules`, have you run `npm install` yet?\n\n");
|
||||
}
|
||||
let cwd = env::current_dir().unwrap();
|
||||
symlink_dir(&cwd.join("node_modules"), &root.join("node_modules")).unwrap();
|
||||
|
||||
// Execute webpack to generate a bundle
|
||||
let mut cmd = if cfg!(windows) {
|
||||
let mut c = Command::new("cmd");
|
||||
c.arg("/c");
|
||||
c.arg("npm");
|
||||
c
|
||||
} else {
|
||||
Command::new("npm")
|
||||
};
|
||||
cmd.arg("run").arg("run-webpack").current_dir(&root);
|
||||
run(&mut cmd, "npm");
|
||||
|
||||
let mut cmd = Command::new("node");
|
||||
cmd.args(&self.node_args);
|
||||
cmd.arg(root.join("bundle.js")).current_dir(&root);
|
||||
run(&mut cmd, "node");
|
||||
}
|
||||
|
||||
/// Reads JS generated by `wasm-bindgen` to a string.
|
||||
pub fn read_js(&self) -> String {
|
||||
let path = root().join(if self.nodejs_experimental_modules {
|
||||
"out.mjs"
|
||||
} else {
|
||||
"out.js"
|
||||
});
|
||||
println!("js, {:?}", &path);
|
||||
fs::read_to_string(path).expect("Unable to read js")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn symlink_dir(a: &Path, b: &Path) -> io::Result<()> {
|
||||
use std::os::unix::fs::symlink;
|
||||
symlink(a, b)
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn symlink_dir(a: &Path, b: &Path) -> io::Result<()> {
|
||||
use std::os::windows::fs::symlink_dir;
|
||||
symlink_dir(a, b)
|
||||
}
|
||||
|
||||
fn wrap_step(desc: &str) -> WrapStep {
|
||||
println!("···················································");
|
||||
println!("{}", desc);
|
||||
WrapStep { start: Instant::now() }
|
||||
}
|
||||
|
||||
struct WrapStep { start: Instant }
|
||||
|
||||
impl Drop for WrapStep {
|
||||
fn drop(&mut self) {
|
||||
let dur = self.start.elapsed();
|
||||
println!(
|
||||
"dur: {}.{:03}s",
|
||||
dur.as_secs(),
|
||||
dur.subsec_nanos() / 1_000_000
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run(cmd: &mut Command, program: &str) {
|
||||
let _x = wrap_step(&format!("running {:?}", cmd));
|
||||
let output = match cmd.output() {
|
||||
Ok(output) => output,
|
||||
Err(err) => panic!("failed to spawn `{}`: {}", program, err),
|
||||
};
|
||||
println!("exit: {}", output.status);
|
||||
if output.stdout.len() > 0 {
|
||||
println!("stdout ---\n{}", String::from_utf8_lossy(&output.stdout));
|
||||
}
|
||||
if output.stderr.len() > 0 {
|
||||
println!("stderr ---\n{}", String::from_utf8_lossy(&output.stderr));
|
||||
}
|
||||
assert!(output.status.success());
|
||||
}
|
||||
|
@ -6,55 +6,55 @@ fn add() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn add(a: u32, b: u32) -> u32 {
|
||||
a + b
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn add3(a: u32) -> u32 {
|
||||
a + 3
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get2(_b: bool) -> u32 {
|
||||
2
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn return_and_take_bool(a: bool, b: bool) -> bool {
|
||||
a && b
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn raw_pointers_work(a: *mut u32, b: *const u8) -> *const u32 {
|
||||
unsafe {
|
||||
(*a) = (*b) as u32;
|
||||
return a
|
||||
#[wasm_bindgen]
|
||||
pub fn add(a: u32, b: u32) -> u32 {
|
||||
a + b
|
||||
}
|
||||
}
|
||||
"#,
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn add3(a: u32) -> u32 {
|
||||
a + 3
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get2(_b: bool) -> u32 {
|
||||
2
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn return_and_take_bool(a: bool, b: bool) -> bool {
|
||||
a && b
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn raw_pointers_work(a: *mut u32, b: *const u8) -> *const u32 {
|
||||
unsafe {
|
||||
(*a) = (*b) as u32;
|
||||
return a
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
assert.strictEqual(wasm.add(1, 2), 3);
|
||||
assert.strictEqual(wasm.add(2, 3), 5);
|
||||
assert.strictEqual(wasm.add3(2), 5);
|
||||
assert.strictEqual(wasm.get2(true), 2);
|
||||
assert.strictEqual(wasm.return_and_take_bool(true, false), false);
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
assert.strictEqual(wasm.add(1, 2), 3);
|
||||
assert.strictEqual(wasm.add(2, 3), 5);
|
||||
assert.strictEqual(wasm.add3(2), 5);
|
||||
assert.strictEqual(wasm.get2(true), 2);
|
||||
assert.strictEqual(wasm.return_and_take_bool(true, false), false);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -65,34 +65,34 @@ fn string_arguments() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn assert_foo_and_bar(a: &str, b: &str) {
|
||||
assert_eq!(a, "foo2");
|
||||
assert_eq!(b, "bar");
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn assert_foo_and_bar(a: &str, b: &str) {
|
||||
assert_eq!(a, "foo2");
|
||||
assert_eq!(b, "bar");
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn assert_foo(a: &str) {
|
||||
assert_eq!(a, "foo");
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn assert_foo(a: &str) {
|
||||
assert_eq!(a, "foo");
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as wasm from "./out";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
wasm.assert_foo("foo");
|
||||
wasm.assert_foo_and_bar("foo2", "bar");
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
wasm.assert_foo("foo");
|
||||
wasm.assert_foo_and_bar("foo2", "bar");
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -103,36 +103,36 @@ fn return_a_string() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn clone(a: &str) -> String {
|
||||
a.to_string()
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn clone(a: &str) -> String {
|
||||
a.to_string()
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn concat(a: &str, b: &str, c: i8) -> String {
|
||||
format!("{} {} {}", a, b, c)
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn concat(a: &str, b: &str, c: i8) -> String {
|
||||
format!("{} {} {}", a, b, c)
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
assert.strictEqual(wasm.clone("foo"), "foo");
|
||||
assert.strictEqual(wasm.clone("another"), "another");
|
||||
assert.strictEqual(wasm.concat("a", "b", 3), "a b 3");
|
||||
assert.strictEqual(wasm.concat("c", "d", -2), "c d -2");
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
assert.strictEqual(wasm.clone("foo"), "foo");
|
||||
assert.strictEqual(wasm.clone("another"), "another");
|
||||
assert.strictEqual(wasm.concat("a", "b", 3), "a b 3");
|
||||
assert.strictEqual(wasm.concat("c", "d", -2), "c d -2");
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -143,36 +143,30 @@ fn exceptions() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn foo(_a: u32) {}
|
||||
#[wasm_bindgen]
|
||||
pub fn foo(_a: u32) {}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn bar(_a: &str) {}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn bar(_a: &str) {}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
assert.throws(() => wasm.foo('a'), /expected a number argument/);
|
||||
assert.throws(() => wasm.bar(3), /expected a string argument/);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.d.ts",
|
||||
r#"
|
||||
export function test(): void;
|
||||
"#,
|
||||
export function test() {
|
||||
assert.throws(() => wasm.foo('a'), /expected a number argument/);
|
||||
assert.throws(() => wasm.bar(3), /expected a string argument/);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -197,7 +191,7 @@ fn exceptions() {
|
||||
// }
|
||||
// }
|
||||
// "#)
|
||||
// .file("test.ts", r#"
|
||||
// .file("test.js", r#"
|
||||
// import * as assert from "assert";
|
||||
// import * as wasm from "./out";
|
||||
//
|
||||
@ -217,20 +211,20 @@ fn other_exports() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#[no_mangle]
|
||||
pub extern fn foo(_a: u32) {
|
||||
}
|
||||
"#,
|
||||
#[no_mangle]
|
||||
pub extern fn foo(_a: u32) {
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as wasm from "./out_bg";
|
||||
import * as wasm from "./out_bg";
|
||||
|
||||
export function test() {
|
||||
wasm.foo(2);
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
wasm.foo(2);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -242,49 +236,49 @@ fn no_std() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![no_std]
|
||||
#![allow(dead_code)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![no_std]
|
||||
#![allow(dead_code)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate std as _some_other_name;
|
||||
extern crate wasm_bindgen;
|
||||
extern crate std as _some_other_name;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen(module = "./foo")]
|
||||
extern {
|
||||
fn test(a: &str);
|
||||
#[wasm_bindgen(module = "./foo")]
|
||||
extern {
|
||||
fn test(a: &str);
|
||||
|
||||
type Js;
|
||||
#[wasm_bindgen(constructor)]
|
||||
fn new() -> Js;
|
||||
#[wasm_bindgen(method)]
|
||||
fn init(this: &Js);
|
||||
}
|
||||
type Js;
|
||||
#[wasm_bindgen(constructor)]
|
||||
fn new() -> Js;
|
||||
#[wasm_bindgen(method)]
|
||||
fn init(this: &Js);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn foo(_a: u32) {}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn foo(_a: u32) {}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as wasm from "./out_bg";
|
||||
import * as wasm from "./out_bg";
|
||||
|
||||
export function test() {
|
||||
// mostly just testing the project compiles here
|
||||
wasm.foo(1);
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
// mostly just testing the project compiles here
|
||||
wasm.foo(1);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"foo.js",
|
||||
r#"
|
||||
export class Js {
|
||||
init() {
|
||||
export class Js {
|
||||
init() {
|
||||
}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -295,49 +289,49 @@ fn no_std_class() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![no_std]
|
||||
#![allow(dead_code)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![no_std]
|
||||
#![allow(dead_code)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate std as _some_other_name;
|
||||
extern crate wasm_bindgen;
|
||||
extern crate std as _some_other_name;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
fn test(a: &str);
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
fn test(a: &str);
|
||||
|
||||
type Js;
|
||||
#[wasm_bindgen(constructor)]
|
||||
fn new() -> Js;
|
||||
#[wasm_bindgen(method, structural)]
|
||||
fn init(this: &Js);
|
||||
}
|
||||
type Js;
|
||||
#[wasm_bindgen(constructor)]
|
||||
fn new() -> Js;
|
||||
#[wasm_bindgen(method, structural)]
|
||||
fn init(this: &Js);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn foo(_a: u32) {}
|
||||
#[wasm_bindgen]
|
||||
pub fn foo(_a: u32) {}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub struct A {}
|
||||
#[wasm_bindgen]
|
||||
pub struct A {}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl A {
|
||||
pub fn foo(&self) {}
|
||||
pub fn bar(&mut self) {}
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
impl A {
|
||||
pub fn foo(&self) {}
|
||||
pub fn bar(&mut self) {}
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as wasm from "./out_bg";
|
||||
import * as wasm from "./out_bg";
|
||||
|
||||
export function test() {
|
||||
// mostly just testing the project compiles here
|
||||
wasm.foo(1);
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
// mostly just testing the project compiles here
|
||||
wasm.foo(1);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
@ -6,82 +6,82 @@ fn export() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
macro_rules! doit {
|
||||
($($i:ident)*) => ($(
|
||||
#[wasm_bindgen]
|
||||
pub fn $i(a: &[$i]) -> Vec<$i> {
|
||||
assert_eq!(a.len(), 2);
|
||||
assert_eq!(a[0], 1 as $i);
|
||||
assert_eq!(a[1], 2 as $i);
|
||||
a.to_vec()
|
||||
}
|
||||
)*)
|
||||
}
|
||||
macro_rules! doit {
|
||||
($($i:ident)*) => ($(
|
||||
#[wasm_bindgen]
|
||||
pub fn $i(a: &[$i]) -> Vec<$i> {
|
||||
assert_eq!(a.len(), 2);
|
||||
assert_eq!(a[0], 1 as $i);
|
||||
assert_eq!(a[1], 2 as $i);
|
||||
a.to_vec()
|
||||
}
|
||||
)*)
|
||||
}
|
||||
|
||||
|
||||
doit! { i8 u8 i16 u16 i32 u32 f32 f64 }
|
||||
"#,
|
||||
doit! { i8 u8 i16 u16 i32 u32 f32 f64 }
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
function assert_arrays_equal(a: any, b: any) {
|
||||
console.log(a, b);
|
||||
assert.strictEqual(a.length, b.length);
|
||||
assert.strictEqual(a.byteLength, b.byteLength);
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
assert.strictEqual(a[i], b[i]);
|
||||
function assert_arrays_equal(a, b) {
|
||||
console.log(a, b);
|
||||
assert.strictEqual(a.length, b.length);
|
||||
assert.strictEqual(a.byteLength, b.byteLength);
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
assert.strictEqual(a[i], b[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function test() {
|
||||
const i8 = new Int8Array(2);
|
||||
i8[0] = 1;
|
||||
i8[1] = 2;
|
||||
assert_arrays_equal(wasm.i8(i8), i8);
|
||||
const u8 = new Uint8Array(2);
|
||||
u8[0] = 1;
|
||||
u8[1] = 2;
|
||||
assert_arrays_equal(wasm.u8(u8), u8);
|
||||
export function test() {
|
||||
const i8 = new Int8Array(2);
|
||||
i8[0] = 1;
|
||||
i8[1] = 2;
|
||||
assert_arrays_equal(wasm.i8(i8), i8);
|
||||
const u8 = new Uint8Array(2);
|
||||
u8[0] = 1;
|
||||
u8[1] = 2;
|
||||
assert_arrays_equal(wasm.u8(u8), u8);
|
||||
|
||||
const i16 = new Int16Array(2);
|
||||
i16[0] = 1;
|
||||
i16[1] = 2;
|
||||
assert_arrays_equal(wasm.i16(i16), i16);
|
||||
const u16 = new Uint16Array(2);
|
||||
u16[0] = 1;
|
||||
u16[1] = 2;
|
||||
assert_arrays_equal(wasm.u16(u16), u16);
|
||||
const i16 = new Int16Array(2);
|
||||
i16[0] = 1;
|
||||
i16[1] = 2;
|
||||
assert_arrays_equal(wasm.i16(i16), i16);
|
||||
const u16 = new Uint16Array(2);
|
||||
u16[0] = 1;
|
||||
u16[1] = 2;
|
||||
assert_arrays_equal(wasm.u16(u16), u16);
|
||||
|
||||
const i32 = new Int32Array(2);
|
||||
i32[0] = 1;
|
||||
i32[1] = 2;
|
||||
wasm.i32(i32);
|
||||
assert_arrays_equal(wasm.i32(i32), i32);
|
||||
const u32 = new Uint32Array(2);
|
||||
u32[0] = 1;
|
||||
u32[1] = 2;
|
||||
assert_arrays_equal(wasm.u32(u32), u32);
|
||||
const i32 = new Int32Array(2);
|
||||
i32[0] = 1;
|
||||
i32[1] = 2;
|
||||
wasm.i32(i32);
|
||||
assert_arrays_equal(wasm.i32(i32), i32);
|
||||
const u32 = new Uint32Array(2);
|
||||
u32[0] = 1;
|
||||
u32[1] = 2;
|
||||
assert_arrays_equal(wasm.u32(u32), u32);
|
||||
|
||||
const f32 = new Float32Array(2);
|
||||
f32[0] = 1;
|
||||
f32[1] = 2;
|
||||
assert_arrays_equal(wasm.f32(f32), f32);
|
||||
const f64 = new Float64Array(2);
|
||||
f64[0] = 1;
|
||||
f64[1] = 2;
|
||||
assert_arrays_equal(wasm.f64(f64), f64);
|
||||
}
|
||||
"#,
|
||||
const f32 = new Float32Array(2);
|
||||
f32[0] = 1;
|
||||
f32[1] = 2;
|
||||
assert_arrays_equal(wasm.f32(f32), f32);
|
||||
const f64 = new Float64Array(2);
|
||||
f64[0] = 1;
|
||||
f64[1] = 2;
|
||||
assert_arrays_equal(wasm.f64(f64), f64);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -92,151 +92,151 @@ fn import() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
macro_rules! doit {
|
||||
($(($rust:ident, $js:ident, $i:ident))*) => ($(
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn $js(a: &[$i]) -> Vec<$i>;
|
||||
}
|
||||
macro_rules! doit {
|
||||
($(($rust:ident, $js:ident, $i:ident))*) => ($(
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn $js(a: &[$i]) -> Vec<$i>;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn $rust(a: &[$i]) -> Vec<$i> {
|
||||
assert_eq!(a.len(), 2);
|
||||
assert_eq!(a[0], 1 as $i);
|
||||
assert_eq!(a[1], 2 as $i);
|
||||
$js(a)
|
||||
}
|
||||
)*)
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn $rust(a: &[$i]) -> Vec<$i> {
|
||||
assert_eq!(a.len(), 2);
|
||||
assert_eq!(a[0], 1 as $i);
|
||||
assert_eq!(a[1], 2 as $i);
|
||||
$js(a)
|
||||
}
|
||||
)*)
|
||||
}
|
||||
|
||||
|
||||
doit! {
|
||||
(rust_i8, js_i8, i8)
|
||||
(rust_u8, js_u8, u8)
|
||||
(rust_i16, js_i16, i16)
|
||||
(rust_u16, js_u16, u16)
|
||||
(rust_i32, js_i32, i32)
|
||||
(rust_u32, js_u32, u32)
|
||||
(rust_f32, js_f32, f32)
|
||||
(rust_f64, js_f64, f64)
|
||||
}
|
||||
"#,
|
||||
doit! {
|
||||
(rust_i8, js_i8, i8)
|
||||
(rust_u8, js_u8, u8)
|
||||
(rust_i16, js_i16, i16)
|
||||
(rust_u16, js_u16, u16)
|
||||
(rust_i32, js_i32, i32)
|
||||
(rust_u32, js_u32, u32)
|
||||
(rust_f32, js_f32, f32)
|
||||
(rust_f64, js_f64, f64)
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function js_i8(a: any): any {
|
||||
assert.strictEqual(a.length, 2);
|
||||
assert.strictEqual(a[0], 1);
|
||||
assert.strictEqual(a[1], 2);
|
||||
return a;
|
||||
}
|
||||
|
||||
export function js_u8(a: any): any {
|
||||
assert.strictEqual(a.length, 2);
|
||||
assert.strictEqual(a[0], 1);
|
||||
assert.strictEqual(a[1], 2);
|
||||
return a;
|
||||
}
|
||||
|
||||
export function js_i16(a: any): any {
|
||||
assert.strictEqual(a.length, 2);
|
||||
assert.strictEqual(a[0], 1);
|
||||
assert.strictEqual(a[1], 2);
|
||||
return a;
|
||||
}
|
||||
|
||||
export function js_u16(a: any): any {
|
||||
assert.strictEqual(a.length, 2);
|
||||
assert.strictEqual(a[0], 1);
|
||||
assert.strictEqual(a[1], 2);
|
||||
return a;
|
||||
}
|
||||
|
||||
export function js_i32(a: any): any {
|
||||
assert.strictEqual(a.length, 2);
|
||||
assert.strictEqual(a[0], 1);
|
||||
assert.strictEqual(a[1], 2);
|
||||
return a;
|
||||
}
|
||||
|
||||
export function js_u32(a: any): any {
|
||||
assert.strictEqual(a.length, 2);
|
||||
assert.strictEqual(a[0], 1);
|
||||
assert.strictEqual(a[1], 2);
|
||||
return a;
|
||||
}
|
||||
|
||||
export function js_f32(a: any): any {
|
||||
assert.strictEqual(a.length, 2);
|
||||
assert.strictEqual(a[0], 1);
|
||||
assert.strictEqual(a[1], 2);
|
||||
return a;
|
||||
}
|
||||
|
||||
export function js_f64(a: any): any {
|
||||
assert.strictEqual(a.length, 2);
|
||||
assert.strictEqual(a[0], 1);
|
||||
assert.strictEqual(a[1], 2);
|
||||
return a;
|
||||
}
|
||||
|
||||
function assert_arrays_equal(a: any, b: any) {
|
||||
console.log(a, b);
|
||||
assert.strictEqual(a.length, b.length);
|
||||
assert.strictEqual(a.byteLength, b.byteLength);
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
assert.strictEqual(a[i], b[i]);
|
||||
export function js_i8(a) {
|
||||
assert.strictEqual(a.length, 2);
|
||||
assert.strictEqual(a[0], 1);
|
||||
assert.strictEqual(a[1], 2);
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
export function test() {
|
||||
const i8 = new Int8Array(2);
|
||||
i8[0] = 1;
|
||||
i8[1] = 2;
|
||||
assert_arrays_equal(wasm.rust_i8(i8), i8);
|
||||
const u8 = new Uint8Array(2);
|
||||
u8[0] = 1;
|
||||
u8[1] = 2;
|
||||
assert_arrays_equal(wasm.rust_u8(u8), u8);
|
||||
export function js_u8(a) {
|
||||
assert.strictEqual(a.length, 2);
|
||||
assert.strictEqual(a[0], 1);
|
||||
assert.strictEqual(a[1], 2);
|
||||
return a;
|
||||
}
|
||||
|
||||
const i16 = new Int16Array(2);
|
||||
i16[0] = 1;
|
||||
i16[1] = 2;
|
||||
assert_arrays_equal(wasm.rust_i16(i16), i16);
|
||||
const u16 = new Uint16Array(2);
|
||||
u16[0] = 1;
|
||||
u16[1] = 2;
|
||||
assert_arrays_equal(wasm.rust_u16(u16), u16);
|
||||
export function js_i16(a) {
|
||||
assert.strictEqual(a.length, 2);
|
||||
assert.strictEqual(a[0], 1);
|
||||
assert.strictEqual(a[1], 2);
|
||||
return a;
|
||||
}
|
||||
|
||||
const i32 = new Int32Array(2);
|
||||
i32[0] = 1;
|
||||
i32[1] = 2;
|
||||
assert_arrays_equal(wasm.rust_i32(i32), i32);
|
||||
const u32 = new Uint32Array(2);
|
||||
u32[0] = 1;
|
||||
u32[1] = 2;
|
||||
assert_arrays_equal(wasm.rust_u32(u32), u32);
|
||||
export function js_u16(a) {
|
||||
assert.strictEqual(a.length, 2);
|
||||
assert.strictEqual(a[0], 1);
|
||||
assert.strictEqual(a[1], 2);
|
||||
return a;
|
||||
}
|
||||
|
||||
const f32 = new Float32Array(2);
|
||||
f32[0] = 1;
|
||||
f32[1] = 2;
|
||||
assert_arrays_equal(wasm.rust_f32(f32), f32);
|
||||
const f64 = new Float64Array(2);
|
||||
f64[0] = 1;
|
||||
f64[1] = 2;
|
||||
assert_arrays_equal(wasm.rust_f64(f64), f64);
|
||||
}
|
||||
"#,
|
||||
export function js_i32(a) {
|
||||
assert.strictEqual(a.length, 2);
|
||||
assert.strictEqual(a[0], 1);
|
||||
assert.strictEqual(a[1], 2);
|
||||
return a;
|
||||
}
|
||||
|
||||
export function js_u32(a) {
|
||||
assert.strictEqual(a.length, 2);
|
||||
assert.strictEqual(a[0], 1);
|
||||
assert.strictEqual(a[1], 2);
|
||||
return a;
|
||||
}
|
||||
|
||||
export function js_f32(a) {
|
||||
assert.strictEqual(a.length, 2);
|
||||
assert.strictEqual(a[0], 1);
|
||||
assert.strictEqual(a[1], 2);
|
||||
return a;
|
||||
}
|
||||
|
||||
export function js_f64(a) {
|
||||
assert.strictEqual(a.length, 2);
|
||||
assert.strictEqual(a[0], 1);
|
||||
assert.strictEqual(a[1], 2);
|
||||
return a;
|
||||
}
|
||||
|
||||
function assert_arrays_equal(a, b) {
|
||||
console.log(a, b);
|
||||
assert.strictEqual(a.length, b.length);
|
||||
assert.strictEqual(a.byteLength, b.byteLength);
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
assert.strictEqual(a[i], b[i]);
|
||||
}
|
||||
}
|
||||
|
||||
export function test() {
|
||||
const i8 = new Int8Array(2);
|
||||
i8[0] = 1;
|
||||
i8[1] = 2;
|
||||
assert_arrays_equal(wasm.rust_i8(i8), i8);
|
||||
const u8 = new Uint8Array(2);
|
||||
u8[0] = 1;
|
||||
u8[1] = 2;
|
||||
assert_arrays_equal(wasm.rust_u8(u8), u8);
|
||||
|
||||
const i16 = new Int16Array(2);
|
||||
i16[0] = 1;
|
||||
i16[1] = 2;
|
||||
assert_arrays_equal(wasm.rust_i16(i16), i16);
|
||||
const u16 = new Uint16Array(2);
|
||||
u16[0] = 1;
|
||||
u16[1] = 2;
|
||||
assert_arrays_equal(wasm.rust_u16(u16), u16);
|
||||
|
||||
const i32 = new Int32Array(2);
|
||||
i32[0] = 1;
|
||||
i32[1] = 2;
|
||||
assert_arrays_equal(wasm.rust_i32(i32), i32);
|
||||
const u32 = new Uint32Array(2);
|
||||
u32[0] = 1;
|
||||
u32[1] = 2;
|
||||
assert_arrays_equal(wasm.rust_u32(u32), u32);
|
||||
|
||||
const f32 = new Float32Array(2);
|
||||
f32[0] = 1;
|
||||
f32[1] = 2;
|
||||
assert_arrays_equal(wasm.rust_f32(f32), f32);
|
||||
const f64 = new Float64Array(2);
|
||||
f64[0] = 1;
|
||||
f64[1] = 2;
|
||||
assert_arrays_equal(wasm.rust_f64(f64), f64);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -247,52 +247,52 @@ fn pass_array_works() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
macro_rules! doit {
|
||||
($(($rust:ident, $i:ident))*) => ($(
|
||||
#[wasm_bindgen]
|
||||
pub fn $rust(a: &[$i]) {
|
||||
assert_eq!(a.len(), 2);
|
||||
assert_eq!(a[0], 1 as $i);
|
||||
assert_eq!(a[1], 2 as $i);
|
||||
}
|
||||
)*)
|
||||
}
|
||||
macro_rules! doit {
|
||||
($(($rust:ident, $i:ident))*) => ($(
|
||||
#[wasm_bindgen]
|
||||
pub fn $rust(a: &[$i]) {
|
||||
assert_eq!(a.len(), 2);
|
||||
assert_eq!(a[0], 1 as $i);
|
||||
assert_eq!(a[1], 2 as $i);
|
||||
}
|
||||
)*)
|
||||
}
|
||||
|
||||
|
||||
doit! {
|
||||
(rust_i8, i8)
|
||||
(rust_u8, u8)
|
||||
(rust_i16, i16)
|
||||
(rust_u16, u16)
|
||||
(rust_i32, i32)
|
||||
(rust_u32, u32)
|
||||
(rust_f32, f32)
|
||||
(rust_f64, f64)
|
||||
}
|
||||
"#,
|
||||
doit! {
|
||||
(rust_i8, i8)
|
||||
(rust_u8, u8)
|
||||
(rust_i16, i16)
|
||||
(rust_u16, u16)
|
||||
(rust_i32, i32)
|
||||
(rust_u32, u32)
|
||||
(rust_f32, f32)
|
||||
(rust_f64, f64)
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.js",
|
||||
r#"
|
||||
const wasm = require("./out");
|
||||
import * as wasm from "./out";
|
||||
|
||||
module.exports.test = function() {
|
||||
wasm.rust_i8([1, 2]);
|
||||
wasm.rust_u8([1, 2]);
|
||||
wasm.rust_i16([1, 2]);
|
||||
wasm.rust_u16([1, 2]);
|
||||
wasm.rust_i32([1, 2]);
|
||||
wasm.rust_u32([1, 2]);
|
||||
wasm.rust_f32([1, 2]);
|
||||
wasm.rust_f64([1, 2]);
|
||||
};
|
||||
"#,
|
||||
export function test() {
|
||||
wasm.rust_i8([1, 2]);
|
||||
wasm.rust_u8([1, 2]);
|
||||
wasm.rust_i16([1, 2]);
|
||||
wasm.rust_u16([1, 2]);
|
||||
wasm.rust_i32([1, 2]);
|
||||
wasm.rust_u32([1, 2]);
|
||||
wasm.rust_f32([1, 2]);
|
||||
wasm.rust_f64([1, 2]);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -303,80 +303,80 @@ fn import_mut() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
macro_rules! doit {
|
||||
($(($rust:ident, $js:ident, $i:ident))*) => (
|
||||
$(
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn $js(a: &mut [$i]);
|
||||
macro_rules! doit {
|
||||
($(($rust:ident, $js:ident, $i:ident))*) => (
|
||||
$(
|
||||
#[wasm_bindgen(module = "./test")]
|
||||
extern {
|
||||
fn $js(a: &mut [$i]);
|
||||
}
|
||||
|
||||
fn $rust() {
|
||||
let mut buf = [
|
||||
1 as $i,
|
||||
2 as $i,
|
||||
3 as $i,
|
||||
];
|
||||
$js(&mut buf);
|
||||
assert_eq!(buf[0], 4 as $i);
|
||||
assert_eq!(buf[1], 5 as $i);
|
||||
assert_eq!(buf[2], 3 as $i);
|
||||
}
|
||||
)*
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
$($rust();)*
|
||||
}
|
||||
|
||||
fn $rust() {
|
||||
let mut buf = [
|
||||
1 as $i,
|
||||
2 as $i,
|
||||
3 as $i,
|
||||
];
|
||||
$js(&mut buf);
|
||||
assert_eq!(buf[0], 4 as $i);
|
||||
assert_eq!(buf[1], 5 as $i);
|
||||
assert_eq!(buf[2], 3 as $i);
|
||||
}
|
||||
)*
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
$($rust();)*
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
doit! {
|
||||
(rust_i8, js_i8, i8)
|
||||
(rust_u8, js_u8, u8)
|
||||
(rust_i16, js_i16, i16)
|
||||
(rust_u16, js_u16, u16)
|
||||
(rust_i32, js_i32, i32)
|
||||
(rust_u32, js_u32, u32)
|
||||
(rust_f32, js_f32, f32)
|
||||
(rust_f64, js_f64, f64)
|
||||
}
|
||||
"#,
|
||||
doit! {
|
||||
(rust_i8, js_i8, i8)
|
||||
(rust_u8, js_u8, u8)
|
||||
(rust_i16, js_i16, i16)
|
||||
(rust_u16, js_u16, u16)
|
||||
(rust_i32, js_i32, i32)
|
||||
(rust_u32, js_u32, u32)
|
||||
(rust_f32, js_f32, f32)
|
||||
(rust_f64, js_f64, f64)
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
function foo(a: any) {
|
||||
assert.strictEqual(a.length, 3);
|
||||
assert.strictEqual(a[0], 1);
|
||||
assert.strictEqual(a[1], 2);
|
||||
a[0] = 4;
|
||||
a[1] = 5;
|
||||
}
|
||||
function foo(a) {
|
||||
assert.strictEqual(a.length, 3);
|
||||
assert.strictEqual(a[0], 1);
|
||||
assert.strictEqual(a[1], 2);
|
||||
a[0] = 4;
|
||||
a[1] = 5;
|
||||
}
|
||||
|
||||
export const js_i8 = foo;
|
||||
export const js_u8 = foo;
|
||||
export const js_i16 = foo;
|
||||
export const js_u16 = foo;
|
||||
export const js_i32 = foo;
|
||||
export const js_u32 = foo;
|
||||
export const js_f32 = foo;
|
||||
export const js_f64 = foo;
|
||||
export const js_i8 = foo;
|
||||
export const js_u8 = foo;
|
||||
export const js_i16 = foo;
|
||||
export const js_u16 = foo;
|
||||
export const js_i32 = foo;
|
||||
export const js_u32 = foo;
|
||||
export const js_f32 = foo;
|
||||
export const js_f64 = foo;
|
||||
|
||||
export function test() {
|
||||
wasm.run();
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
wasm.run();
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -387,61 +387,61 @@ fn export_mut() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
macro_rules! doit {
|
||||
($($i:ident)*) => ($(
|
||||
#[wasm_bindgen]
|
||||
pub fn $i(a: &mut [$i]) {
|
||||
assert_eq!(a.len(), 3);
|
||||
assert_eq!(a[0], 1 as $i);
|
||||
assert_eq!(a[1], 2 as $i);
|
||||
assert_eq!(a[2], 3 as $i);
|
||||
a[0] = 4 as $i;
|
||||
a[1] = 5 as $i;
|
||||
}
|
||||
)*)
|
||||
}
|
||||
macro_rules! doit {
|
||||
($($i:ident)*) => ($(
|
||||
#[wasm_bindgen]
|
||||
pub fn $i(a: &mut [$i]) {
|
||||
assert_eq!(a.len(), 3);
|
||||
assert_eq!(a[0], 1 as $i);
|
||||
assert_eq!(a[1], 2 as $i);
|
||||
assert_eq!(a[2], 3 as $i);
|
||||
a[0] = 4 as $i;
|
||||
a[1] = 5 as $i;
|
||||
}
|
||||
)*)
|
||||
}
|
||||
|
||||
|
||||
doit! { i8 u8 i16 u16 i32 u32 f32 f64 }
|
||||
"#,
|
||||
doit! { i8 u8 i16 u16 i32 u32 f32 f64 }
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
function run(a: any, rust: any) {
|
||||
assert.strictEqual(a.length, 3);
|
||||
a[0] = 1;
|
||||
a[1] = 2;
|
||||
a[2] = 3;
|
||||
console.log(a);
|
||||
rust(a);
|
||||
console.log(a);
|
||||
assert.strictEqual(a.length, 3);
|
||||
assert.strictEqual(a[0], 4);
|
||||
assert.strictEqual(a[1], 5);
|
||||
assert.strictEqual(a[2], 3);
|
||||
}
|
||||
function run(a, rust) {
|
||||
assert.strictEqual(a.length, 3);
|
||||
a[0] = 1;
|
||||
a[1] = 2;
|
||||
a[2] = 3;
|
||||
console.log(a);
|
||||
rust(a);
|
||||
console.log(a);
|
||||
assert.strictEqual(a.length, 3);
|
||||
assert.strictEqual(a[0], 4);
|
||||
assert.strictEqual(a[1], 5);
|
||||
assert.strictEqual(a[2], 3);
|
||||
}
|
||||
|
||||
export function test() {
|
||||
run(new Int8Array(3), wasm.i8);
|
||||
run(new Uint8Array(3), wasm.u8);
|
||||
run(new Int16Array(3), wasm.i16);
|
||||
run(new Uint16Array(3), wasm.u16);
|
||||
run(new Int32Array(3), wasm.i32);
|
||||
run(new Uint32Array(3), wasm.u32);
|
||||
run(new Float32Array(3), wasm.f32);
|
||||
run(new Float64Array(3), wasm.f64);
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
run(new Int8Array(3), wasm.i8);
|
||||
run(new Uint8Array(3), wasm.u8);
|
||||
run(new Int16Array(3), wasm.i16);
|
||||
run(new Uint16Array(3), wasm.u16);
|
||||
run(new Int32Array(3), wasm.i32);
|
||||
run(new Uint32Array(3), wasm.u32);
|
||||
run(new Float32Array(3), wasm.f32);
|
||||
run(new Float64Array(3), wasm.f64);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -452,75 +452,75 @@ fn return_vec_ok() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
extern crate wasm_bindgen;
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn broken_vec() -> Vec<u32> {
|
||||
vec![1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn broken_vec() -> Vec<u32> {
|
||||
vec![1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn web_main() -> Application {
|
||||
Application::new()
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub fn web_main() -> Application {
|
||||
Application::new()
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub struct Application {
|
||||
thing: Vec<u32>,
|
||||
}
|
||||
#[wasm_bindgen]
|
||||
pub struct Application {
|
||||
thing: Vec<u32>,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl Application {
|
||||
pub fn new() -> Application {
|
||||
let mut thing = vec![];
|
||||
thing.push(0);
|
||||
thing.push(0);
|
||||
thing.push(0);
|
||||
thing.push(0);
|
||||
thing.push(0);
|
||||
#[wasm_bindgen]
|
||||
impl Application {
|
||||
pub fn new() -> Application {
|
||||
let mut thing = vec![];
|
||||
thing.push(0);
|
||||
thing.push(0);
|
||||
thing.push(0);
|
||||
thing.push(0);
|
||||
thing.push(0);
|
||||
|
||||
Application {
|
||||
thing: thing
|
||||
Application {
|
||||
thing: thing
|
||||
}
|
||||
}
|
||||
pub fn tick(&mut self) {
|
||||
self.thing = self.thing.clone();
|
||||
}
|
||||
}
|
||||
pub fn tick(&mut self) {
|
||||
self.thing = self.thing.clone();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
}
|
||||
"#,
|
||||
pub fn main() {
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
|
||||
export function test() {
|
||||
let app = wasm.web_main();
|
||||
export function test() {
|
||||
let app = wasm.web_main();
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
app.tick();
|
||||
let bad = wasm.broken_vec();
|
||||
console.log("Received from rust:", i, bad);
|
||||
assert.strictEqual(bad[0], 1);
|
||||
assert.strictEqual(bad[1], 2);
|
||||
assert.strictEqual(bad[2], 3);
|
||||
assert.strictEqual(bad[3], 4);
|
||||
assert.strictEqual(bad[4], 5);
|
||||
assert.strictEqual(bad[5], 6);
|
||||
assert.strictEqual(bad[6], 7);
|
||||
assert.strictEqual(bad[7], 8);
|
||||
assert.strictEqual(bad[8], 9);
|
||||
for (let i = 0; i < 10; i++) {
|
||||
app.tick();
|
||||
let bad = wasm.broken_vec();
|
||||
console.log("Received from rust:", i, bad);
|
||||
assert.strictEqual(bad[0], 1);
|
||||
assert.strictEqual(bad[1], 2);
|
||||
assert.strictEqual(bad[2], 3);
|
||||
assert.strictEqual(bad[3], 4);
|
||||
assert.strictEqual(bad[4], 5);
|
||||
assert.strictEqual(bad[5], 6);
|
||||
assert.strictEqual(bad[6], 7);
|
||||
assert.strictEqual(bad[7], 8);
|
||||
assert.strictEqual(bad[8], 9);
|
||||
}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
@ -6,47 +6,47 @@ fn works() {
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
extern crate wasm_bindgen;
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
pub type Foo;
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
pub type Foo;
|
||||
|
||||
#[wasm_bindgen(method, structural)]
|
||||
fn bar(this: &Foo);
|
||||
#[wasm_bindgen(method, getter, structural)]
|
||||
fn baz(this: &Foo) -> u32;
|
||||
#[wasm_bindgen(method, setter, structural)]
|
||||
fn set_baz(this: &Foo, val: u32);
|
||||
}
|
||||
#[wasm_bindgen(method, structural)]
|
||||
fn bar(this: &Foo);
|
||||
#[wasm_bindgen(method, getter, structural)]
|
||||
fn baz(this: &Foo) -> u32;
|
||||
#[wasm_bindgen(method, setter, structural)]
|
||||
fn set_baz(this: &Foo, val: u32);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run(a: &Foo) {
|
||||
a.bar();
|
||||
assert_eq!(a.baz(), 1);
|
||||
a.set_baz(2);
|
||||
assert_eq!(a.baz(), 2);
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn run(a: &Foo) {
|
||||
a.bar();
|
||||
assert_eq!(a.baz(), 1);
|
||||
a.set_baz(2);
|
||||
assert_eq!(a.baz(), 2);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import { run } from "./out";
|
||||
import * as assert from "assert";
|
||||
import { run } from "./out";
|
||||
|
||||
export function test() {
|
||||
let called = false;
|
||||
run({
|
||||
bar() { called = true; },
|
||||
baz: 1,
|
||||
});
|
||||
assert.strictEqual(called, true);
|
||||
}
|
||||
"#,
|
||||
export function test() {
|
||||
let called = false;
|
||||
run({
|
||||
bar() { called = true; },
|
||||
baz: 1,
|
||||
});
|
||||
assert.strictEqual(called, true);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
79
tests/all/typescript.rs
Normal file
79
tests/all/typescript.rs
Normal file
@ -0,0 +1,79 @@
|
||||
use super::project;
|
||||
|
||||
#[test]
|
||||
fn works() {
|
||||
project()
|
||||
.webpack(true)
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn foo() {}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn bar(a: &str, b: u32) -> String {
|
||||
format!("{} {}", a, b)
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn thunk(a: &JsValue) {
|
||||
drop(a);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub struct A {
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl A {
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new() -> A {
|
||||
A {}
|
||||
}
|
||||
|
||||
pub fn new2() -> A {
|
||||
A {}
|
||||
}
|
||||
|
||||
pub fn foo(&self) {}
|
||||
|
||||
pub fn bar(&self, _a: u32) {}
|
||||
|
||||
pub fn baz(&self, _d: &A) {}
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
r#"
|
||||
import * as assert from 'assert';
|
||||
import { foo, bar, A, thunk } from './out';
|
||||
import { memory } from './out_bg';
|
||||
|
||||
export function test() {
|
||||
foo();
|
||||
assert.strictEqual(bar('a', 3), 'a 3');
|
||||
|
||||
const x = new A();
|
||||
x.foo();
|
||||
x.free();
|
||||
|
||||
const y = A.new2();
|
||||
y.foo();
|
||||
y.bar(2);
|
||||
y.baz(y);
|
||||
y.free();
|
||||
|
||||
thunk(memory);
|
||||
};
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
@ -6,55 +6,55 @@ fn method() {
|
||||
.file(
|
||||
"foo.webidl",
|
||||
r#"
|
||||
[Constructor(double value)]
|
||||
interface Foo {
|
||||
[Pure]
|
||||
boolean myCmp(Foo bar);
|
||||
};
|
||||
"#,
|
||||
[Constructor(double value)]
|
||||
interface Foo {
|
||||
[Pure]
|
||||
boolean myCmp(Foo bar);
|
||||
};
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"foo.ts",
|
||||
"foo.js",
|
||||
r#"
|
||||
export class Foo {
|
||||
constructor(private value: number) {
|
||||
this.value = value;
|
||||
export class Foo {
|
||||
constructor(value) {
|
||||
this.value = value;
|
||||
}
|
||||
myCmp(other) {
|
||||
return this.value === other.value;
|
||||
}
|
||||
}
|
||||
myCmp(other: Foo): boolean {
|
||||
return this.value === other.value;
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
pub mod foo;
|
||||
pub mod foo;
|
||||
|
||||
use foo::Foo;
|
||||
use foo::Foo;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
let pi = Foo::new(3.14159);
|
||||
let e = Foo::new(2.71828);
|
||||
// TODO: figure out why the following doesn't fail
|
||||
// assert!(!pi.my_cmp(Foo::new(3.14159)));
|
||||
let tmp = pi.my_cmp(Foo::new(3.14159));
|
||||
assert!(tmp);
|
||||
let tmp =!pi.my_cmp(Foo::new(2.71828));
|
||||
assert!(tmp);
|
||||
let tmp = !e.my_cmp(Foo::new(3.14159));
|
||||
assert!(tmp);
|
||||
let tmp = e.my_cmp(Foo::new(2.71828));
|
||||
assert!(tmp);
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
let pi = Foo::new(3.14159);
|
||||
let e = Foo::new(2.71828);
|
||||
// TODO: figure out why the following doesn't fail
|
||||
// assert!(!pi.my_cmp(Foo::new(3.14159)));
|
||||
let tmp = pi.my_cmp(Foo::new(3.14159));
|
||||
assert!(tmp);
|
||||
let tmp =!pi.my_cmp(Foo::new(2.71828));
|
||||
assert!(tmp);
|
||||
let tmp = !e.my_cmp(Foo::new(3.14159));
|
||||
assert!(tmp);
|
||||
let tmp = e.my_cmp(Foo::new(2.71828));
|
||||
assert!(tmp);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -65,54 +65,54 @@ fn property() {
|
||||
.file(
|
||||
"foo.webidl",
|
||||
r#"
|
||||
[Constructor(double value)]
|
||||
interface Foo {
|
||||
[Pure]
|
||||
attribute double value;
|
||||
};
|
||||
"#,
|
||||
[Constructor(double value)]
|
||||
interface Foo {
|
||||
[Pure]
|
||||
attribute double value;
|
||||
};
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"foo.ts",
|
||||
"foo.js",
|
||||
r#"
|
||||
export class Foo {
|
||||
constructor(private _value: number) {
|
||||
this._value = _value;
|
||||
}
|
||||
export class Foo {
|
||||
constructor(value) {
|
||||
this._value = value;
|
||||
}
|
||||
|
||||
get value(): number {
|
||||
return this._value;
|
||||
}
|
||||
get value() {
|
||||
return this._value;
|
||||
}
|
||||
|
||||
set value(_value: number) {
|
||||
this._value = _value;
|
||||
set value(value) {
|
||||
this._value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
pub mod foo;
|
||||
pub mod foo;
|
||||
|
||||
use foo::Foo;
|
||||
use foo::Foo;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
let x = Foo::new(3.14159);
|
||||
assert_eq!(x.value(), 3.14159);
|
||||
assert_ne!(x.value(), 2.71828);
|
||||
x.set_value(2.71828);
|
||||
assert_ne!(x.value(), 3.14159);
|
||||
assert_eq!(x.value(), 2.71828);
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
let x = Foo::new(3.14159);
|
||||
assert_eq!(x.value(), 3.14159);
|
||||
assert_ne!(x.value(), 2.71828);
|
||||
x.set_value(2.71828);
|
||||
assert_ne!(x.value(), 3.14159);
|
||||
assert_eq!(x.value(), 2.71828);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -123,52 +123,55 @@ fn named_constructor() {
|
||||
.file(
|
||||
"foo.webidl",
|
||||
r#"
|
||||
[NamedConstructor=Bar(double value)]
|
||||
interface Foo {
|
||||
[Pure]
|
||||
readonly attribute double value;
|
||||
};
|
||||
"#,
|
||||
[NamedConstructor=Bar(double value)]
|
||||
interface Foo {
|
||||
[Pure]
|
||||
readonly attribute double value;
|
||||
};
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
// Not a perfect test, but it gets the job done.
|
||||
"foo.ts",
|
||||
"foo.js",
|
||||
r#"
|
||||
export class Foo {
|
||||
protected _value: number = 0;
|
||||
get value(): number {
|
||||
return this._value;
|
||||
}
|
||||
}
|
||||
export class Foo {
|
||||
constructor() {
|
||||
this._value = 0;
|
||||
}
|
||||
|
||||
export class Bar extends Foo {
|
||||
constructor(_value: number) {
|
||||
super();
|
||||
this._value = _value;
|
||||
get value(){
|
||||
return this._value;
|
||||
}
|
||||
}
|
||||
|
||||
export class Bar extends Foo {
|
||||
constructor(_value) {
|
||||
super();
|
||||
this._value = _value;
|
||||
}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
pub mod foo;
|
||||
pub mod foo;
|
||||
|
||||
use foo::Foo;
|
||||
use foo::Foo;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
let x = Foo::new(3.14159);
|
||||
assert_eq!(x.value(), 3.14159);
|
||||
assert_ne!(x.value(), 0.);
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
let x = Foo::new(3.14159);
|
||||
assert_eq!(x.value(), 3.14159);
|
||||
assert_ne!(x.value(), 0.);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -179,46 +182,47 @@ fn static_method() {
|
||||
.file(
|
||||
"foo.webidl",
|
||||
r#"
|
||||
interface Foo {
|
||||
static double swap(double value);
|
||||
};
|
||||
"#,
|
||||
interface Foo {
|
||||
static double swap(double value);
|
||||
};
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"foo.ts",
|
||||
"foo.js",
|
||||
r#"
|
||||
export class Foo {
|
||||
private static value: number = 0;
|
||||
static swap(value: number): number {
|
||||
const res = Foo.value;
|
||||
Foo.value = value;
|
||||
return res;
|
||||
export class Foo {
|
||||
static swap(value) {
|
||||
const res = Foo.value;
|
||||
Foo.value = value;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Foo.value = 0;
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
pub mod foo;
|
||||
pub mod foo;
|
||||
|
||||
use foo::Foo;
|
||||
use foo::Foo;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
assert_eq!(Foo::swap(3.14159), 0.);
|
||||
assert_eq!(Foo::swap(2.71828), 3.14159);
|
||||
assert_ne!(Foo::swap(2.71828), 3.14159);
|
||||
assert_eq!(Foo::swap(3.14159), 2.71828);
|
||||
assert_ne!(Foo::swap(3.14159), 2.71828);
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
assert_eq!(Foo::swap(3.14159), 0.);
|
||||
assert_eq!(Foo::swap(2.71828), 3.14159);
|
||||
assert_ne!(Foo::swap(2.71828), 3.14159);
|
||||
assert_eq!(Foo::swap(3.14159), 2.71828);
|
||||
assert_ne!(Foo::swap(3.14159), 2.71828);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
@ -229,51 +233,51 @@ fn static_property() {
|
||||
.file(
|
||||
"foo.webidl",
|
||||
r#"
|
||||
interface Foo {
|
||||
static attribute double value;
|
||||
};
|
||||
"#,
|
||||
interface Foo {
|
||||
static attribute double value;
|
||||
};
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"foo.ts",
|
||||
"foo.js",
|
||||
r#"
|
||||
export class Foo {
|
||||
private static _value: number = 0;
|
||||
export class Foo {
|
||||
static get value(){
|
||||
return Foo._value;
|
||||
}
|
||||
|
||||
static get value(): number {
|
||||
return Foo._value;
|
||||
static set value(value) {
|
||||
Foo._value = value;
|
||||
}
|
||||
}
|
||||
|
||||
static set value(_value: number) {
|
||||
Foo._value = _value;
|
||||
}
|
||||
}
|
||||
Foo._value = 0;
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
pub mod foo;
|
||||
pub mod foo;
|
||||
|
||||
use foo::Foo;
|
||||
use foo::Foo;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
assert_eq!(Foo::value(), 0.);
|
||||
Foo::set_value(3.14159);
|
||||
assert_eq!(Foo::value(), 3.14159);
|
||||
assert_ne!(Foo::value(), 2.71828);
|
||||
Foo::set_value(2.71828);
|
||||
assert_eq!(Foo::value(), 2.71828);
|
||||
assert_ne!(Foo::value(), 3.14159);
|
||||
}
|
||||
"#,
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
assert_eq!(Foo::value(), 0.);
|
||||
Foo::set_value(3.14159);
|
||||
assert_eq!(Foo::value(), 3.14159);
|
||||
assert_ne!(Foo::value(), 2.71828);
|
||||
Foo::set_value(2.71828);
|
||||
assert_eq!(Foo::value(), 2.71828);
|
||||
assert_ne!(Foo::value(), 3.14159);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user