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

Commit

Permalink
LUMO-28: Runtime option for disabling --use_strict
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro committed Nov 16, 2016
1 parent 6d6d5fd commit 1cde81a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

- Highlight the matching brace when inserting a closing brace.

### Changes

- Stop compiling Lumo with a static `--use-strict` V8 flag, allows to override it
at runtime ([#28](https://github.com/anmonteiro/lumo/issues/28)).

## [1.0.0-alpha3](https://github.com/anmonteiro/lumo/compare/1.0.0-alpha2...1.0.0-alpha3) (2016-11-15)

### Changes
Expand All @@ -23,15 +28,15 @@ indentation.
### New features

- Add `load` REPL special function. Same as [Clojure's `load`](http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/load).
- Add support for Windows-formatted class paths [#18](https://github.com/anmonteiro/lumo/pull/18).
- Add support for Windows-formatted class paths ([#18](https://github.com/anmonteiro/lumo/pull/18)).
- Add support for indentation via Parinfer when multiline editing.

### Bug fixes

- Lack of OpenSSL support breaks some Node.js modules ([#2](https://github.com/anmonteiro/lumo/issues/2)).
- Allow foreign libraries to side-effect the global scope when required.
- Improve error message when a path is not passed to `-k` ([#14](https://github.com/anmonteiro/lumo/issues/14)).
- Don't throw when loading empty files [#10](https://github.com/anmonteiro/lumo/issues/10).
- Don't throw when loading empty files ([#10](https://github.com/anmonteiro/lumo/issues/10)).
- `load-file` and init scripts shouldn't change the current namespace.
- Don't crash if JAR not found when looking for upstream foreign libs ([#19](https://github.com/anmonteiro/lumo/issues/19)).

Expand Down
1 change: 1 addition & 0 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ browserify({
NODE_ENV: isDevBuild ? 'development' : 'production',
}))
.exclude('nexeres')
.exclude('v8')
.bundle((err, buf) => {
if (err) {
throw err;
Expand Down
2 changes: 1 addition & 1 deletion scripts/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Promise.all(promises).then(() => {
resourceRoot: 'target',
flags: true, // use this for applications that need command line flags.
jsFlags: [
'--use_strict',
// '--use_strict',
// '--prepare_always_opt',
// '--always_opt',
// '--compiled_keyed_generic_loads',
Expand Down
4 changes: 2 additions & 2 deletions src/cljs/lumo/repl.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@
(with-redefs [js/module js/undefined
js/exports js/undefined]
(set! *loading-foreign* false)
(js/eval source))
(js/eval source)))
(js/LUMO_EVAL source))
(js/LUMO_EVAL source)))

;; =============================================================================
;; REPL plumbing
Expand Down
4 changes: 4 additions & 0 deletions src/js/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import * as lumo from './lumo';
import * as util from './util';
import version from './version';

// $FlowIssue: this module exists.
const v8 = require('v8'); // eslint-disable-line import/no-unresolved
const minimist = require('minimist');

type ScriptsType = [string, string][];
Expand Down Expand Up @@ -180,6 +182,8 @@ export default function startCLI(): void {
const opts = processOpts(getCLIOpts());
const mainScript = opts._.length > 0;

v8.setFlagsFromString('--use_strict');

if (mainScript) {
opts.repl = false;
}
Expand Down
11 changes: 11 additions & 0 deletions src/js/cljs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ const vm = require('vm');
let newContext;
let ClojureScriptContext;

function lumoEval(source: string): mixed {
if (__DEV__) {
// $FlowFixMe: this type differs according to the env
return vm.runInContext(source, ClojureScriptContext);
}
return vm.runInThisContext(source);
}

if (__DEV__) {
newContext = function newCtx(): vm$Context {
const cljsSrc = lumo.load('main.js');
Expand All @@ -20,6 +28,7 @@ if (__DEV__) {

const context = {
module,
exports,
require,
process,
console,
Expand All @@ -30,6 +39,7 @@ if (__DEV__) {
LUMO_WRITE_CACHE: lumo.writeCache,
LUMO_LOAD_UPS_DEPS_CLJS: lumo.loadUpstreamForeignLibs,
LUMO_EXISTS: lumo.fileExists,
LUMO_EVAL: lumoEval,
global: undefined,
};

Expand All @@ -48,6 +58,7 @@ if (__DEV__) {
global.LUMO_WRITE_CACHE = lumo.writeCache;
global.LUMO_LOAD_UPS_DEPS_CLJS = lumo.loadUpstreamForeignLibs;
global.LUMO_EXISTS = lumo.fileExists;
global.LUMO_EVAL = lumoEval;

// $FlowExpectedError: only exists in the custom V8 startup snapshot
initialize(); // eslint-disable-line no-undef
Expand Down

0 comments on commit 1cde81a

Please sign in to comment.