Permalink
Browse files

Removed a bunch of old examples and updated the ones left to a new, n…

…icer format
  • Loading branch information...
1 parent e73a9fe commit b7e65405f00dbe7030de1d8bf24ec7037f9b61fb @jterrace committed Apr 19, 2012
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1,45 +0,0 @@
-<html>
-<head>
-<title>js.js Browser Emulator</title>
-<script type="text/javascript" src="../../src/libjs.O2.js"></script>
-<script type="text/javascript" src="../../src/jsjs-wrapper.js"></script>
-<script type="text/javascript">
-
- function start_jsjs() {
- var jsObjs = JSJS.Init();
-
- jsjsWindowObj = JSJS.DefineObject(jsObjs.cx, jsObjs.glob, "window", 0, 0, 0);
- if (!jsjsWindowObj) {
- console.log("Creating object failed");
- } else {
-
- function customAlert(str) {
- window.alert(str);
- }
-
- var wrappedCustomAlert = JSJS.wrapFunction({
- func: customAlert,
- args: [JSJS.Types.charPtr],
- returns: null
- });
-
- JSJS.DefineFunction(jsObjs.cx, jsjsWindowObj, "alert", wrappedCustomAlert, 1, 0);
-
- var src = "window.alert('Hello, world!');";
- rval = JSJS.EvaluateScript(jsObjs.cx, jsObjs.glob, src);
-
- }
-
- // This is how you do a proper shut down
- JSJS.End(jsObjs);
- }
-
- window.onload = start_jsjs;
-
- </script>
-</head>
-<body>
- <h1>js.js Browser Emulator</h1>
- <p id="demo"></p>
-</body>
-</html>
@@ -1,24 +1,26 @@
+<!DOCTYPE html>
<html>
<head>
<title>js.js Callbacks Testing</title>
-<script type="text/javascript" src="../../src/libjs.O1.js"></script>
-<script type="text/javascript" src="../../src/jsjs-wrapper.js"></script>
+<link href="../bootstrap.min.css" rel="stylesheet" >
+<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
+<script type="text/javascript" src="../../src/libjs.O2.min.js"></script>
+<script type="text/javascript" src="../common.js"></script>
<script type="text/javascript">
-
function start_jsjs() {
var jsObjs = JSJS.Init();
// 1 int
function callbackInt(func) {
- console.log("callbackInt");
+ reportMessage("callbackInt");
var jsvalout = JSJS.CreateJSVal(jsObjs.cx, func, JSJS.Types.objPtr);
JSJS.CallFunctionValue(jsObjs.cx, jsObjs.glob, jsvalout, [JSJS.Types.i32], [55]);
}
function verifyInt(val) {
- console.log("verifyInt");
- console.log("int val should be 55: " + val);
+ reportMessage("verifyInt");
+ reportMessage("int val should be 55: " + val);
assert(val == 55);
return 55;
}
@@ -40,14 +42,14 @@
// 1 string
function callbackString(func) {
- console.log("callbackString");
- console.log(func);
+ reportMessage("callbackString");
+ reportMessage(func);
var jsvalout = JSJS.CreateJSVal(jsObjs.cx, func, JSJS.Types.objPtr);
JSJS.CallFunctionValue(jsObjs.cx, jsObjs.glob, jsvalout, [JSJS.Types.charPtr], ["blah"]);
}
function verifyString(s) {
- console.log("verifyString");
- console.log("s val should be 'blah': " + s);
+ reportMessage("verifyString");
+ reportMessage("s val should be 'blah': " + s);
assert(s == 'blah');
return "blah";
}
@@ -68,7 +70,7 @@
// 1 object
function objGetProperty(propName) {
- console.log("obj get property " + propName);
+ reportMessage("obj get property " + propName);
switch(propName) {
case "tester":
return {'type': JSJS.Types.charPtr, 'val': "hello"};
@@ -88,16 +90,16 @@
var jsObj = JSJS.NewObject(jsObjs.cx, jsObjClass, 0, 0);
function callbackObject(func) {
- console.log("callbackObject");
- console.log(func);
+ reportMessage("callbackObject");
+ reportMessage(func);
var jsvalout = JSJS.CreateJSVal(jsObjs.cx, func, JSJS.Types.objPtr);
JSJS.CallFunctionValue(jsObjs.cx, jsObjs.glob, jsvalout, [JSJS.Types.objPtr], [jsObj]);
}
function verifyObject(o, b) {
- console.log("verifyObject");
- console.log("obj val should be " + jsObj + ": " + o);
+ reportMessage("verifyObject");
+ reportMessage("obj val should be " + jsObj + ": " + o);
assert(o == jsObj);
- console.log("obj bool should be 'true': " + b);
+ reportMessage("obj bool should be 'true': " + b);
assert(b == true);
}
var wrappedCallbackObject = JSJS.wrapFunction({
@@ -124,6 +126,13 @@
</script>
</head>
<body>
- <h1>js.js Callback Testing</h1>
+ <div class="container">
+ <div class="page-header">
+ <h1>js.js Callback Testing</h1>
+ </div>
+ <p>Demonstrates two-way communication with different argument types. Shows integers, strings, and objects
+ being passed back and forth between sandbox and native JavaScript space.</p>
+ <pre id="console_log"></pre>
+ </div>
</body>
</html>
View
@@ -0,0 +1,10 @@
+function reportMessage(s) {
+ console.log(s);
+ $('pre#console_log').append(s + "\n");
+}
+
+function assert(v) {
+ if (!v) {
+ throw "Assertion failed";
+ }
+}
@@ -1,94 +0,0 @@
-<html>
-<head>
-<title>js.js Complex Document Property </title>
-<script type="text/javascript" src="../../src/js.O1.js"></script>
-<script type="text/javascript" src="../../src/jsjs-wrapper.js"></script>
-<script type="text/javascript">
-
-
-
- function start_jsjs() {
- var jsObjs = JSJS.Init();
- var map = new Array(); // Be able to map backwards from the JSObject to the real one
-
- jsjsDocument = JSJS.DefineObject(jsObjs.cx, jsObjs.glob, "document", 0, 0, 0);
- if (!jsjsDocument) {
- throw ("Creating object failed");
- }
-
- // Custom Setter
- function set_customInnerHtml(cx,obj,idval,strict,str) {
- document.getElementById(map[obj]).innerHTML = str;
- };
-
- //Wrap the setter and define the property
- var setterPtr = JSJS.wrapSetter(set_customInnerHtml);
-
- function customGetElement(str) {
- console.log("Calling get element for " + str + " (should see me twice)");
- if(!(document.getElementById(str).jsjs))
- {
- console.log("Creating the element for " + str + " (should only see me once)");
- // create the object
- var elementObject = JSJS.DefineObject(jsObjs.cx, jsjsDocument, str, 0, 0, 0);
-
- // create innerHTML property and assign setter
- var ok=JSJS.DefineProperty(jsObjs.cx, elementObject, "innerHTML", 0, 0, setterPtr, 0);
-
- // map the object
- document.getElementById(str).jsjs = elementObject;
- var strptr = allocate(intArrayFromString("innerHTML"), 'i8', ALLOC_NORMAL);
- var jsval = _INT_TO_JSVAL(42);
- map[elementObject] = str;
- //_JS_SetProperty(jsObjs.cx, elementObject, strptr, jsval);
- }
-
- // return object
- var retVal = document.getElementById(str).jsjs;
- return retVal;
- }
-
- // Wrap customGetElement
- var wrappedCustomElement = JSJS.wrapFunction({
- func: customGetElement,
- args: [JSJS.Types.charPtr],
- returns: JSJS.Types.objPtr});
-
- JSJS.DefineFunction(jsObjs.cx, jsjsDocument, "getElementById",
- wrappedCustomElement, 1, 0);
-
-
- // Everything has gone well, execute script
- var src = "document.getElementById('demo').innerHTML = 'It worked'; \
- document.getElementById('demo').innerHTML = 'The meaning of life'; \
- document.getElementById('demo2').innerHTML = 37; \
- document.getElementById('demo2').innerHTML = 42; \
- document.getElementById('demo3').innerHTML = 33.33; \
- document.getElementById('demo3').innerHTML = 33.33;";
-
-
- rval = JSJS.EvaluateScript(jsObjs.cx, jsObjs.glob, src);
- if (rval) {
- //Convert the JSVal to 'the right thing'
- d = JSJS.identifyConvertValue(jsObjs.cx, rval);
- } else {
- d = "Can't get result because an error happened.";
- }
-
-
- // This is how you do a proper shut down
- JSJS.End(jsObjs);
- }
-
- </script>
-</head>
-<body>
- <h1>js.js Complex Document Property Test</h1>
- <p id="demo">This should be replaced by 'The meaning of life'</p>
- <p id="demo2">This should be replaced by '42'</p>
- <p id="demo3">This should be replaced by '33.33'</p>
- <script type="text/javascript">
- start_jsjs();
- </script>
-</body>
-</html>
@@ -1,42 +0,0 @@
-<html>
-<head>
-<title>js.js Cookie Security</title>
-<script type="text/javascript" src="../../src/libjs.O2.js"></script>
-<script type="text/javascript" src="../../src/jsjs-wrapper.js"></script>
-<script type="text/javascript">
-
-var scriptSrc = "document.getElementById('demo').innerHTML = document.cookie;";
- function start_jsjs() {
- var jsObjs = JSJS.Init();
- var ok = JSJS.InitDocument(jsObjs, 'locked');
- JSJS.UnlockElement(document.getElementById('demo'));
-
- // Everything has gone well, execute script
- rval = JSJS.EvaluateScript(jsObjs.cx, jsObjs.glob, scriptSrc);
- if (rval) {
- //Convert the JSVal to 'the right thing'
- d = JSJS.identifyConvertValue(jsObjs.cx, rval);
- } else {
- d = "Can't get result because an error happened.";
- }
-
- // This is how you do a proper shut down
- JSJS.End(jsObjs);
- }
-
- function unprotected() { eval(scriptSrc); };
-
- </script>
-</head>
-<body>
- <script type="text/javascript"> document.cookie = "something=Thecookieshavebeenstolen"; </script>
- <h1>js.js Cookie Security Test</h1>
- <form>
-
- <input type="button" value="Protected" onclick="start_jsjs()" >
- <input type="button" value="Native" onclick="unprotected()" >
- </form>
-
- Document cookie:<div id="demo"></div>
-</body>
-</html>
View
@@ -1,17 +1,12 @@
-function fib(fld) {
- function f(n) {
- if(n == 0) return(0);
- if(n == 1) {
- return(1);
- }
- else {
- return(f(n - 1) + f(n - 2));
- }
- };
-
- var iters = window.prompt("What iteration (less than 30) of the Fibonacci sequence would you like to see?", 10);
- var res = f(iters);
- var ret = "The " + iters + " iteration of Fibonacci sequence is " + res;
- document.getElementById(fld).innerHTML = ret;
+function fibonacci(n) {
+ if (n==0 || n==1) {
+ return n;
+ }
+ var prev2 = 0, prev1 = 1, fib = 1, i;
+ for (i=2; i<=n; i++) {
+ fib = prev1 + prev2;
+ prev2 = prev1;
+ prev1 = fib;
+ }
+ return fib;
}
-
Oops, something went wrong.

0 comments on commit b7e6540

Please sign in to comment.