2 * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "JSMessagePort.h"
30 #include "ExceptionCode.h"
32 #include "JSDOMGlobalObject.h"
34 #include "JSEventListener.h"
35 #include "JSMessagePortCustom.h"
36 #include "MessagePort.h"
37 #include <runtime/Error.h>
38 #include <wtf/text/AtomicString.h>
44 void JSMessagePort::visitChildren(SlotVisitor& visitor)
46 ASSERT_GC_OBJECT_INHERITS(this, &s_info);
47 COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
48 ASSERT(structure()->typeInfo().overridesVisitChildren());
49 Base::visitChildren(visitor);
51 // If we have a locally entangled port, we can directly mark it as reachable. Ports that are remotely entangled are marked in-use by markActiveObjectsForContext().
52 if (MessagePort* port = m_impl->locallyEntangledPort())
53 visitor.addOpaqueRoot(port);
55 m_impl->visitJSEventListeners(visitor);
58 JSC::JSValue JSMessagePort::postMessage(JSC::ExecState* exec)
60 return handlePostMessage(exec, impl());
63 void fillMessagePortArray(JSC::ExecState* exec, JSC::JSValue value, MessagePortArray& portArray)
65 // Convert from the passed-in JS array-like object to a MessagePortArray.
66 // Also validates the elements per sections 4.1.13 and 4.1.15 of the WebIDL spec and section 8.3.3 of the HTML5 spec.
67 if (value.isUndefinedOrNull()) {
72 // Validation of sequence types, per WebIDL spec 4.1.13.
74 JSObject* object = toJSSequence(exec, value, length);
75 if (exec->hadException())
78 for (unsigned i = 0 ; i < length; ++i) {
79 JSValue value = object->get(exec, i);
80 if (exec->hadException())
82 // Validation of non-null objects, per HTML5 spec 10.3.3.
83 if (value.isUndefinedOrNull()) {
84 setDOMException(exec, DATA_CLONE_ERR);
88 // Validation of Objects implementing an interface, per WebIDL spec 4.1.15.
89 RefPtr<MessagePort> port = toMessagePort(value);
94 portArray.append(port.release());
98 } // namespace WebCore