Skip to content

Commit a538788

Browse files
committed
fix(core): the optional value extract index & validate index
1 parent 167972f commit a538788

3 files changed

Lines changed: 766 additions & 118 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "talib-binding",
33
"main": "./build/Release/talib_binding.node",
44
"types": "./src/talib-binding.generated.d.ts",
5-
"version": "0.1.0",
5+
"version": "0.1.1",
66
"license": "MIT",
77
"scripts": {
88
"install": "cd ta-lib && cmake ./ && make -j4 && cd .. && node-gyp configure build -j4"

src/generate.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ export function generateBindings() {
247247
.normal('return;')
248248
.undent('}')
249249
const config: TaFuncApiXml = require('./ta_func_api.generated.json')
250-
config.FinancialFunctions.FinancialFunction.filter((func) => !!func).forEach((func) => {
250+
config.FinancialFunctions.FinancialFunction.filter((func) => func.Abbreviation[0] === 'SAR' || 1).forEach((func) => {
251251
const name = func.Abbreviation[0]
252252
const required: RequiredInputArgument[] = func.RequiredInputArguments
253253
? func.RequiredInputArguments.reduce((prev, curr) => {
@@ -347,7 +347,7 @@ export function generateBindings() {
347347
}))
348348
.undent('}')
349349
.normal(...optional.map((argv, index) => {
350-
index += required.length
350+
index += 1 + doubleRequired.length
351351
const type = optType(argv)
352352
const check = type === 'double' ? 'Number' : 'Int32'
353353
const cast = type === 'TA_MAType' ? '(TA_MAType) ' : ''
@@ -359,6 +359,10 @@ export function generateBindings() {
359359
return `${name} = argc > ${index} && info[${index}]->IsInt32() ? info[${index}]->Int32Value() : ${name};`
360360
}))
361361
.undent('}')
362+
.normal('if (startIdx < 0 || endIdx >= inLength || startIdx > endIdx) {')
363+
.indent('Nan::ThrowRangeError("`startIdx` or `endIdx` out of range");')
364+
.normal('return;')
365+
.undent('}')
362366
.normal(`int lookback = TA_${name}_Lookback(${optional.map((argv) => optName(argv)).join(', ')});`)
363367
.normal('int temp = lookback > startIdx ? lookback : startIdx;')
364368
.normal('outLength = temp > endIdx ? 0 : endIdx - temp + 1;')

0 commit comments

Comments
 (0)