You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I encountered the following error when using protobuf 6.11.3 for file codec, indicating that eval and new Function()/Function() are not supported. How can I avoid this problem?
protobuf.load(path,function(err,root){if(err){console.info('-----------------------awesome: '+err)throwerr;}// Obtain a message typevarAwesomeMessage=root.lookupType("awesomepackage.AwesomeMessage");// Exemplary payloadvarpayload={awesomeField: "AwesomeString"};// Verify the payload if necessary (i.e. when possibly incomplete or invalid)varerrMsg=AwesomeMessage.verify(payload);if(errMsg){console.info('-----------------------errMsg: '+errMsg)throwError(errMsg);}// Create a new messagevarmessage=AwesomeMessage.create(payload);// or use .fromObject if conversion is necessary// Encode a message to an Uint8Array (browser) or Buffer (node)varbuffer=AwesomeMessage.encode(message).finish();console.info('-----------------------encode message: '+newUint8Array(buffer))// ... do something with buffer// Decode an Uint8Array (browser) or Buffer (node) to a messagevarmessage=AwesomeMessage.decode(buffer);console.info('-----------------------decode message: '+JSON.stringify(message))// ... do something with message// If the application uses length-delimited buffers, there is also encodeDelimited and decodeDelimited.// Maybe convert the message back to a plain objectvarobject=AwesomeMessage.toObject(message,{longs: String,enums: String,bytes: String,// see ConversionOptions});
Type.generateConstructor=functiongenerateConstructor(mtype){/* eslint-disable no-unexpected-multiline */vargen=util.codegen(["p"],mtype.name);// explicitly initialize mutable object/array fields so that these aren't just inherited from the prototypefor(vari=0,field;i<mtype.fieldsArray.length;++i)if((field=mtype._fieldsArray[i]).map)gen("this%s={}",util.safeProp(field.name));elseif(field.repeated)gen("this%s=[]",util.safeProp(field.name));returngen("if(p)for(var ks=Object.keys(p),i=0;i<ks.length;++i)if(p[ks[i]]!=null)")// omit undefined or null("this[ks[i]]=p[ks[i]]");/* eslint-enable no-unexpected-multiline */};functionCodegen(formatStringOrScope){// note that explicit array handling below makes this ~50% faster// finish the functionif(typeofformatStringOrScope!=="string"){varsource=toString();if(codegen.verbose)console.log("codegen: "+source);// eslint-disable-line no-consolesource="return "+source;if(formatStringOrScope){varscopeKeys=Object.keys(formatStringOrScope),scopeParams=newArray(scopeKeys.length+1),scopeValues=newArray(scopeKeys.length),scopeOffset=0;while(scopeOffset<scopeKeys.length){scopeParams[scopeOffset]=scopeKeys[scopeOffset];scopeValues[scopeOffset]=formatStringOrScope[scopeKeys[scopeOffset++]];}scopeParams[scopeOffset]=source;returnFunction.apply(null,scopeParams).apply(null,scopeValues);// eslint-disable-line no-new-func}returnFunction(source)();// eslint-disable-line no-new-func}// otherwise append to bodyvarformatParams=newArray(arguments.length-1),formatOffset=0;while(formatOffset<formatParams.length)formatParams[formatOffset]=arguments[++formatOffset];formatOffset=0;formatStringOrScope=formatStringOrScope.replace(/%([%dfijs])/g,functionreplace($0,$1){varvalue=formatParams[formatOffset++];switch($1){case"d": case"f": returnString(Number(value));case"i": returnString(Math.floor(value));case"j": returnJSON.stringify(value);case"s": returnString(value);}return"%";});if(formatOffset!==formatParams.length)throwError("parameter count mismatch");body.push(formatStringOrScope);returnCodegen;}
stack info:
page: pages/Index.js
Error message: Not support eval. Forbidden using new Function()/Function().
SourceCode:
return Function(source)(); // eslint-disable-line no-new-func
^
Stacktrace:
at Codegen (entry/oh_modules/.ohpm/@[email protected]/oh_modules/@protobufjs/codegen/index.js:51:14)
at get (entry/oh_modules/.ohpm/[email protected]/oh_modules/protobufjs/src/type.js:145:41)
at resolve (entry/oh_modules/.ohpm/[email protected]/oh_modules/protobufjs/src/field.js:281:7)
at encoder (entry/oh_modules/.ohpm/[email protected]/oh_modules/protobufjs/src/encoder.js:34:17)
at setup (entry/oh_modules/.ohpm/[email protected]/oh_modules/protobufjs/src/type.js:380:17)
at verify_setup (entry/oh_modules/.ohpm/[email protected]/oh_modules/protobufjs/src/type.js:470:10)
at anonymous (entry/src/main/ets/pages/Index.ets:102:34)
at finish (entry/oh_modules/.ohpm/[email protected]/oh_modules/protobufjs/src/root.js:100:5)
at process (entry/oh_modules/.ohpm/[email protected]/oh_modules/protobufjs/src/root.js:128:27)
at anonymous (entry/oh_modules/.ohpm/[email protected]/oh_modules/protobufjs/src/root.js:173:9)
at anonymous (entry/src/main/ets/pages/Index.ets:22:12)
at fetch (entry/oh_modules/.ohpm/@[email protected]/oh_modules/@protobufjs/fetch/index.js:46:10)
at fetch (entry/oh_modules/.ohpm/[email protected]/oh_modules/protobufjs/src/root.js:161:7)
at load (entry/oh_modules/.ohpm/[email protected]/oh_modules/protobufjs/src/root.js:182:105)
at load (entry/oh_modules/.ohpm/[email protected]/oh_modules/protobufjs/src/index-light.js:28:10)
at anonymous (entry/src/main/ets/pages/Index.ets:92:17)
The text was updated successfully, but these errors were encountered:
Same here. I've been using electron's cast library which uses protobuf as a dependency. Some security changes have stopped it from working due to no-new-func. It's kind of bad practice to use eval (as noted by the lint message).
protobuf.js version: <6.11.3>
Hello, I encountered the following error when using protobuf 6.11.3 for file codec, indicating that eval and new Function()/Function() are not supported. How can I avoid this problem?
stack info:
The text was updated successfully, but these errors were encountered: