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

Adds asm.js support #7

Merged
merged 27 commits into from
Mar 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6ff35dc
Adds asm.js support
arcanis Jan 15, 2017
006255c
Implements Patch.compose
arcanis Jan 16, 2017
87bda03
Reverts snakecase bindings
arcanis Jan 16, 2017
82d34a7
Fixes the compilation warning by enforcing unsigned (end will never b…
arcanis Jan 18, 2017
68c5d2c
Tries to compile browser.js if possible; useful for using the git rep…
arcanis Jan 18, 2017
dc262d5
Wraps the generated code inside UMD markers
arcanis Jan 19, 2017
87d1c25
Exposes legacy properties
arcanis Jan 19, 2017
20be491
Merge branch 'master' of https://github.com/arcanis/superstring into …
maxbrunsfeld Feb 24, 2017
accbd20
Bridge MarkerIndex.has in emscripten binding
maxbrunsfeld Feb 24, 2017
3b02be2
Rename Marker::delete to remove to avoid conflict w/ emscripten method
maxbrunsfeld Feb 24, 2017
afd2299
Remove legacy fields from Hunk
maxbrunsfeld Feb 24, 2017
6c075bd
Add script for installing emscripten
maxbrunsfeld Mar 3, 2017
8128996
Install cmake on travis
maxbrunsfeld Mar 3, 2017
18bd75d
Install newer cmake on travis
maxbrunsfeld Mar 3, 2017
fc9e947
Try to get Travis to build the right commit
maxbrunsfeld Mar 3, 2017
afbeff3
Try using trusty on Travis
maxbrunsfeld Mar 3, 2017
48230bf
Download cmake binary manually on travis
maxbrunsfeld Mar 3, 2017
9acb148
Install a newer libstdc++ version on travis
maxbrunsfeld Mar 3, 2017
814d505
Try another name for the libstdc++ package on travis
maxbrunsfeld Mar 3, 2017
5ab2b74
Install libc++ via gcc package on travis
maxbrunsfeld Mar 3, 2017
76e9b13
Try using gcc rather than clang on travis
maxbrunsfeld Mar 4, 2017
4b2c515
Just use 2 cores when building emscripten
maxbrunsfeld Mar 6, 2017
97f6d9f
Install emscripten earlier in travis build and use 4 cores
maxbrunsfeld Mar 6, 2017
64afc4b
Cache emscripten's cache directory on travis
maxbrunsfeld Mar 6, 2017
1aa3cee
Change environment variable used to force browser version
maxbrunsfeld Mar 6, 2017
ea0c014
Use two spaces in browser.js sources
maxbrunsfeld Mar 6, 2017
c49a89d
Remove unnecessary rebuild on Travis
maxbrunsfeld Mar 6, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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