「chrome.storage.local」を利用するクロム拡張機能を開発しており、例外をスローできるようにしたい chrome.storage.local.get() 非同期関数からプロミスを作成しようとしています。拒否/解決します。以下の実装でこれをテストしようとしましたが、コンソール ログから " " 行からのものと思われるreadLocalStorageObj("prefs").then(function(item) {
エラーが表示されます (エラーはコードの後に示されています)。
require([
"libs/bluebird"
],
function(Promise) {
function readLocalStorageObj(itemName) {
var localReadResult = Promise.method(function(item) {
console.log("localReadResult():", item);
// if (chrome.runtime.lastError) {
// throw new Error(chrome.runtime.lastError);
// }
if (Object.getOwnPropertyNames(item).length > 0) {
console.log('in if part');
return item;
}
else {
console.log('in else part');
// throw new Error("my test exception");
return undefined;
}
});
chrome.storage.local.get(itemName, localReadResult);
return localReadResult;
};
readLocalStorageObj("prefs").then(function(item) {
console.log('success', item);
}, function(e) {
console.log('fail', e);
}).error(function(e) {
console.log('error', e);
}).catch(ChromeRuntimeError, function(e) {
console.log('catch', e);
}).finally(function(a) {
console.log('finally', a);
});
});
エラー:
キャッチされていない TypeError: オブジェクト関数 Promise$_method() { var value; switch(arguments.length) { ケース 0: 値 = tryCatch1(fn, this, void 0); 壊す; ケース 1: 値 = tryCatch1(fn, this, 引数[0]); 壊す; 場合......n'
私はこれの原因が何であるかを理解できないようです.これについて何か助けていただければ幸いです.
ティア