Skip to content
Browse files

Avoid using a Java applet if it's not needed.

  • Loading branch information...
1 parent 63c5cb6 commit 36e0460ff91da9bfe1269f5165c4882689b18204 @jdalton jdalton committed Aug 19, 2012
Showing with 35 additions and 13 deletions.
  1. +19 −9 example/jsperf/ui.js
  2. +16 −4 test/index.html
View
28 example/jsperf/ui.js
@@ -698,6 +698,25 @@
html.scrollTop = scrollTop;
}());
+ // inject nano applet
+ // (assumes ui.js is just before </body>)
+ (function() {
+ var measured,
+ perfNow,
+ begin = new Date;
+
+ if ('nojava' in ui.params) {
+ return addClass('java', classNames.show);
+ }
+ // is the applet really needed?
+ while (!(measured = new Date - begin)) { }
+ if (measured != 1 && !((perfNow = window.performance) && typeof (perfNow.webkitNow || perfNow.now) == 'function')) {
+ // load applet using innerHTML to avoid an alert in some versions of IE6
+ document.body.insertBefore(setHTML(createElement('div'),
+ '<applet code=nano archive=' + archive + '>').lastChild, document.body.firstChild);
+ }
+ }());
+
// catch and display errors from the "preparation code"
window.onerror = function(message, fileName, lineNumber) {
logError('<p>' + message + '.</p><ul><li>' + join({
@@ -707,15 +726,6 @@
}, '</li><li>') + '</li></ul>');
scrollEl.scrollTop = $('error-info').offsetTop;
};
- // inject nano applet
- // (assumes ui.js is just before </body>)
- if ('nojava' in ui.params) {
- addClass('java', classNames.show);
- } else {
- // using innerHTML avoids an alert in some versions of IE6
- document.body.insertBefore(setHTML(createElement('div'),
- '<applet code=nano archive=' + archive + '>').lastChild, document.body.firstChild);
- }
}
else {
// short circuit unusable methods
View
20 test/index.html
@@ -45,10 +45,22 @@
QUnit.urlParams.nojava = /[?&]nojava=true(?:&|$)/.test(location.search);
QUnit.urlParams.norequire = /[?&]norequire=true(?:&|$)/.test(location.search);
- // load the nanosecond timer
- if (!QUnit.urlParams.nojava) {
- document.write('<applet code="nano" archive="../nano.jar"></applet>');
- }
+ (function() {
+ if (QUnit.urlParams.nojava) {
+ return;
+ }
+ var measured,
+ perfNow,
+ begin = new Date;
+
+ // is the applet really needed?
+ while (!(measured = new Date - begin)) { }
+ if (measured != 1 && !((perfNow = window.performance) && typeof (perfNow.webkitNow || perfNow.now) == 'function')) {
+ // load applet
+ document.write('<applet code="nano" archive="../nano.jar"></applet>');
+ }
+ }());
+
// load require.js
if (!QUnit.urlParams.norequire) {
document.write('<script src="../vendor/requirejs/require.js"><\/script>');

0 comments on commit 36e0460

Please sign in to comment.
Something went wrong with that request. Please try again.