aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/webcore/JSMessageEventCustom.cpp
blob: 772a1b3c4ca911eb1dce08f115348e1b77174e59 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * Copyright (C) 2009 Google Inc. All rights reserved.
 * Copyright (C) 2009-2021 Apple Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *     * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following disclaimer
 * in the documentation and/or other materials provided with the
 * distribution.
 *     * Neither the name of Google Inc. nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "config.h"
#include "JSMessageEvent.h"

// #include "JSBlob.h"
#include "JSDOMBinding.h"
#include "JSDOMConvert.h"
#include "JSDOMWindow.h"
#include "JSEventTarget.h"
// #include "JSMessagePort.h"
#include <JavaScriptCore/JSArray.h>
#include <JavaScriptCore/JSArrayBuffer.h>

namespace WebCore {

JSC::JSValue JSMessageEvent::ports(JSC::JSGlobalObject& lexicalGlobalObject) const
{
    auto throwScope = DECLARE_THROW_SCOPE(lexicalGlobalObject.vm());
    return cachedPropertyValue(lexicalGlobalObject, *this, wrapped().cachedPorts(), [&] {
        JSC::JSValue ports = toJS<IDLFrozenArray<IDLInterface<MessagePort>>>(lexicalGlobalObject, *globalObject(), throwScope, wrapped().ports());
        return ports;
    });
}

JSC::JSValue JSMessageEvent::data(JSC::JSGlobalObject& lexicalGlobalObject) const
{
    auto throwScope = DECLARE_THROW_SCOPE(lexicalGlobalObject.vm());
    return cachedPropertyValue(throwScope, lexicalGlobalObject, *this, wrapped().cachedData(), [this, &lexicalGlobalObject](JSC::ThrowScope&) {
        return WTF::switchOn(
            wrapped().data(), [this](MessageEvent::JSValueTag) -> JSC::JSValue { return wrapped().jsData().getValue(JSC::jsNull()); }, [this, &lexicalGlobalObject](const Ref<SerializedScriptValue>& data) {
            // FIXME: Is it best to handle errors by returning null rather than throwing an exception?
            return data->deserialize(lexicalGlobalObject, globalObject(), wrapped().ports(), SerializationErrorMode::NonThrowing); }, [&lexicalGlobalObject](const String& data) { return toJS<IDLDOMString>(lexicalGlobalObject, data); }, [this, &lexicalGlobalObject](const Ref<ArrayBuffer>& data) { return toJS<IDLInterface<ArrayBuffer>>(lexicalGlobalObject, *globalObject(), data); });
    });
}

template<typename Visitor>
void JSMessageEvent::visitAdditionalChildren(Visitor& visitor)
{
    wrapped().jsData().visit(visitor);
    wrapped().cachedData().visit(visitor);
    wrapped().cachedPorts().visit(visitor);
}

DEFINE_VISIT_ADDITIONAL_CHILDREN(JSMessageEvent);

} // namespace WebCore
er-highlight'> Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-08-21Fix memory leak in `buffer.toString("hex")` (#4235)Gravatar Jarred Sumner 2-1/+6 Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-08-21Update README.md (#4232)Gravatar xxxhussein 1-1/+1 Fix typo in README.md 2023-08-21Add missing header changeGravatar Jarred Sumner 1-1/+1 2023-08-21Add LazyPropertyGravatar Jarred Sumner 1-0/+3 2023-08-21Fix BigIntStats generated classGravatar Jarred Sumner 1-1/+1 cc @paperdave, code generator script misses a constructor decl when this isn't true 2023-08-21RegenerateGravatar Jarred Sumner 1-8/+15 2023-08-21Implement FileGravatar Jarred Sumner 12-12/+387 2023-08-20Fixes #1675 (#4230)Gravatar Jarred Sumner 8-70/+297 * Fixes https://github.com/oven-sh/bun/issues/1675 * Add fallback for Bun.write * Update blob.zig * Fix test --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-08-20Implement `--inspect-brk` (#4222)Gravatar Jarred Sumner 17-41/+101 * Implement `--inspect-brk` * Bump WebKit --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-08-20Fix test failures from 3a9a6c63a (#4231)Gravatar Jarred Sumner 4-32/+34 cc @Hanaasagi Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-08-20Fix(bundler): use different alias mappings based on the target. (#4163)Gravatar Ai Hoshino 8-18/+90 * Fix(bundler): use different alias mappings based on the target. Close: #3844 * chore: reduce duplicated code. * chore: split to two separate ComptimeStringMap. 2023-08-19Update BunDebugger.cppGravatar Jarred Sumner 1-1/+3 2023-08-19Introduce `bun --inspect-wait`Gravatar Jarred Sumner 3-19/+47 This waits for the inspector to connect before beginning execution 2023-08-19misc non-posix fixesGravatar Jarred Sumner 2-3/+3 2023-08-19Update lockfile.mdGravatar Jarred Sumner 1-1/+8 2023-08-19Update lockfile.mdGravatar Jarred Sumner 1-4/+4 2023-08-19Update lockfile.mdGravatar Jarred Sumner 1-1/+29 2023-08-19Update Dockerfile-distroless (#4210)Gravatar Omar 1-0/+1 2023-08-19Fix symbol visibilityGravatar Jarred Sumner 1-0/+1 2023-08-19[napi] Implement `node_api_create_syntax_error`, `node_api_symbol_for`, ↵Gravatar Jarred Sumner 5-1/+70 `node_api_throw_syntax_error` These were marked as experimental 2023-08-19Fix crash impacting sharp & resvg (#4221)Gravatar Jarred Sumner 5-73/+73 Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-08-19Fixes #172 (#4220)Gravatar Jarred Sumner 7-9/+87 Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-08-19Add inline sourcemaps when `--inspect` is enabled (#4213)Gravatar Jarred Sumner 3-3/+64 * Add inline sourcemaps when --inspect is enabled * Add some assertions * Update javascript.zig --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-08-19tty `ReadStream`, `WriteStream`, and readline rawmode (#4179)Gravatar Dylan Conway 23-722/+821 * tty `WriteStream`, `ReadStream`, and rawmode * tests * refactor prototypes * fix failing test * fix test and library usage * more merge * fix child_process test * create pseudo terminal for tty tests * match node logic * handle invalid tty * close descriptors * move tests to another process * fix test again * fix test on linux 2023-08-18Fix make headers (again)Gravatar Jarred Sumner 1-0/+2