On Tue, Jun 9, 2009 at 9:58 AM, disya2<[email protected]> wrote: > > Aaron, > Thanks for your replay. I have a few more questions. > >> The reason it doesn't work is because the Chrome APIs are >> asynchronous. > I suspected this :) after adding setTimeout(console.log(win_id), 100); > but was not sure if this was a bug or by design.
Alas, it is by-design. > Now questions: > 1. Let's assume that something throws an exception while callback > function run. What happens if it wasn't catch in callback? Is there a > chance to set somewhere 'big' try-catch block which could handle that? There are several answers to this question: a) All errors in JavaScript anywhere (callback or not) get reported to the console inside the web inspector. If you just want to know about errors (for debugging) this is the way to do it, you don't need to catch them. Normally, you can access the console for an extension by navigation the chrome://extensions and clicking "inspect" for the view you're interested in. But in the current dev release, the inspector is busted. The next dev release will fix this though. b) If you really do want to catch errors, for example to report them to your server, the usual way to do this is with window.onerror (https://developer.mozilla.org/en/DOM/window.onerror). However, I do not think that WebKit (the rendering engine that Chrome uses) supports this for runtime JS errors yet. c) A way to get an effect similar to window.onerror is to wrap all your event handlers and callbacks in error handling manually. You can generate functions that wrap a function in error handling, like this: // (untested!) function errorHandledFunction(fn) { return function() { try { fn.apply(null, Array.prototype.splice.call(arguments, 1)); } catch (e) { // do something with e } } } chrome.tabs.create({url:"http://www.google.com/"}, errorHandledFunction(function() { ... })); > 2. I need a kind of sleep() function. I'm porting Firefox add-on where > I use generator-iterator feature and (earlier) JS debugger API to > accomplish that. Is it planned to add something like that? I would > vote for generator-iterator feature (like described in > https://developer.mozilla.org/en/New_in_JavaScript_1.7) if someone > asks me. I don't expect something like this to be added to Chrome unless it gets added to the ECMAScript standard. I don't think that is planned anytime soon. Perhaps there is another way to get what you're after? What are you using it for? > 3. A dumb question - what would be 'this' in callback function? What > is the execution context for callback, the same as for caller? Do the > caller and callback have the same global object? I suspect the answer > would be "yes" for the last two questions, just to make sure. The 'this' object in chrome callbacks is the global object. If you want some other 'this' object, you need to use a function like bind() to set it. > 4. Is there a date for localStorage to appear? Drop-down menu for > toolstrips? I really need these two to make the extension somewhat > useful. Also I need file access for extension script, is it planned? No, there's no date. We expect localStorage to appear sooner than dropdowns though, unless somebody offers to help with dropdowns. > Denis > P.S. I believed I was experienced JS programmer :) Ok, sorry if I'm giving you info you already know. Sometimes it's hard to tell where people are at -- I give a bunch of information so that I can refer to it in the future when somebody asks the same thing :). - a --~--~---------~--~----~------------~-------~--~----~ Chromium Discussion mailing list: [email protected] View archives, change email options, or unsubscribe: http://groups.google.com/group/chromium-discuss -~----------~----~----~----~------~----~------~--~---
