Chromium Code Reviews| Index: LayoutTests/http/tests/notifications/resources/instrumentation-service-worker.js |
| diff --git a/LayoutTests/http/tests/notifications/resources/instrumentation-service-worker.js b/LayoutTests/http/tests/notifications/resources/instrumentation-service-worker.js |
| index 5327843a0b62dc8432680179b5b6707e40d6964c..07f85ebf520ca74401be98558c1f5ac7f2e146c4 100644 |
| --- a/LayoutTests/http/tests/notifications/resources/instrumentation-service-worker.js |
| +++ b/LayoutTests/http/tests/notifications/resources/instrumentation-service-worker.js |
| @@ -1,8 +1,28 @@ |
| importScripts('/resources/testharness-helpers.js'); |
| +// For copying Notification.data. Currently a deep copy algorithm is used. Note |
| +// that the robustness of this function (and also |assert_object_equals| in |
| +// testharness.js) affects the types of possible testing can be done. |
| +// TODO(peter): change this to a structured clone algorithm. |
| +function cloneObject(src) { |
| + if (typeof src != 'object') |
|
Peter Beverloo
2015/09/01 15:31:44
nit: could change this to the following, which mat
lwchkg
2015/09/01 16:21:09
Sounds good.
|
| + return src; |
| + if (src === null) |
| + return null; |
| + var dst = Array.isArray(src) ? [] : {}; |
| + for (var property in src) { |
| + if (src.hasOwnProperty(property)) { |
|
Peter Beverloo
2015/09/01 15:31:44
nit: no need for {} (one-statement if clause)
lwchkg
2015/09/01 16:21:09
Acknowledged.
|
| + dst[property] = cloneObject(src[property]); |
| + } |
| + } |
| + return dst; |
| +} |
| + |
| // Copies the serializable attributes of |notification|. |
| function cloneNotification(notification) { |
| - return JSON.parse(stringifyDOMObject(notification)); |
| + var dst = JSON.parse(stringifyDOMObject(notification)); |
|
Peter Beverloo
2015/09/01 15:31:44
nit: could we name this "copiedNotification"? We p
lwchkg
2015/09/01 16:21:09
Sounds good. Agree that "dst" is not clear enough.
|
| + dst.data = cloneObject(notification.data); |
| + return dst; |
| } |
| // Allows a document to exercise the Notifications API within a service worker by sending commands. |