Permalink
Browse files

example-restrict-mode-on-the-fly html/js, examplifies hooking the jss…

…haper framework directly into the AMD loader
  • Loading branch information...
1 parent 3b58b50 commit 0bc887b96f98fb54ffe779fc97f653607cb7c929 @olov committed Oct 6, 2012
Showing with 43 additions and 1 deletion.
  1. +8 −0 README
  2. +18 −0 src/example-restrict-mode-on-the-fly.html
  3. +14 −0 src/example-restrict-mode-on-the-fly.js
  4. +3 −1 src/s.js
View
8 README
@@ -58,6 +58,14 @@ For restricter (the restrict mode checker), you can also run the more
convenient run-restricter:
example: node run-restricter.js myfile.js
+JSShaper can also execute on the fly, in your browser. Check out
+example-restrict-mode-on-the-fly.html for an example of how to use that to
+get restrict mode checking without a precomplilation step.
+
+If you want to restrict mode check your node.js code,
+plugins/restricter/restrict-mode.js can be loaded with require once and its
+helper functions (such as __add) will be accessible to all other modules.
+
JSShaper and its plugins are Open Source and licensed under the MIT
license, see LICENSE file for terms and conditions.
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<title>Restrict mode checking on-the-fly</title>
+<script type="text/javascript" src="plugins/restricter/restrict-mode.js"></script>
+<script type="text/javascript" data-main="s!restricter!example-restrict-mode-on-the-fly" src="require.js"></script>
+</head>
+
+<body>
+<h3>Restrict mode checking on-the-fly</h3>
+<p>
+ Executing <a href="example-restrict-mode-on-the-fly.js">example-restrict-mode-on-the-fly.js</a>. Bring
+ up your console.
+</p>
+<pre id="output"></pre>
+
+</body> </html>
@@ -0,0 +1,14 @@
+define(function() {
+ "use strict";
+
+ (function() {
+ console.log("evaluating 1 + undefined, not using strict mode. watch the NaN.");
+ console.log(1 + undefined); // NaN
+ })();
+
+ (function() {
+ "use restrict";
+ console.log("evaluating 1 + undefined, using strict mode. watch it fail fast!");
+ console.log(1 + undefined); // BOOM!
+ })();
+});
View
@@ -89,7 +89,8 @@
}
// load the plugin
var pluginPaths = {
- yielder: './plugins/yielder/yielder'
+ yielder: './plugins/yielder/yielder',
+ restricter: './plugins/restricter',
};
var ppath = prefix;
if (prefix in pluginPaths) {
@@ -130,6 +131,7 @@
};
root = Shaper.run(root, [plugin, hackdeps]);
text = root.getSrc();
+// console.log("shaper produced "+ name +": "+ text);
} catch (e) {// throw e;
var msg = "Could not compile: "+path;
msg += " ("+e.toString();

0 comments on commit 0bc887b

Please sign in to comment.