toJSON method Null safety

dynamic toJSON()

Returns a JSON representation of the PerformanceEntry object. json = perfEntry.toJSON();

The following example shows the use of the toJSON() method.

function run_PerformanceEntry() { log("PerformanceEntry support ...");

if (performance.mark === undefined) { log("... performance.mark Not supported"); return; }

// Create some performance entries via the mark() method performance.mark("Begin"); do_work(50000); performance.mark("End");

// Use getEntries() to iterate through the each entry var p = performance.getEntries(); for (var i=0; i < p.length; i++) { log("Entry" + i + ""); check_PerformanceEntry(pi); } } function check_PerformanceEntry(obj) { var properties = "name", "entryType", "startTime", "duration"; var methods = "toJSON";

for (var i=0; i < properties.length; i++) { // check each property var supported = propertiesi in obj; if (supported) log("..." + propertiesi + " = " + obj[propertiesi]); else log("..." + propertiesi + " = Not supported"); } for (var i=0; i < methods.length; i++) { // check each method var supported = typeof obj[methodsi] == "function"; if (supported) { var js = obj[methodsi](); log("..." + methodsi + "() = " + JSON.stringify(js)); } else { log("..." + methodsi + " = Not supported"); } } }

Implementation

external dynamic toJSON();