| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var exceptionHandler = require('uncaught_exception_handler'); |
| 5 var eventNatives = requireNative('event_natives'); | 6 var eventNatives = requireNative('event_natives'); |
| 6 var handleUncaughtException = require('uncaught_exception_handler').handle; | |
| 7 var logging = requireNative('logging'); | 7 var logging = requireNative('logging'); |
| 8 var schemaRegistry = requireNative('schema_registry'); | 8 var schemaRegistry = requireNative('schema_registry'); |
| 9 var sendRequest = require('sendRequest').sendRequest; | 9 var sendRequest = require('sendRequest').sendRequest; |
| 10 var utils = require('utils'); | 10 var utils = require('utils'); |
| 11 var validate = require('schemaUtils').validate; | 11 var validate = require('schemaUtils').validate; |
| 12 var unloadEvent = require('unload_event'); | 12 var unloadEvent = require('unload_event'); |
| 13 | 13 |
| 14 // Schemas for the rule-style functions on the events API that | 14 // Schemas for the rule-style functions on the events API that |
| 15 // only need to be generated occasionally, so populate them lazily. | 15 // only need to be generated occasionally, so populate them lazily. |
| 16 var ruleFunctionSchemas = { | 16 var ruleFunctionSchemas = { |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 this.attachmentStrategy.getListenersByIDs(listenerIDs)); | 374 this.attachmentStrategy.getListenersByIDs(listenerIDs)); |
| 375 | 375 |
| 376 var results = []; | 376 var results = []; |
| 377 for (var i = 0; i < listeners.length; i++) { | 377 for (var i = 0; i < listeners.length; i++) { |
| 378 try { | 378 try { |
| 379 var result = this.wrapper.dispatchToListener(listeners[i].callback, | 379 var result = this.wrapper.dispatchToListener(listeners[i].callback, |
| 380 args); | 380 args); |
| 381 if (result !== undefined) | 381 if (result !== undefined) |
| 382 $Array.push(results, result); | 382 $Array.push(results, result); |
| 383 } catch (e) { | 383 } catch (e) { |
| 384 handleUncaughtException( | 384 exceptionHandler.handle('Error in event handler for ' + |
| 385 'Error in event handler for ' + | 385 (this.eventName ? this.eventName : '(unknown)'), |
| 386 (this.eventName ? this.eventName : '(unknown)') + | |
| 387 ': ' + e.message + '\nStack trace: ' + e.stack, | |
| 388 e); | 386 e); |
| 389 } | 387 } |
| 390 } | 388 } |
| 391 if (results.length) | 389 if (results.length) |
| 392 return {results: results}; | 390 return {results: results}; |
| 393 } | 391 } |
| 394 | 392 |
| 395 // Can be overridden to support custom dispatching. | 393 // Can be overridden to support custom dispatching. |
| 396 EventImpl.prototype.dispatchToListener = function(callback, args) { | 394 EventImpl.prototype.dispatchToListener = function(callback, args) { |
| 397 return $Function.apply(callback, null, args); | 395 return $Function.apply(callback, null, args); |
| 398 } | 396 } |
| 399 | 397 |
| 400 // Dispatches this event object to all listeners, passing all supplied | 398 // Dispatches this event object to all listeners, passing all supplied |
| 401 // arguments to this function each listener. | 399 // arguments to this function each listener. |
| 402 EventImpl.prototype.dispatch = function(varargs) { | 400 EventImpl.prototype.dispatch = function(varargs) { |
| 403 return this.dispatch_($Array.slice(arguments), undefined); | 401 return this.dispatch_($Array.slice(arguments), undefined); |
| 404 }; | 402 }; |
| 405 | 403 |
| 406 // Detaches this event object from its name. | 404 // Detaches this event object from its name. |
| 407 EventImpl.prototype.detach_ = function() { | 405 EventImpl.prototype.detach_ = function() { |
| 408 this.attachmentStrategy.detach(false); | 406 this.attachmentStrategy.detach(false); |
| 409 }; | 407 }; |
| 410 | 408 |
| 411 EventImpl.prototype.destroy_ = function() { | 409 EventImpl.prototype.destroy_ = function() { |
| 412 this.listeners.length = 0; | 410 this.listeners.length = 0; |
| 413 this.detach_(); | 411 this.detach_(); |
| 414 this.destroyed = new Error().stack; | 412 this.destroyed = exceptionHandler.getStackTrace(); |
| 415 }; | 413 }; |
| 416 | 414 |
| 417 EventImpl.prototype.addRules = function(rules, opt_cb) { | 415 EventImpl.prototype.addRules = function(rules, opt_cb) { |
| 418 if (!this.eventOptions.supportsRules) | 416 if (!this.eventOptions.supportsRules) |
| 419 throw new Error("This event does not support rules."); | 417 throw new Error("This event does not support rules."); |
| 420 | 418 |
| 421 // Takes a list of JSON datatype identifiers and returns a schema fragment | 419 // Takes a list of JSON datatype identifiers and returns a schema fragment |
| 422 // that verifies that a JSON object corresponds to an array of only these | 420 // that verifies that a JSON object corresponds to an array of only these |
| 423 // data types. | 421 // data types. |
| 424 function buildArrayOfChoicesSchema(typesList) { | 422 function buildArrayOfChoicesSchema(typesList) { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 'removeRules', | 517 'removeRules', |
| 520 'getRules' | 518 'getRules' |
| 521 ] }); | 519 ] }); |
| 522 | 520 |
| 523 // NOTE: Event is (lazily) exposed as chrome.Event from dispatcher.cc. | 521 // NOTE: Event is (lazily) exposed as chrome.Event from dispatcher.cc. |
| 524 exports.Event = Event; | 522 exports.Event = Event; |
| 525 | 523 |
| 526 exports.dispatchEvent = dispatchEvent; | 524 exports.dispatchEvent = dispatchEvent; |
| 527 exports.parseEventOptions = parseEventOptions; | 525 exports.parseEventOptions = parseEventOptions; |
| 528 exports.registerArgumentMassager = registerArgumentMassager; | 526 exports.registerArgumentMassager = registerArgumentMassager; |
| OLD | NEW |