1 // JavaScript Library for Nacl Tests and Demos
3 function NaclLib(modules
, statusfield
, num_retries
) {
4 this.modules_
= modules
;
5 this.statusfield_
= statusfield
;
9 this.retries_
= num_retries
;
13 NaclLib
.prototype.getStatus = function() {
18 NaclLib
.prototype.getMessage = function() {
23 NaclLib
.prototype.cleanUp = function() {
25 clearInterval(this._handler
);
30 NaclLib
.prototype.setStatus = function() {
31 this.statusfield_
.innerHTML
=
32 this.status_
+ ": " + this.message_
;
36 NaclLib
.prototype.setStatusWait = function(message
) {
37 this.status_
= "WAIT";
38 this.message_
= message
;
43 NaclLib
.prototype.setStatusError = function(message
) {
44 this.status_
= "ERROR";
45 this.message_
= message
;
50 NaclLib
.prototype.setStatusSuccess = function(message
) {
51 this.status_
= "SUCCESS";
52 this.message_
= message
;
57 NaclLib
.prototype.numModulesReady = function(modules
) {
59 for (var i
= 0; i
< modules
.length
; i
++) {
60 if (modules
[i
].__moduleReady
== 1) {
68 NaclLib
.prototype.areTherePluginProblems = function(modules
) {
69 for (var i
= 0; i
< modules
.length
; i
++) {
70 if (modules
[i
].__moduleReady
== undefined) return 1;
76 NaclLib
.prototype.checkModuleReadiness = function() {
77 var num_ready
= this.numModulesReady(this.modules_
);
79 this.setStatusWait("" + this.retries_
+ ": Loaded " +
80 num_ready
+ "/" + this.modules_
.length
+ " modules");
82 if (this.modules_
.length
== num_ready
) {
88 this.setStatusError(e
);
93 this.setStatusSuccess("");
95 this.setStatusError(result
);
100 if (this.areTherePluginProblems(this.modules_
)) {
102 this.setStatusError("The Native Client plugin was unable to load");
106 if (this.retries_
== 0) {
108 this.setStatusError("The Native Client modules are loading too slowly");
116 // Workaround for JS inconsistent scoping behavior
117 function wrapperForCheckModuleReadiness(that
) {
118 that
.checkModuleReadiness();
122 NaclLib
.prototype.waitForModulesAndRunTests = function() {
123 this.handler_
= setInterval(wrapperForCheckModuleReadiness
, 100, this);