Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'jb53914' into 'master'
[embedlite-components] Stringify none primitive types for runJavaScript. JB#53914 OMP#JOLLA-29

See merge request mer-core/embedlite-components!125
  • Loading branch information
rainemak committed Apr 27, 2021
2 parents 7f0a1d5 + c9a6d82 commit 7b5983e
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions jsscripts/embedhelper.js
Expand Up @@ -381,16 +381,36 @@ EmbedHelper.prototype = {
let promise = new Promise(function(resolve, reject) {
try {
let f = new content.Function(jsstring);
let result = f();
resolve(result);
let resultObject = {
stringified: false,
result: undefined
}
resultObject.result = f();
if (typeof resultObject.result === "function") {
reject("Error: cannot return a function.")
} else if (typeof resultObject.result === "symbol") {
// Special handling for Symbol type
resultObject.result = resultObject.result.toString()
resolve(resultObject);
} else if (typeof resultObject.result === "boolean"
|| typeof resultObject.result === "undefined"
|| typeof resultObject.result === "number"
|| typeof resultObject.result === "string") {
resolve(resultObject);
} else {
resultObject.result = JSON.stringify(resultObject.result);
resultObject.stringified = true;
resolve(resultObject);
}
} catch (e) {
reject(e.toString());
}
}).then(result => {
}).then(resultObject => {
if (callbackId >= 0) {
let error
sendAsyncMessage("embed:runjavascript", {
"result": result,
"result": resultObject.result,
"stringified": resultObject.stringified,
"error": error,
"callbackId": callbackId
});
Expand All @@ -400,6 +420,7 @@ EmbedHelper.prototype = {
let result
sendAsyncMessage("embed:runjavascript", {
"result": result,
"stringified": false,
"error": error,
"callbackId": callbackId
});
Expand Down

0 comments on commit 7b5983e

Please sign in to comment.