Skip to content

Commit adfd4ac

Browse files
authored
Fixed issue scijs#38 - Validate input for get method (and others potentially)
1 parent 58f5d8c commit adfd4ac

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ndarray.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,19 @@ return [0,2,1];\
145145
//view.set(i0, ..., v):
146146
code.push(
147147
"proto.set=function "+className+"_set("+args.join(",")+",v){")
148-
if(useGetters) {
148+
if (index_str === +index_str && index_str === (index_str|0)) { // https://stackoverflow.com/a/3885844/4915882
149+
code.push("throw 'set parameter should be integer'")
150+
} else if(useGetters) {
149151
code.push("return this.data.set("+index_str+",v)}")
150152
} else {
151153
code.push("return this.data["+index_str+"]=v}")
152154
}
153155

154156
//view.get(i0, ...):
155157
code.push("proto.get=function "+className+"_get("+args.join(",")+"){")
156-
if(useGetters) {
158+
if (index_str === +index_str && index_str === (index_str|0)) { // https://stackoverflow.com/a/3885844/4915882
159+
code.push("throw 'get parameter should be integer'")
160+
} else if (useGetters) {
157161
code.push("return this.data.get("+index_str+")}")
158162
} else {
159163
code.push("return this.data["+index_str+"]}")

0 commit comments

Comments
 (0)