diff --git a/source/io/module_eggShell.js b/source/io/module_eggShell.js index aae6ac1a3..ff8d2c497 100644 --- a/source/io/module_eggShell.js +++ b/source/io/module_eggShell.js @@ -232,16 +232,19 @@ var assignEggShell; var dataStackPointer = Module.stackAlloc(POINTER_SIZE); var eggShellResult = Module._EggShell_FindValue(Module.eggShell.v_userShell, viStackPointer, pathStackPointer, typeStackPointer, dataStackPointer); - if (eggShellResult !== EGGSHELL_RESULT.SUCCESS) { + if (eggShellResult !== EGGSHELL_RESULT.SUCCESS && eggShellResult !== EGGSHELL_RESULT.OBJECT_NOT_FOUND_AT_PATH) { throw new Error('A ValueRef could not be made for the following reason: ' + eggShellResultEnum[eggShellResult] + ' (error code: ' + eggShellResult + ')' + ' (vi name: ' + vi + ')' + ' (path: ' + path + ')'); } - var typeRef = Module.getValue(typeStackPointer, 'i32'); - var dataRef = Module.getValue(dataStackPointer, 'i32'); - var valueRef = Module.eggShell.createValueRef(typeRef, dataRef); + var typeRef, dataRef, valueRef; + if (eggShellResult !== EGGSHELL_RESULT.OBJECT_NOT_FOUND_AT_PATH) { + typeRef = Module.getValue(typeStackPointer, 'i32'); + dataRef = Module.getValue(dataStackPointer, 'i32'); + valueRef = Module.eggShell.createValueRef(typeRef, dataRef); + } Module.stackRestore(stack); return valueRef; @@ -255,16 +258,19 @@ var assignEggShell; var dataStackPointer = Module.stackAlloc(POINTER_SIZE); var eggShellResult = Module._EggShell_FindSubValue(Module.eggShell.v_userShell, valueRef.typeRef, valueRef.dataRef, subPathStackPointer, typeStackPointer, dataStackPointer); - if (eggShellResult !== EGGSHELL_RESULT.SUCCESS) { + if (eggShellResult !== EGGSHELL_RESULT.SUCCESS && eggShellResult !== EGGSHELL_RESULT.OBJECT_NOT_FOUND_AT_PATH) { throw new Error('A ValueRef could not be made for the following reason: ' + eggShellResultEnum[eggShellResult] + ' (error code: ' + eggShellResult + ')' + ' (type name: ' + Module.typeHelpers.typeName(valueRef.typeRef) + ')' + ' (subpath: ' + subPath + ')'); } - var typeRef = Module.getValue(typeStackPointer, 'i32'); - var dataRef = Module.getValue(dataStackPointer, 'i32'); - var subValueRef = Module.eggShell.createValueRef(typeRef, dataRef); + var typeRef, dataRef, subValueRef; + if (eggShellResult !== EGGSHELL_RESULT.OBJECT_NOT_FOUND_AT_PATH) { + typeRef = Module.getValue(typeStackPointer, 'i32'); + dataRef = Module.getValue(dataStackPointer, 'i32'); + subValueRef = Module.eggShell.createValueRef(typeRef, dataRef); + } Module.stackRestore(stack); return subValueRef; diff --git a/test-it/karma/publicapi/AllocateTypes.Test.js b/test-it/karma/publicapi/AllocateTypes.Test.js index ee2293926..7448a3ddb 100644 --- a/test-it/karma/publicapi/AllocateTypes.Test.js +++ b/test-it/karma/publicapi/AllocateTypes.Test.js @@ -67,10 +67,8 @@ describe('Vireo public API allows', function () { }; describe('error handling', function () { - // Use a memory aligned invalid addess to avoid alignment warnings in debug builds - // Debug builds enable SAFE_HEAP which warns on unaligned access: https://kripken.github.io/emscripten-site/docs/porting/guidelines/portability_guidelines.html#other-issues - // Wasm supports unaligned memory access, although it may cause performance degradation - var invalidAddress = 1024; + // Use null pointer for an invalid address. Random values can have unexpected results. + var invalidAddress = 0; describe('for allocateData', function () { it('throws an InvalidTypeRef error given an invalid typeRef', function () { var invalidTypeRef = invalidAddress; diff --git a/test-it/karma/publicapi/FindSubValueRef.Test.js b/test-it/karma/publicapi/FindSubValueRef.Test.js index 2fbd8cae1..2e16f90ca 100644 --- a/test-it/karma/publicapi/FindSubValueRef.Test.js +++ b/test-it/karma/publicapi/FindSubValueRef.Test.js @@ -59,12 +59,9 @@ describe('The Vireo EggShell findSubValueRef', function () { expect(invalidValueRef).toThrow(); }); - it('throws for a nonexistant path', function () { - var invalidPath = function () { - vireo.eggShell.findSubValueRef(valueRef, 'nonexistantpath'); - }; - - expect(invalidPath).toThrow(); + it('return undefined for a nonexistant path', function () { + var nonExistantValueRef = vireo.eggShell.findSubValueRef(valueRef, 'nonexistantpath'); + expect(nonExistantValueRef).toBeUndefined(); }); it('finds values of cluster elements', function () { @@ -87,20 +84,14 @@ describe('The Vireo EggShell findSubValueRef', function () { valueRef = vireo.eggShell.findValueRef(viName, arrayOfBooleansPath); }); - it('throws for invalid index', function () { - var invalidIndex = function () { - vireo.eggShell.findSubValueRef(valueRef, '-1'); - }; - - expect(invalidIndex).toThrow(); + it('return undefined for invalid index', function () { + var nonExistantValueRef = vireo.eggShell.findSubValueRef(valueRef, '-1'); + expect(nonExistantValueRef).toBeUndefined(); }); - it('throws for index out of bounds', function () { - var invalidIndex = function () { - vireo.eggShell.findSubValueRef(valueRef, '10'); - }; - - expect(invalidIndex).toThrow(); + it('return undefined for index out of bounds', function () { + var nonExistantValueRef = vireo.eggShell.findSubValueRef(valueRef, '10'); + expect(nonExistantValueRef).toBeUndefined(); }); it('finds a value', function () { @@ -116,20 +107,14 @@ describe('The Vireo EggShell findSubValueRef', function () { valueRef = vireo.eggShell.findValueRef(viName, ndimArrayPath); }); - it('throws for an invalid path format', function () { - var invalidPathFormat = function () { - vireo.eggShell.findSubValueRef(valueRef, '0,0.0'); - }; - - expect(invalidPathFormat).toThrow(); + it('return undefined for an invalid path format', function () { + var nonExistantValueRef = vireo.eggShell.findSubValueRef(valueRef, '0,0.0'); + expect(nonExistantValueRef).toBeUndefined(); }); - it('throws for index out of bounds', function () { - var indexOutOfBounds = function () { - vireo.eggShell.findSubValueRef(valueRef, '2,0,0'); - }; - - expect(indexOutOfBounds).toThrow(); + it('return undefined for index out of bounds', function () { + var nonExistantValueRef = vireo.eggShell.findSubValueRef(valueRef, '2,0,0'); + expect(nonExistantValueRef).toBeUndefined(); }); it('finds values for comma-separated indexes', function () { @@ -150,12 +135,9 @@ describe('The Vireo EggShell findSubValueRef', function () { valueRef = vireo.eggShell.findValueRef(viName, arrayOfClustersPath); }); - it('throws for invalid path format', function () { - var invalidPathFormat = function () { - vireo.eggShell.findSubValueRef(valueRef, '0,bool'); - }; - - expect(invalidPathFormat).toThrow(); + it('return undefined for invalid path format', function () { + var nonExistantValueRef = vireo.eggShell.findSubValueRef(valueRef, '0,bool'); + expect(nonExistantValueRef).toBeUndefined(); }); it('finds values for indexes followed by "." field name', function () { @@ -177,20 +159,14 @@ describe('The Vireo EggShell findSubValueRef', function () { valueRef = vireo.eggShell.findValueRef(viName, clusterOfArraysPath); }); - it('throws for invalid path format', function () { - var invalidPathFormat = function () { - vireo.eggShell.findSubValueRef(valueRef, 'booleans,0'); - }; - - expect(invalidPathFormat).toThrow(); + it('return undefined for invalid path format', function () { + var nonExistantValueRef = vireo.eggShell.findSubValueRef(valueRef, 'booleans,0'); + expect(nonExistantValueRef).toBeUndefined(); }); - it('throws for index out of bounds', function () { - var indexOutOfBounds = function () { - vireo.eggShell.findSubValueRef(valueRef, 'booleans.3'); - }; - - expect(indexOutOfBounds).toThrow(); + it('return undefined for index out of bounds', function () { + var nonExistantValueRef = vireo.eggShell.findSubValueRef(valueRef, 'booleans.3'); + expect(nonExistantValueRef).toBeUndefined(); }); it('finds values for fields followed by "." index', function () { diff --git a/test-it/karma/publicapi/FindValueRef.Test.js b/test-it/karma/publicapi/FindValueRef.Test.js index 217a920a6..c263be998 100644 --- a/test-it/karma/publicapi/FindValueRef.Test.js +++ b/test-it/karma/publicapi/FindValueRef.Test.js @@ -33,25 +33,19 @@ describe('The Vireo EggShell findValueRef api can', function () { expect(valueRef.dataRef).not.toBe(0); }); - it('to throw for a nonexistant vi name', function () { - var invalidViName = function () { - vireo.eggShell.findValueRef('nonexistantvi', pathName); - }; - expect(invalidViName).toThrowError(/ObjectNotFoundAtPath/); + it('to return undefined for a nonexistant vi name', function () { + var valueRef = vireo.eggShell.findValueRef('nonexistantvi', pathName); + expect(valueRef).toBeUndefined(); }); - it('to throw for an empty vi name', function () { - var invalidViName = function () { - vireo.eggShell.findValueRef('', pathName); - }; - expect(invalidViName).toThrowError(/ObjectNotFoundAtPath/); + it('to return undefined for an empty vi name', function () { + var valueRef = vireo.eggShell.findValueRef('', pathName); + expect(valueRef).toBeUndefined(); }); - it('to throw for a nonexistant path', function () { - var invalidPath = function () { - vireo.eggShell.findValueRef(viName, 'nonexistantvalue'); - }; - expect(invalidPath).toThrowError(/ObjectNotFoundAtPath/); + it('to return undefined for a nonexistant path', function () { + var valueRef = vireo.eggShell.findValueRef(viName, 'nonexistantvalue'); + expect(valueRef).toBeUndefined(); }); it('to return a typeRef for the the local scope of a VI for an empty path', function () { diff --git a/test-it/karma/publicapi/TypedArray.Test.js b/test-it/karma/publicapi/TypedArray.Test.js index 2fbd02e2f..cb9f270d8 100644 --- a/test-it/karma/publicapi/TypedArray.Test.js +++ b/test-it/karma/publicapi/TypedArray.Test.js @@ -107,9 +107,7 @@ describe('The Vireo EggShell Typed Array api', function () { readTypedArray('arrayString'); }).toThrowError(/UnexpectedObjectType/); - expect(function () { - readTypedArray('nonExistantPath'); - }).toThrowError(/ObjectNotFoundAtPath/); + expect(vireo.eggShell.findValueRef(viName, 'nonExistantPath')).toBeUndefined(); expect(function () { readTypedArray('scalarUInt32');