Best JavaScript code snippet using wpt
object-get-own-property-names.js
Source:object-get-own-property-names.js
1// Copyright 2009 the V8 project authors. All rights reserved.2// Redistribution and use in source and binary forms, with or without3// modification, are permitted provided that the following conditions are4// met:5//6// * Redistributions of source code must retain the above copyright7// notice, this list of conditions and the following disclaimer.8// * Redistributions in binary form must reproduce the above9// copyright notice, this list of conditions and the following10// disclaimer in the documentation and/or other materials provided11// with the distribution.12// * Neither the name of Google Inc. nor the names of its13// contributors may be used to endorse or promote products derived14// from this software without specific prior written permission.15//16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27// Test ES5 section 15.2.3.4 Object.getOwnPropertyNames.28// Check simple cases.29var obj = { a: 1, b: 2};30var propertyNames = Object.getOwnPropertyNames(obj);31propertyNames.sort();32assertEquals(2, propertyNames.length);33assertEquals("a", propertyNames[0]);34assertEquals("b", propertyNames[1]);35var obj = { a: function(){}, b: function(){} };36var propertyNames = Object.getOwnPropertyNames(obj);37propertyNames.sort();38assertEquals(2, propertyNames.length);39assertEquals("a", propertyNames[0]);40assertEquals("b", propertyNames[1]);41// Check slow case42var obj = { a: 1, b: 2, c: 3 };43delete obj.b;44var propertyNames = Object.getOwnPropertyNames(obj)45propertyNames.sort();46assertEquals(2, propertyNames.length);47assertEquals("a", propertyNames[0]);48assertEquals("c", propertyNames[1]);49// Check that non-enumerable properties are being returned.50var propertyNames = Object.getOwnPropertyNames([1, 2]);51propertyNames.sort();52assertEquals(3, propertyNames.length);53assertEquals("0", propertyNames[0]);54assertEquals("1", propertyNames[1]);55assertEquals("string", typeof propertyNames[0]);56assertEquals("string", typeof propertyNames[1]);57assertEquals("length", propertyNames[2]);58// Check that no proto properties are returned.59var obj = { foo: "foo" };60obj.__proto__ = { bar: "bar" };61propertyNames = Object.getOwnPropertyNames(obj);62propertyNames.sort();63assertEquals(1, propertyNames.length);64assertEquals("foo", propertyNames[0]);65// Check that getter properties are returned.66var obj = {};67obj.__defineGetter__("getter", function() {});68propertyNames = Object.getOwnPropertyNames(obj);69propertyNames.sort();70assertEquals(1, propertyNames.length);71assertEquals("getter", propertyNames[0]);72// Check that implementation does not access Array.prototype.73var savedConcat = Array.prototype.concat;74Array.prototype.concat = function() { return []; }75propertyNames = Object.getOwnPropertyNames({0: 'foo', bar: 'baz'});76assertEquals(2, propertyNames.length);77assertEquals('0', propertyNames[0]);78assertEquals('bar', propertyNames[1]);79assertSame(Array.prototype, propertyNames.__proto__);80Array.prototype.concat = savedConcat;81assertEquals(Object.getOwnPropertyNames(4), []);82assertEquals(Object.getOwnPropertyNames("foo"), ["0", "1", "2", "length"]);83assertEquals(Object.getOwnPropertyNames(true), []);84try {85 Object.getOwnPropertyNames(undefined);86 assertTrue(false);87} catch (e) {88 assertTrue(/Cannot convert undefined or null to object/.test(e));89}90try {91 Object.getOwnPropertyNames(null);92 assertTrue(false);93} catch (e) {94 assertTrue(/Cannot convert undefined or null to object/.test(e));...
Using AI Code Generation
1var wpt = new WebPageTest('www.webpagetest.org');2 if (err) {3 console.log(err);4 } else {5 console.log('Test Id: ' + data.data.testId);6 wpt.getTestStatus(data.data.testId, function(err, data) {7 if (err) {8 console.log(err);9 } else {10 console.log('Test Status: ' + data.data.statusText);11 wpt.getTestResults(data.data.testId, function(err, data) {12 if (err) {13 console.log(err);14 } else {15 console.log('Test Results: ' + data.data.median.firstView);16 }17 });18 }19 });20 }21});22var wpt = new WebPageTest('www.webpagetest.org');23 if (err) {24 console.log(err);25 } else {26 console.log('Test Id: ' + data.data.testId);27 wpt.getTestStatus(data.data.testId, function(err, data) {28 if (err) {29 console.log(err);30 } else {31 console.log('Test Status: ' + data.data.statusText);32 wpt.getTestResults(data.data.testId, function(err, data) {33 if (err) {34 console.log(err);35 } else {36 console.log('Test Results: ' + data.data.median.firstView);37 }38 });39 }40 });41 }42});43var wpt = new WebPageTest('www.webpagetest.org');44 if (err) {45 console.log(err);46 } else {47 console.log('Test Id: ' + data.data.testId);48 wpt.getTestStatus(data.data.testId, function(err, data) {49 if (err) {50 console.log(err);51 } else {52 console.log('Test Status: ' + data.data.statusText);53 wpt.getTestResults(data.data.testId, function(err, data) {54 if (err) {55 console.log(err
Using AI Code Generation
1var wpt = require('webpagetest');2var test = new wpt('API_KEY');3test.propertyNames(function(err, data) {4 console.log(data);5});6{ statusCode: 200,7 { version: '1.0.0',8 default: { runs: 3, fvonly: 1, video: 1, location: 'Dulles:Chrome' },
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!