From 48eaff87dc566a3f16bfad20ad1d2489ef5a05ff Mon Sep 17 00:00:00 2001 From: Angshuman Agarwal Date: Sat, 20 Jul 2019 03:17:44 +0100 Subject: [PATCH] Javascript Integration - Passing empty array in JS now maps to empty list/array instead of null (#2829) * Set empty list instead of null * Added QUnit Test for testing Empty Array --- .../Serialization/V8Serialization.cpp | 11 ++++------- CefSharp.Example/Resources/BindingTest.html | 11 +++++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CefSharp.BrowserSubprocess.Core/Serialization/V8Serialization.cpp b/CefSharp.BrowserSubprocess.Core/Serialization/V8Serialization.cpp index c7bcc8ee9..c335eb621 100644 --- a/CefSharp.BrowserSubprocess.Core/Serialization/V8Serialization.cpp +++ b/CefSharp.BrowserSubprocess.Core/Serialization/V8Serialization.cpp @@ -1,4 +1,4 @@ -// Copyright © 2015 The CefSharp Authors. All rights reserved. +// Copyright © 2015 The CefSharp Authors. All rights reserved. // // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. @@ -59,20 +59,17 @@ namespace CefSharp { int arrLength = obj->GetArrayLength(); std::vector keys; + auto array = CefListValue::Create(); if (arrLength > 0 && obj->GetKeys(keys)) { - auto array = CefListValue::Create(); for (int i = 0; i < arrLength; i++) { SerializeV8Object(obj->GetValue(keys[i]), array, i, callbackRegistry, seen); } - list->SetList(index, array); - } - else - { - list->SetNull(index); } + + list->SetList(index, array); } else if (obj->IsFunction()) { diff --git a/CefSharp.Example/Resources/BindingTest.html b/CefSharp.Example/Resources/BindingTest.html index dc5e6e36c..47c0e4385 100644 --- a/CefSharp.Example/Resources/BindingTest.html +++ b/CefSharp.Example/Resources/BindingTest.html @@ -333,6 +333,17 @@ }); }); + QUnit.test("Async call (Test Empty Array):", function (assert) { + var asyncCallback = assert.async(); + + boundAsync.echoArray([]).then(function (res) { + assert.equal(Array.isArray(res), true, "Expected result is an array"); + assert.equal(res.length, 0, "Expected result to be length 0 (empty array)"); + asyncCallback(); + }); + }); + + QUnit.test("Async call (echoValueTypeArray):", function (assert) { var asyncCallback = assert.async();