Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ set(PREJS_FILES
${CMAKE_CURRENT_SOURCE_DIR}/include/pyjs/pre_js/dynload/dynload.js
${CMAKE_CURRENT_SOURCE_DIR}/include/pyjs/pre_js/fetch.js
${CMAKE_CURRENT_SOURCE_DIR}/include/pyjs/pre_js/load_pkg.js
${CMAKE_CURRENT_SOURCE_DIR}/include/pyjs/pre_js/literal_map.js
)
set(POSTJS_FILES
${CMAKE_CURRENT_SOURCE_DIR}/include/pyjs/post_js/fixes.js
Expand Down
50 changes: 50 additions & 0 deletions build_debug2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
set -e

# dir of this script
THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
PREFIX_DIR=$THIS_DIR/wasm_prefix
EMSDK_DIR=$THIS_DIR/emsdk_install
EMSDK_VERSION="3.1.58"

if [ ! -d "$EMSDK_DIR" ]; then
echo "Creating emsdk dir $EMSDK_DIR"
$THIS_DIR/emsdk/setup_emsdk.sh $EMSDK_VERSION $EMSDK_DIR
else
echo "Emsdk dir $EMSDK_DIR already exists"
fi


if true; then
rm -rf $PREFIX_DIR
echo "Creating wasm env at $PREFIX_DIR"
$MAMBA_EXE create -p $PREFIX_DIR \
--platform=emscripten-wasm32 \
-c https://repo.mamba.pm/emscripten-forge \
-c https://repo.mamba.pm/conda-forge \
--yes \
python pybind11 "emscripten-abi=3.1.58"\
bzip2 sqlite zlib libffi pytest
fi

cd $THIS_DIR
source $EMSDK_DIR/emsdk_env.sh


mkdir -p build
cd build

export PREFIX=$PREFIX_DIR
export CMAKE_PREFIX_PATH=$PREFIX
export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX

emcmake cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
-DBUILD_RUNTIME_BROWSER=ON \
-DBUILD_RUNTIME_NODE=OFF \
-DCMAKE_INSTALL_PREFIX=$PREFIX \
..

emmake make -j8
emmake make install
60 changes: 60 additions & 0 deletions include/pyjs/pre_js/literal_map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// see literal_map_license.txt for license information

const { get, getOwnPropertyDescriptor, ownKeys } = Reflect;

const getPropertyDescriptor = (value) => ({
value,
enumerable: true,
writable: true,
configurable: true,
});

const _ = Symbol();
const prototype = "prototype";

const handler = {
deleteProperty: (map, k) => (map.has(k) ? map.delete(k) : delete map[k]),
get(map, k, proxy) {
if (k === _) return map;
let v = map[k];
if (typeof v === "function" && k !== "constructor") {
v = v.bind(map);
}
v ||= map.get(k);
return v;
},
getOwnPropertyDescriptor(map, k) {
if (map.has(k)) return getPropertyDescriptor(map.get(k));
if (k in map) return getOwnPropertyDescriptor(map, k);
},
has: (map, k) => map.has(k) || k in map,
ownKeys: (map) =>
[...map.keys(), ...ownKeys(map)].filter((x) =>
["string", "symbol"].includes(typeof x),
),
set: (map, k, v) => (map.set(k, v), true),
};

const LiteralMap = new Proxy(
class LiteralMap extends Map {
constructor(...args) {
return new Proxy(super(...args), handler);
}
},
{
get(Class, k, ...rest) {
return k !== prototype && k in Class[prototype]
? (proxy, ...args) => {
const map = proxy[_];
let value = map[k];
if (typeof value === "function") value = value.apply(map, args);
// prevent leaking the internal map elsewhere
return value === map ? proxy : value;
}
: get(Class, k, ...rest);
},
},
);

// export default LiteralMap;
globalThis.LiteralMap = LiteralMap;
Loading