Chromium Code Reviews| 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 nativeDeepCopy = requireNative('utils').deepCopy; | 5 var nativeDeepCopy = requireNative('utils').deepCopy; |
| 6 var schemaRegistry = requireNative('schema_registry'); | 6 var schemaRegistry = requireNative('schema_registry'); |
| 7 var CHECK = requireNative('logging').CHECK; | 7 var CHECK = requireNative('logging').CHECK; |
| 8 var DCHECK = requireNative('logging').DCHECK; | 8 var DCHECK = requireNative('logging').DCHECK; |
| 9 var WARNING = requireNative('logging').WARNING; | 9 var WARNING = requireNative('logging').WARNING; |
| 10 var logActivity = requireNative('activityLogger'); | |
| 11 var exceptionHandler = require('uncaught_exception_handler'); | |
| 12 | |
| 13 var runCallbackWithLastError; | |
| 14 if (bindingUtil) { | |
| 15 runCallbackWithLastError = function(name, message, stack, callback, args) { | |
| 16 bindingUtil.runCallbackWithLastError(message, function() { | |
| 17 $Function.apply(callback, null, args); | |
| 18 }); | |
| 19 } | |
| 20 } else { | |
| 21 var lastError = require('lastError'); | |
| 22 if (lastError) // lastError can be undefined in unittests. | |
| 23 runCallbackWithLastError = lastError.run; | |
| 24 } | |
| 10 | 25 |
| 11 /** | 26 /** |
| 12 * An object forEach. Calls |f| with each (key, value) pair of |obj|, using | 27 * An object forEach. Calls |f| with each (key, value) pair of |obj|, using |
| 13 * |self| as the target. | 28 * |self| as the target. |
| 14 * @param {Object} obj The object to iterate over. | 29 * @param {Object} obj The object to iterate over. |
| 15 * @param {function} f The function to call in each iteration. | 30 * @param {function} f The function to call in each iteration. |
| 16 * @param {Object} self The object to use as |this| in each function call. | 31 * @param {Object} self The object to use as |this| in each function call. |
| 17 */ | 32 */ |
| 18 function forEach(obj, f, self) { | 33 function forEach(obj, f, self) { |
| 19 for (var key in obj) { | 34 for (var key in obj) { |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 } | 237 } |
| 223 if (arguments.length <= 1) | 238 if (arguments.length <= 1) |
| 224 resolve(arguments[0]); | 239 resolve(arguments[0]); |
| 225 else | 240 else |
| 226 resolve($Array.slice(arguments)); | 241 resolve($Array.slice(arguments)); |
| 227 }); | 242 }); |
| 228 $Function.apply(func, null, args); | 243 $Function.apply(func, null, args); |
| 229 }); | 244 }); |
| 230 } | 245 } |
| 231 | 246 |
| 247 function handleRequestWithPromise( | |
| 248 binding, methodName, apiName, customizedFunction) { | |
|
lazyboy
2017/06/29 00:05:00
nit: apiName before methodName (feels odd otherwis
Devlin
2017/06/29 18:21:26
Fair point; done.
| |
| 249 var fullName = apiName + '.' + methodName; | |
| 250 var extensionId = requireNative('process').GetExtensionId(); | |
| 251 binding.setHandleRequest(methodName, function() { | |
| 252 logActivity.LogAPICall(extensionId, fullName, $Array.slice(arguments)); | |
| 253 var stack = exceptionHandler.getExtensionStackTrace(); | |
| 254 var callback = arguments[arguments.length - 1]; | |
| 255 var args = $Array.slice(arguments, 0, arguments.length - 1); | |
| 256 var keepAlivePromise = requireAsync('keep_alive').then(function(module) { | |
|
jbroman
2017/06/22 17:31:43
FYI: since you're using $Array.slice, $Function.ap
Devlin
2017/06/22 18:43:19
... Yuck :( Good catch.
Ideally, I'd rather just
| |
| 257 return module.createKeepAlive(); | |
| 258 }); | |
| 259 $Function.apply(customizedFunction, this, args).then(function(result) { | |
| 260 if (callback) { | |
| 261 exceptionHandler.safeCallbackApply( | |
| 262 fullName, {__proto__: null, stack: stack}, callback, [result]); | |
| 263 } | |
| 264 }).catch(function(error) { | |
| 265 if (callback) { | |
| 266 var message = exceptionHandler.safeErrorToString(error, true); | |
| 267 runCallbackWithLastError(fullName, message, stack, callback); | |
| 268 } | |
| 269 }).then(function() { | |
| 270 keepAlivePromise.then(function(keepAlive) { | |
| 271 keepAlive.close(); | |
| 272 }); | |
| 273 }); | |
| 274 }); | |
| 275 }; | |
| 276 | |
| 232 exports.$set('forEach', forEach); | 277 exports.$set('forEach', forEach); |
| 233 exports.$set('loadTypeSchema', loadTypeSchema); | 278 exports.$set('loadTypeSchema', loadTypeSchema); |
| 234 exports.$set('lookup', lookup); | 279 exports.$set('lookup', lookup); |
| 235 exports.$set('defineProperty', defineProperty); | 280 exports.$set('defineProperty', defineProperty); |
| 236 exports.$set('expose', expose); | 281 exports.$set('expose', expose); |
| 237 exports.$set('deepCopy', deepCopy); | 282 exports.$set('deepCopy', deepCopy); |
| 238 exports.$set('promise', promise); | 283 exports.$set('promise', promise); |
| 284 exports.$set('handleRequestWithPromise', handleRequestWithPromise); | |
| OLD | NEW |