Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: Source/devtools/front_end/RemoteObject.js

Issue 83383002: DevTools: Allow setting -0 value to object property (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 * @param {string} value 244 * @param {string} value
245 * @param {function(string=)} callback 245 * @param {function(string=)} callback
246 */ 246 */
247 setPropertyValue: function(name, value, callback) 247 setPropertyValue: function(name, value, callback)
248 { 248 {
249 if (!this._objectId) { 249 if (!this._objectId) {
250 callback("Can't set a property of non-object."); 250 callback("Can't set a property of non-object.");
251 return; 251 return;
252 } 252 }
253 253
254 RuntimeAgent.evaluate.invoke({expression:value, doNotPauseOnExceptionsAn dMuteConsole:true}, evaluatedCallback.bind(this)); 254 RuntimeAgent.evaluate.invoke({expression: value, doNotPauseOnExceptionsA ndMuteConsole: true, forceObjectId: true}, evaluatedCallback.bind(this));
255 255
256 /** 256 /**
257 * @param {?Protocol.Error} error 257 * @param {?Protocol.Error} error
258 * @param {RuntimeAgent.RemoteObject} result 258 * @param {RuntimeAgent.RemoteObject} result
259 * @param {boolean=} wasThrown 259 * @param {boolean=} wasThrown
260 */ 260 */
261 function evaluatedCallback(error, result, wasThrown) 261 function evaluatedCallback(error, result, wasThrown)
262 { 262 {
263 if (error || wasThrown) { 263 if (error || wasThrown) {
264 callback(error || result.description); 264 callback(error || result.description);
(...skipping 13 matching lines...) Expand all
278 * @param {function(string=)} callback 278 * @param {function(string=)} callback
279 */ 279 */
280 doSetObjectPropertyValue: function(result, name, callback) 280 doSetObjectPropertyValue: function(result, name, callback)
281 { 281 {
282 // This assignment may be for a regular (data) property, and for an accc essor property (with getter/setter). 282 // This assignment may be for a regular (data) property, and for an accc essor property (with getter/setter).
283 // Note the sensitive matter about accessor property: the property may b e physically defined in some proto object, 283 // Note the sensitive matter about accessor property: the property may b e physically defined in some proto object,
284 // but logically it is bound to the object in question. JavaScript passe s this object to getters/setters, not the object 284 // but logically it is bound to the object in question. JavaScript passe s this object to getters/setters, not the object
285 // where property was defined; so do we. 285 // where property was defined; so do we.
286 var setPropertyValueFunction = "function(a, b) { this[a] = b; }"; 286 var setPropertyValueFunction = "function(a, b) { this[a] = b; }";
287 287
288 // Special case for NaN, Infinity and -Infinity
289 if (result.type === "number" && typeof result.value !== "number")
290 setPropertyValueFunction = "function(a) { this[a] = " + result.descr iption + "; }";
291
292 delete result.description; // Optimize on traffic. 288 delete result.description; // Optimize on traffic.
293 RuntimeAgent.callFunctionOn(this._objectId, setPropertyValueFunction, [{ value:name }, result], true, undefined, undefined, propertySetCallback.bind(thi s)); 289 RuntimeAgent.callFunctionOn(this._objectId, setPropertyValueFunction, [{ value: name }, result], true, undefined, undefined, undefined, propertySetCallb ack.bind(this));
294 290
295 /** 291 /**
296 * @param {?Protocol.Error} error 292 * @param {?Protocol.Error} error
297 * @param {RuntimeAgent.RemoteObject} result 293 * @param {RuntimeAgent.RemoteObject} result
298 * @param {boolean=} wasThrown 294 * @param {boolean=} wasThrown
299 */ 295 */
300 function propertySetCallback(error, result, wasThrown) 296 function propertySetCallback(error, result, wasThrown)
301 { 297 {
302 if (error || wasThrown) { 298 if (error || wasThrown) {
303 callback(error || result.description); 299 callback(error || result.description);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 function mycallback(error, result, wasThrown) 339 function mycallback(error, result, wasThrown)
344 { 340 {
345 if (!callback) 341 if (!callback)
346 return; 342 return;
347 if (error) 343 if (error)
348 callback(null, false); 344 callback(null, false);
349 else 345 else
350 callback(WebInspector.RemoteObject.fromPayload(result), wasThrow n); 346 callback(WebInspector.RemoteObject.fromPayload(result), wasThrow n);
351 } 347 }
352 348
353 RuntimeAgent.callFunctionOn(this._objectId, functionDeclaration.toString (), args, true, undefined, undefined, mycallback); 349 RuntimeAgent.callFunctionOn(this._objectId, functionDeclaration.toString (), args, true, undefined, undefined, undefined, mycallback);
354 }, 350 },
355 351
356 /** 352 /**
357 * @param {function(this:Object)} functionDeclaration 353 * @param {function(this:Object)} functionDeclaration
358 * @param {Array.<RuntimeAgent.CallArgument>|undefined} args 354 * @param {Array.<RuntimeAgent.CallArgument>|undefined} args
359 * @param {function(*)} callback 355 * @param {function(*)} callback
360 */ 356 */
361 callFunctionJSON: function(functionDeclaration, args, callback) 357 callFunctionJSON: function(functionDeclaration, args, callback)
362 { 358 {
363 /** 359 /**
364 * @param {?Protocol.Error} error 360 * @param {?Protocol.Error} error
365 * @param {RuntimeAgent.RemoteObject} result 361 * @param {RuntimeAgent.RemoteObject} result
366 * @param {boolean=} wasThrown 362 * @param {boolean=} wasThrown
367 */ 363 */
368 function mycallback(error, result, wasThrown) 364 function mycallback(error, result, wasThrown)
369 { 365 {
370 callback((error || wasThrown) ? null : result.value); 366 callback((error || wasThrown) ? null : result.value);
371 } 367 }
372 368
373 RuntimeAgent.callFunctionOn(this._objectId, functionDeclaration.toString (), args, true, true, false, mycallback); 369 RuntimeAgent.callFunctionOn(this._objectId, functionDeclaration.toString (), args, true, true, false, false, mycallback);
374 }, 370 },
375 371
376 release: function() 372 release: function()
377 { 373 {
378 if (!this._objectId) 374 if (!this._objectId)
379 return; 375 return;
380 RuntimeAgent.releaseObject(this._objectId); 376 RuntimeAgent.releaseObject(this._objectId);
381 }, 377 },
382 378
383 /** 379 /**
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 }, 527 },
532 528
533 /** 529 /**
534 * @override 530 * @override
535 * @param {RuntimeAgent.RemoteObject} result 531 * @param {RuntimeAgent.RemoteObject} result
536 * @param {string} name 532 * @param {string} name
537 * @param {function(string=)} callback 533 * @param {function(string=)} callback
538 */ 534 */
539 doSetObjectPropertyValue: function(result, name, callback) 535 doSetObjectPropertyValue: function(result, name, callback)
540 { 536 {
541 var newValue; 537 var newValue = { objectId: result.objectId, value: result.value };
542
543 switch (result.type) {
544 case "undefined":
545 newValue = {};
546 break;
547 case "object":
548 case "function":
549 newValue = { objectId: result.objectId };
550 break;
551 default:
552 newValue = { value: result.value };
553 }
554
555 DebuggerAgent.setVariableValue(this._scopeRef.number, name, newValue, th is._scopeRef.callFrameId, this._scopeRef.functionId, setVariableValueCallback.bi nd(this)); 538 DebuggerAgent.setVariableValue(this._scopeRef.number, name, newValue, th is._scopeRef.callFrameId, this._scopeRef.functionId, setVariableValueCallback.bi nd(this));
556 539
557 /** 540 /**
558 * @param {?Protocol.Error} error 541 * @param {?Protocol.Error} error
559 */ 542 */
560 function setVariableValueCallback(error) 543 function setVariableValueCallback(error)
561 { 544 {
562 if (error) { 545 if (error) {
563 callback(error); 546 callback(error);
564 return; 547 return;
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 }, 791 },
809 792
810 /** 793 /**
811 * @return {number} 794 * @return {number}
812 */ 795 */
813 arrayLength: function() 796 arrayLength: function()
814 { 797 {
815 return this._value instanceof Array ? this._value.length : 0; 798 return this._value instanceof Array ? this._value.length : 0;
816 } 799 }
817 } 800 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698