| 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 DCHECK = requireNative('logging').DCHECK; | 6 var DCHECK = requireNative('logging').DCHECK; |
| 7 var WARNING = requireNative('logging').WARNING; |
| 8 var logActivity = requireNative('activityLogger'); |
| 9 var exceptionHandler = require('uncaught_exception_handler'); |
| 10 |
| 11 var runCallbackWithLastError; |
| 12 if (bindingUtil) { |
| 13 runCallbackWithLastError = function(name, message, stack, callback, args) { |
| 14 bindingUtil.runCallbackWithLastError(message, function() { |
| 15 $Function.apply(callback, null, args); |
| 16 }); |
| 17 } |
| 18 } else { |
| 19 var lastError = require('lastError'); |
| 20 if (lastError) // lastError can be undefined in unittests. |
| 21 runCallbackWithLastError = lastError.run; |
| 22 } |
| 7 | 23 |
| 8 /** | 24 /** |
| 9 * An object forEach. Calls |f| with each (key, value) pair of |obj|, using | 25 * An object forEach. Calls |f| with each (key, value) pair of |obj|, using |
| 10 * |self| as the target. | 26 * |self| as the target. |
| 11 * @param {Object} obj The object to iterate over. | 27 * @param {Object} obj The object to iterate over. |
| 12 * @param {function} f The function to call in each iteration. | 28 * @param {function} f The function to call in each iteration. |
| 13 * @param {Object} self The object to use as |this| in each function call. | 29 * @param {Object} self The object to use as |this| in each function call. |
| 14 */ | 30 */ |
| 15 function forEach(obj, f, self) { | 31 function forEach(obj, f, self) { |
| 16 for (var key in obj) { | 32 for (var key in obj) { |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 } | 215 } |
| 200 if (arguments.length <= 1) | 216 if (arguments.length <= 1) |
| 201 resolve(arguments[0]); | 217 resolve(arguments[0]); |
| 202 else | 218 else |
| 203 resolve($Array.slice(arguments)); | 219 resolve($Array.slice(arguments)); |
| 204 }); | 220 }); |
| 205 $Function.apply(func, null, args); | 221 $Function.apply(func, null, args); |
| 206 }); | 222 }); |
| 207 } | 223 } |
| 208 | 224 |
| 225 // DO NOT USE. This causes problems with safe builtins, and makes migration to |
| 226 // native bindings more difficult. |
| 227 function handleRequestWithPromiseDoNotUse( |
| 228 binding, apiName, methodName, customizedFunction) { |
| 229 var fullName = apiName + '.' + methodName; |
| 230 var extensionId = requireNative('process').GetExtensionId(); |
| 231 binding.setHandleRequest(methodName, function() { |
| 232 logActivity.LogAPICall(extensionId, fullName, $Array.slice(arguments)); |
| 233 var stack = exceptionHandler.getExtensionStackTrace(); |
| 234 var callback = arguments[arguments.length - 1]; |
| 235 var args = $Array.slice(arguments, 0, arguments.length - 1); |
| 236 var keepAlivePromise = requireAsync('keep_alive').then(function(module) { |
| 237 return module.createKeepAlive(); |
| 238 }); |
| 239 $Function.apply(customizedFunction, this, args).then(function(result) { |
| 240 if (callback) { |
| 241 exceptionHandler.safeCallbackApply( |
| 242 fullName, {__proto__: null, stack: stack}, callback, [result]); |
| 243 } |
| 244 }).catch(function(error) { |
| 245 if (callback) { |
| 246 var message = exceptionHandler.safeErrorToString(error, true); |
| 247 runCallbackWithLastError(fullName, message, stack, callback); |
| 248 } |
| 249 }).then(function() { |
| 250 keepAlivePromise.then(function(keepAlive) { |
| 251 keepAlive.close(); |
| 252 }); |
| 253 }); |
| 254 }); |
| 255 }; |
| 256 |
| 209 exports.$set('forEach', forEach); | 257 exports.$set('forEach', forEach); |
| 210 exports.$set('lookup', lookup); | 258 exports.$set('lookup', lookup); |
| 211 exports.$set('defineProperty', defineProperty); | 259 exports.$set('defineProperty', defineProperty); |
| 212 exports.$set('expose', expose); | 260 exports.$set('expose', expose); |
| 213 exports.$set('deepCopy', deepCopy); | 261 exports.$set('deepCopy', deepCopy); |
| 214 exports.$set('promise', promise); | 262 exports.$set('promise', promise); |
| 263 exports.$set('handleRequestWithPromiseDoNotUse', |
| 264 handleRequestWithPromiseDoNotUse); |
| OLD | NEW |