15ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen/* 25ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen * Copyright (C) 2009 Apple Inc. All rights reserved. 35ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen * 45ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen * Redistribution and use in source and binary forms, with or without 55ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen * modification, are permitted provided that the following conditions 65ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen * are met: 75ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen * 1. Redistributions of source code must retain the above copyright 85ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen * notice, this list of conditions and the following disclaimer. 95ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen * 2. Redistributions in binary form must reproduce the above copyright 105ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen * notice, this list of conditions and the following disclaimer in the 115ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen * documentation and/or other materials provided with the distribution. 125ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen * 135ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 145ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 155ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 165ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 175ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 185ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 195ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 205ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 215ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 225ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 235ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 245ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen * 255ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen */ 265ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen 275ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen#ifndef SerializedScriptValue_h 285ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen#define SerializedScriptValue_h 295ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen 305ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen#include <heap/Strong.h> 312fc2651226baac27029e38c9d6ef883fa32084dbSteve Block#include <runtime/JSValue.h> 325ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen#include <wtf/Forward.h> 335ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen#include <wtf/PassRefPtr.h> 345ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen#include <wtf/RefCounted.h> 355ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen 365ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsentypedef const struct OpaqueJSContext* JSContextRef; 375ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsentypedef const struct OpaqueJSValue* JSValueRef; 38ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch 39ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdochnamespace WebCore { 405ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen 415ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen 425ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsenenum SerializationReturnCode { 435ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen SuccessfullyCompleted, 445ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen StackOverflowError, 455ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen InterruptedExecutionError, 465ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen ValidationError, 475ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen ExistingExceptionError, 485ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen UnspecifiedError 495ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen}; 505ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen 515ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsenenum SerializationErrorMode { NonThrowing, Throwing }; 525ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen 535ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsenclass SharedBuffer; 545ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen 555ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsenclass SerializedScriptValue : public RefCounted<SerializedScriptValue> { 565ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsenpublic: 572fc2651226baac27029e38c9d6ef883fa32084dbSteve Block static PassRefPtr<SerializedScriptValue> create(JSC::ExecState*, JSC::JSValue, SerializationErrorMode = Throwing); 585ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen static PassRefPtr<SerializedScriptValue> create(JSContextRef, JSValueRef value, JSValueRef* exception); 595ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen static PassRefPtr<SerializedScriptValue> create(String string); 605ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen static PassRefPtr<SerializedScriptValue> adopt(Vector<uint8_t>& buffer) 615ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen { 625ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen return adoptRef(new SerializedScriptValue(buffer)); 635ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen } 645ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen 655ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen static PassRefPtr<SerializedScriptValue> create(); 665ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen static SerializedScriptValue* nullValue(); 675ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen 685ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen String toString(); 695ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen 705ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen JSC::JSValue deserialize(JSC::ExecState*, JSC::JSGlobalObject*, SerializationErrorMode = Throwing); 715ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen JSValueRef deserialize(JSContextRef, JSValueRef* exception); 725ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen 735ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen const Vector<uint8_t>& data() { return m_data; } 745ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen 755ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen ~SerializedScriptValue(); 765ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen 775ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsenprivate: 785ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen static void maybeThrowExceptionIfSerializationFailed(JSC::ExecState*, SerializationReturnCode); 795ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen static bool serializationDidCompleteSuccessfully(SerializationReturnCode); 805ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen 81 SerializedScriptValue(Vector<unsigned char>&); 82 Vector<unsigned char> m_data; 83}; 84 85} 86 87#endif // SerializedScriptValue_h 88