Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #7 from arcanis/master
Browse files Browse the repository at this point in the history
Adds asm.js support
  • Loading branch information
Max Brunsfeld authored Mar 6, 2017
2 parents ba12951 + c49a89d commit 86d8320
Show file tree
Hide file tree
Showing 31 changed files with 773 additions and 81 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ node_modules
build
.DS_Store
.clang_complete

/browser.js
emsdk_portable
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
test
build
.gitignore
emsdk_portable
26 changes: 22 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: node_js
sudo: false

notifications:
email:
Expand All @@ -8,8 +9,17 @@ notifications:
node_js:
- "node"

before_install:
- export CXX="g++-4.8" CC="gcc-4.8"
- curl https://cmake.org/files/v3.6/cmake-3.6.3-Linux-x86_64.tar.gz | tar xz
- export PATH=${PWD}/cmake-3.6.3-Linux-x86_64/bin:$PATH
- script/install-emscripten.sh

script:
- "npm run ci"
- npm run standard
- npm run build:browser
- npm run test:browser
- npm run test:node

git:
depth: 10
Expand All @@ -18,7 +28,15 @@ branches:
only:
- master

sudo: false
cache:
directories:
- emsdk_portable
- $HOME/.emscripten_cache

env:
- CXX=clang++
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-4.8
- g++-4.8
12 changes: 8 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
try {
module.exports = require('./build/Release/superstring.node')
} catch (e) {
module.exports = require('./build/Debug/superstring.node')
if (process.env.SUPERSTRING_USE_BROWSER_VERSION) {
module.exports = require('./browser');
} else {
try {
module.exports = require('./build/Release/superstring.node')
} catch (e) {
module.exports = require('./build/Debug/superstring.node')
}
}
17 changes: 12 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
"name": "superstring",
"version": "1.1.0",
"description": "A data structure to efficiently represent the results of applying patches.",
"main": "./index",
"browser": "./browser",
"scripts": {
"test-native": "script/test-native.js",
"test": "mocha test/js/*.js",
"build:node": "node-gyp rebuild",
"build:browser": "script/build-browser-version.sh",
"build": "npm run build:node && npm run build:browser",
"test:native": "script/test-native.js",
"test:node": "mocha test/js/*.js",
"test:browser": "SUPERSTRING_USE_BROWSER_VERSION=1 mocha test/js/*.js",
"test": "npm run test:node && npm run test:browser",
"benchmark": "node benchmark/marker-index.benchmark.js",
"prepublish": "npm run standard",
"standard": "standard --recursive src test",
"ci": "npm run standard && node-gyp rebuild --debug --tests && npm run test"
"prepublish": "not-in-install && npm run build:browser || in-install",
"standard": "standard --recursive src test"
},
"repository": {
"type": "git",
Expand All @@ -29,6 +35,7 @@
},
"devDependencies": {
"chai": "^2.0.0",
"in-publish": "^2.0.0",
"mocha": "^2.3.4",
"random-seed": "^0.2.0",
"segfault-handler": "^1.0.0",
Expand Down
18 changes: 18 additions & 0 deletions script/build-browser-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

EM_COMPILER_PATH=$(find emsdk_portable -name em++ | head -n1)

echo "Running ${EM_COMPILER_PATH}"
${EM_COMPILER_PATH} \
--bind \
-o browser.js \
-O3 \
-std=c++14 \
-I src/bindings/em \
-I src/core \
--pre-js src/bindings/em/prologue.js \
--post-js src/bindings/em/epilogue.js \
src/core/*.cc \
src/bindings/em/*.cc \
-s TOTAL_MEMORY=134217728 \
--memory-init-file 0 \
17 changes: 17 additions & 0 deletions script/install-emscripten.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set -e

EMSCRIPTEN_DOWNLOAD_URL='https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-portable.tar.gz'
EMSDK_PATH="./emsdk_portable/emsdk"

if [ ! -f $EMSDK_PATH ]; then
echo 'Downloading emscripten SDK installer...'
curl $EMSCRIPTEN_DOWNLOAD_URL | tar xz
fi

echo 'Installing emscripten SDK...'

$EMSDK_PATH update
$EMSDK_PATH install -j4 latest
$EMSDK_PATH activate latest
2 changes: 2 additions & 0 deletions src/bindings/buffer-offset-index-wrapper.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "buffer-offset-index-wrapper.h"
#include "noop.h"
#include "point-wrapper.h"

using namespace v8;
Expand All @@ -8,6 +9,7 @@ void BufferOffsetIndexWrapper::init(Local<Object> exports) {
constructor_template->SetClassName(Nan::New<String>("BufferOffsetIndex").ToLocalChecked());
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
const auto &prototype_template = constructor_template->PrototypeTemplate();
prototype_template->Set(Nan::New<String>("delete").ToLocalChecked(), Nan::New<FunctionTemplate>(noop));
prototype_template->Set(Nan::New<String>("splice").ToLocalChecked(), Nan::New<FunctionTemplate>(splice));
prototype_template->Set(Nan::New<String>("positionForCharacterIndex").ToLocalChecked(), Nan::New<FunctionTemplate>(position_for_character_index));
prototype_template->Set(Nan::New<String>("characterIndexForPosition").ToLocalChecked(), Nan::New<FunctionTemplate>(character_index_for_position));
Expand Down
15 changes: 15 additions & 0 deletions src/bindings/em/as.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <emscripten/val.h>

#include "patch.h"

template<> inline Patch const * emscripten::val::as<Patch const *>(void) const {
using namespace emscripten;
using namespace internal;

EM_DESTRUCTORS destructors;
EM_GENERIC_WIRE_TYPE result = _emval_as(handle, TypeID<AllowedRawPointer<Patch const>>::get(), &destructors);
DestructorsRunner dr(destructors);
return fromGenericWireType<Patch *>(result);
}
Loading

0 comments on commit 86d8320

Please sign in to comment.