From 8d2260e6585977d31456772d59c1a58fa593681d Mon Sep 17 00:00:00 2001 From: Boxiao Cao Date: Thu, 4 Mar 2021 19:50:38 +0000 Subject: [PATCH] Add wasm initialization call in nodejs --- validator/js/nodejs/index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/validator/js/nodejs/index.js b/validator/js/nodejs/index.js index 6d1c1e33bb90..f23b5905e652 100755 --- a/validator/js/nodejs/index.js +++ b/validator/js/nodejs/index.js @@ -243,6 +243,18 @@ function Validator(scriptContents) { } } +/** + * Initialize the validator. + * @return {Promise!} + */ +Validator.prototype.init = function() { + if (this.sandbox.amp.validator.init) { + return this.sandbox.amp.validator.init(); + } else { + return Promise.resolve(undefined); + } +} + /** * Validates the provided inputString; the htmlFormat can be 'AMP' or * 'AMP4ADS'; it defaults to 'AMP' if not specified. @@ -440,6 +452,9 @@ function main() { } } getInstance(program.validator_js, program.userAgent) + .then(function(validator) { + return validator.init().then(() => validator); + }) .then(function(validator) { Promise.all(inputs) .then(function(resolvedInputs) {