Lutz Roeder 9 månader sedan
förälder
incheckning
de0412733e
6 ändrade filer med 32 tillägg och 32 borttagningar
  1. 1 1
      source/circle.js
  2. 1 1
      source/coreml.js
  3. 10 10
      source/python.js
  4. 1 1
      source/tflite.js
  5. 3 4
      source/weka.js
  6. 16 15
      test/worker.js

+ 1 - 1
source/circle.js

@@ -354,7 +354,7 @@ circle.Node = class {
                 for (const [name, value] of Object.entries(options)) {
                     if (name === 'fused_activation_function' && value) {
                         if (value < 1 || value > 5) {
-                            throw new circle.Error(`Unsupported activation funtion index '${value}'.`);
+                            throw new circle.Error(`Unsupported activation function index '${value}'.`);
                         }
                         const list = ['Unknown', 'Relu', 'ReluN1To1', 'Relu6', 'Tanh', 'SignBit'];
                         const type = list[value];

+ 1 - 1
source/coreml.js

@@ -493,7 +493,7 @@ coreml.ImageType = class {
     }
 
     toString() {
-        return `image<${this.colorSpace},${this.width. toString()}x${this.height}>`;
+        return `image<${this.colorSpace},${this.width.toString()}x${this.height}>`;
     }
 };
 

+ 10 - 10
source/python.js

@@ -1073,7 +1073,7 @@ python.Execution = class {
                                 }
                                 if (op) {
                                     const left = stack.pop();
-                                    const right = this._parseExpression(precedence, terminal, tuple === true ? true : false);
+                                    const right = this._parseExpression(precedence, terminal, tuple === true);
                                     node = new ast.BinOp(left, op, right);
                                 } else {
                                     switch (token.value) {
@@ -1090,14 +1090,14 @@ python.Execution = class {
                                         default: break;
                                     }
                                     const left = stack.pop();
-                                    const comparator = this._parseExpression(precedence, ['for', 'if'], tuple === true ? true : false);
+                                    const comparator = this._parseExpression(precedence, ['for', 'if'], tuple === true);
                                     node = new ast.Compare(left, [op], [comparator]);
                                 }
                             } else if (token.value === '*') {
-                                const value =  this._parseExpression(precedence, terminal, tuple === true ? true : false);
+                                const value =  this._parseExpression(precedence, terminal, tuple === true);
                                 node = new ast.Starred(value);
                             } else if (token.value === '**') {
-                                const value =  this._parseExpression(precedence, terminal, tuple === true ? true : false);
+                                const value =  this._parseExpression(precedence, terminal, tuple === true);
                                 node = new ast.keyword(null, value);
                             } else {
                                 let op = null;
@@ -1108,7 +1108,7 @@ python.Execution = class {
                                     case 'not': op = new ast.Not(); break;
                                     default: throw new python.Error(`Unsupported unary operator ${token.value} ${this._location()}`);
                                 }
-                                const operand =  this._parseExpression(precedence, terminal, tuple === true ? true : false);
+                                const operand =  this._parseExpression(precedence, terminal, tuple === true);
                                 node = new ast.UnaryOp(op, operand);
                                 node = this._mark(node, position);
                             }
@@ -1118,7 +1118,7 @@ python.Execution = class {
                     }
                     if (this._tokenizer.eat(':=')) {
                         const target = stack.pop();
-                        const value = this._parseExpression(-1, terminal, tuple === false ? false : true);
+                        const value = this._parseExpression(-1, terminal, tuple !== false);
                         const node = new ast.NamedExpr(target, value);
                         this._mark(node, position);
                         stack.push(node);
@@ -1127,7 +1127,7 @@ python.Execution = class {
                     if (this._tokenizer.eat('=')) {
                         const position = this._position();
                         const targets = stack.pop();
-                        const value = this._parseExpression(-1, terminal, tuple === false ? false : true);
+                        const value = this._parseExpression(-1, terminal, tuple !== false);
                         const node = new ast.Assign([targets], value);
                         this._mark(node, position);
                         stack.push(node);
@@ -7482,7 +7482,7 @@ python.Execution = class {
             }
             _target_to_str(target) {
                 if (typeof target === 'string') {
-                    if (target.startsWith('__') && target.endswith('__')) {
+                    if (target.startsWith('__') && target.endsWith('__')) {
                         target = target.substring(2, target.length - 2);
                     }
                 } else {
@@ -15638,7 +15638,7 @@ python.Execution = class {
                     if (save_false.findInAnyFrame(v) || false_exits) {
                         mutated_variables.add(v);
                     } else {
-                        this.environment_stack.setVariableTypeError(v, () => 'Value is is not defined in the false branch.');
+                        this.environment_stack.setVariableTypeError(v, () => 'Value is not defined in the false branch.');
                     }
                     insert.dispose();
                 }
@@ -15647,7 +15647,7 @@ python.Execution = class {
                     if (save_true.findInAnyFrame(v) || true_exits) {
                         mutated_variables.add(v);
                     } else {
-                        this.environment_stack.setVariableTypeError(v, () => 'Value is is not defined in the true branch.');
+                        this.environment_stack.setVariableTypeError(v, () => 'Value is not defined in the true branch.');
                     }
                     insert.dispose();
                 }

+ 1 - 1
source/tflite.js

@@ -362,7 +362,7 @@ tflite.Node = class {
                 for (const [name, value] of Object.entries(options)) {
                     if (name === 'fused_activation_function' && value) {
                         if (value < 1 || value > 5) {
-                            throw new tflite.Error(`Unsupported activation funtion index '${value}'.`);
+                            throw new tflite.Error(`Unsupported activation function index '${value}'.`);
                         }
                         const list = ['Unknown', 'Relu', 'ReluN1To1', 'Relu6', 'Tanh', 'SignBit'];
                         const type = list[value];

+ 3 - 4
source/weka.js

@@ -144,12 +144,11 @@ java.io.InputObjectStream = class {
             superClass = superClass.superClass;
         }
         if (flags & 0x02) { // SC_SERIALIZABLE
-            debugger;
             const customObject = objects[classname];
             const hasReadObjectMethod = customObject && customObject.readObject;
             if (flags & 0x01) { // SC_WRITE_METHOD
                 if (!hasReadObjectMethod) {
-                    throw new Error('Class "'+ classname + '" dose not implement readObject()');
+                    throw new Error(`Class '${classname}' does not implement readObject().`);
                 }
                 customObject.readObject(this, obj);
                 if (this._reader.byte() !== 0x78) { // TC_ENDBLOCKDATA
@@ -204,8 +203,8 @@ java.io.InputObjectStream.BinaryReader = class {
 
     skip(offset) {
         this._position += offset;
-        if (this._position > this._end) {
-            throw new java.io.Error(`Expected ${this._position - this._end} more bytes. The file might be corrupted. Unexpected end of file.`);
+        if (this._position > this._length) {
+            throw new java.io.Error(`Expected ${this._position - this._length} more bytes. The file might be corrupted. Unexpected end of file.`);
         }
     }
 

+ 16 - 15
test/worker.js

@@ -278,7 +278,7 @@ class HTMLElement {
     }
 
     getBoundingClientRect() {
-        return { left: 0, top: 0, wigth: 0, height: 0 };
+        return { left: 0, top: 0, width: 0, height: 0 };
     }
 
     scrollTo() {
@@ -582,16 +582,17 @@ export class Target {
     }
 
     async validate() {
-        if (!this.model.format || (this.format && this.format !== this.model.format)) {
-            throw new Error(`Invalid model format '${this.model.format}'.`);
+        const model = this.model;
+        if (!model.format || (this.format && this.format !== model.format)) {
+            throw new Error(`Invalid model format '${model.format}'.`);
         }
-        if (this.producer && this.model.producer !== this.producer) {
-            throw new Error(`Invalid producer '${this.model.producer}'.`);
+        if (this.producer && model.producer !== this.producer) {
+            throw new Error(`Invalid producer '${model.producer}'.`);
         }
-        if (this.runtime && this.model.runtime !== this.runtime) {
-            throw new Error(`Invalid runtime '${this.model.runtime}'.`);
+        if (this.runtime && model.runtime !== this.runtime) {
+            throw new Error(`Invalid runtime '${model.runtime}'.`);
         }
-        if (this.model.metadata && !Array.isArray(this.model.metadata) && this.model.metadata.every((argument) => argument.name && argument.value)) {
+        if (model.metadata && (!Array.isArray(model.metadata) || !model.metadata.every((argument) => argument.name && argument.value))) {
             throw new Error("Invalid model metadata.'");
         }
         if (this.assert) {
@@ -599,7 +600,7 @@ export class Target {
                 const parts = assert.split('==').map((item) => item.trim());
                 const properties = parts[0].split('.');
                 const value = JSON.parse(parts[1].replace(/\s*'|'\s*/g, '"'));
-                let context = { model: this.model };
+                let context = { model };
                 while (properties.length) {
                     const property = properties.shift();
                     if (context[property] !== undefined) {
@@ -615,14 +616,14 @@ export class Target {
                             continue;
                         }
                     }
-                    throw new Error(`Invalid property path: '${parts[0]}`);
+                    throw new Error(`Invalid property path '${parts[0]}'.`);
                 }
                 if (context !== value) {
                     throw new Error(`Invalid '${context}' != '${assert}'.`);
                 }
             }
         }
-        if (this.model.version || this.model.description || this.model.author || this.model.license) {
+        if (model.version || model.description || model.author || model.license) {
             // continue
         }
         /* eslint-disable no-unused-expressions */
@@ -724,7 +725,7 @@ export class Target {
                     }
                 }
             }
-            if (graph.metadata && !Array.isArray(graph.metadata) && graph.metadata.every((argument) => argument.name && argument.value)) {
+            if (graph.metadata && (!Array.isArray(graph.metadata) || !graph.metadata.every((argument) => argument.name && argument.value))) {
                 throw new Error("Invalid graph metadata.'");
             }
             for (const node of graph.nodes) {
@@ -806,15 +807,15 @@ export class Target {
                 const sidebar = new view.NodeSidebar(this.view, node);
                 sidebar.render();
             }
-            const sidebar = new view.ModelSidebar(this.view, this.model, graph);
+            const sidebar = new view.ModelSidebar(this.view, model, graph);
             sidebar.render();
         };
-        for (const graph of this.model.graphs) {
+        for (const graph of model.graphs) {
             /* eslint-disable no-await-in-loop */
             await validateTarget(graph);
             /* eslint-enable no-await-in-loop */
         }
-        const functions = this.model.functions || [];
+        const functions = model.functions || [];
         for (const func of functions) {
             /* eslint-disable no-await-in-loop */
             await validateTarget(func);