'Chrome Debugger can't access variable of static callback
I have a static class with only static method written in javascript. The pourpose of the calss and the method is to be a callback container for a certain kind of ajax call.
From the HTML page, sometimes an ajax call is raised and the static method of static class described above, is passed as callback argument. All work just fine, i also remeber to have debugged the callback previously, but after the last chrome update, even if i can debug the callback, i can't see variable value. I can't access variable value (when a breackpoint in the static callback is hit, so in the same scope of breakpoint) with the console nor with the watch.
This is the callback class with static method (it's a bit triky, but i prefer not simplify it because maybe the problem reside in the callback code)
/**
* List of defaults callback
* */
class CallbackDefaults {
/**
* Callback used to update price of priced articles
* @param {object} data Page of ArticleDto with actual prices
*/
static priceUpdateCallback = function (data) {
var callbackSource = "getPricesAndStock_callback";
try {
if (!data || data.Success == false || !data.ReturnData || !data.ReturnData.PageContent && data.ReturnData.PageContent.length > 0)
return;
for (var index = 0; index < data.ReturnData.PageContent.length; index++) {
var currentArticle = data.ReturnData.PageContent[index];
var item = document.querySelector(".cgi-priced[ref-code='" + currentArticle.Code + "']");
if (item && currentArticle && currentArticle.Attributes && currentArticle.Attributes.PriceData && currentArticle.Attributes.PriceData.TaxedPrice) {
var priceData = currentArticle.Attributes.PriceData;
var finalPrice = globals.isVatIncluded ? priceData.TaxedPrice : priceData.CalculatedPrice;
let precetageBadge = item.querySelector(".discount-percentage") || { textContent: "" };
let originalPrice = item.querySelector(".original-price") || { textContent: "" };
let discountedPrice = item.querySelector(".discounted-price") || { textContent: "" };
let buyButton = item.querySelector(".buy") || { disabled: false };
var percentage = globals.trustAS400Perc ?
finalPrice.DiscountPercentage :
finalPrice.CalculatedDiscountPercentage;
var percentageString = globals.trustAS400Perc ?
finalPrice.DiscountPercAsString :
finalPrice.CalculatedDiscountPercAsString;
if (!percentage || percentage <= 0)
precetageBadge?.classList?.add("d-none");
else
{
if (precetageBadge?.classList?.contains("d-none"))
precetageBadge?.classList?.remove('d-none');
precetageBadge.textContent = percentageString || "";
}
if (finalPrice.NetPriceAsStringWithCurrency == finalPrice.GrossPriceAsStringWithCurrency)
originalPrice?.classList?.add("d-none");
else
{
originalPrice.textContent = finalPrice.GrossPriceAsStringWithCurrency || "";
}
if (finalPrice.NetPriceAsStringWithCurrency)
discountedPrice.textContent = finalPrice.NetPriceAsStringWithCurrency || "";
else
buyButton.disabled = true;
//update quantity limit
var inSpinner = $(item).find("input[meta=original]");
if (inSpinner && inSpinner.length == 1) {
var updatedQuantity = currentArticle?.Attributes?.StockInformation?.AvailableQuantityFromCgi;
if (updatedQuantity && updatedQuantity > 0) {
inSpinner.inputSpinner("destroy");
inSpinner[0].max = updatedQuantity;
inSpinner.inputSpinner(globals.inputSpinnerConf);
}
}
}
}
}
catch (callbackErr) {
ClientLogManager.logError(callbackSource, callbackErr);
Toaster.getToast("tstTemplatePriceError");
}
};
}
In JQuery ajax success function i call the callback in the following way :
success: function (data) {
try
{
CallbackDefaults.priceUpdateCallback(data);
}
catch (callErr) {
ClientLogManager.logError(source, callErr)
}
}
When i place a breack point into priceUpdateCallback, for example on the following line :
var callbackSource = "getPricesAndStock_callback";
And the run code, the breakpoint will be hit, but i can't see the actual value of 'callbackSource' variable. I can't get the value hovering, placing the variable in the watch or writing it into the console.
If i try to access the variable through console i get this error :
VM255:1 Uncaught ReferenceError: callbackSource is not defined
at eval (eval at priceUpdateCallback (CallbackDefaults.js:1:1), <anonymous>:1:1)
at priceUpdateCallback (CallbackDefaults.js:13:30)
at Object.success (ConnectionManager.js:169:25)
at c (jquery-3.6.0.min.js:2:28327)
at Object.fireWith [as resolveWith] (jquery-3.6.0.min.js:2:29072)
at l (jquery-3.6.0.min.js:2:79901)
at XMLHttpRequest.<anonymous> (jquery-3.6.0.min.js:2:82355)
I can't understand why, because i remember to have debugged that function before, and seems strange that the new chrome version just introduce a so blatant bug.
--Edit : i am using Chrome 98.0.4758.102 (Official Build) (64-bit)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
