source: webkit/trunk/JavaScriptCore/runtime/DateInstance.cpp@ 54843

Last change on this file since 54843 was 53969, checked in by [email protected], 15 years ago

2010-01-27 Oliver Hunt <[email protected]>

Reviewed by Maciej Stachowiak.

MessageEvent.data should deserialize in the context of the MessageEvent's global object
https://bugs.webkit.org/show_bug.cgi?id=34227

Add logic to allow us to create an Object, Array, or Date instance
so we can create them in the context of a specific global object,
rather than just using the current lexical global object.

  • JavaScriptCore.exp:
  • runtime/DateInstance.cpp: (JSC::DateInstance::DateInstance):
  • runtime/DateInstance.h:
  • runtime/JSGlobalObject.h: (JSC::constructEmptyObject): (JSC::constructEmptyArray):

2010-01-27 Oliver Hunt <[email protected]>

Reviewed by Maciej Stachowiak.

MessageEvent.data should deserialize in the context of the MessageEvent's global object
https://bugs.webkit.org/show_bug.cgi?id=34227

Test that the object returned from postMessage.data is created in the correct context

  • fast/dom/Window/resources/window-postmessage-clone-frames-frame.html: Added.
  • fast/dom/Window/window-postmessage-clone-frames-expected.txt: Added.
  • fast/dom/Window/window-postmessage-clone-frames.html: Added.

2010-01-27 Oliver Hunt <[email protected]>

Reviewed by Maciej Stachowiak.

MessageEvent.data should deserialize in the context of the MessageEvent's global object
https://bugs.webkit.org/show_bug.cgi?id=34227

Make ScriptValue deserialisation support the provision of a specific global
object to use when creating new objects. This then allows us to make
MessageEvent.data and PopStateEvent.state deserialize in the correct
context.

Test: fast/dom/Window/window-postmessage-clone-frames.html

  • bindings/js/JSPopStateEventCustom.cpp: Remove custom implementation of state getter
  • bindings/js/SerializedScriptValue.cpp: (WebCore::DeserializingTreeWalker::DeserializingTreeWalker): (WebCore::DeserializingTreeWalker::createOutputArray): (WebCore::DeserializingTreeWalker::createOutputObject): (WebCore::DeserializingTreeWalker::convertIfTerminal): (WebCore::SerializedScriptValueData::deserialize): (WebCore::SerializedScriptValue::deserialize):
  • bindings/js/SerializedScriptValue.h: (WebCore::SerializedScriptValue::deserialize):
  • bindings/scripts/CodeGeneratorJS.pm: Update bindings generation to pass the correct global object, and to treat "any" as synonymous with SerializedValue.
  • dom/PopStateEvent.idl:
  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1/*
2 * Copyright (C) 1999-2000 Harri Porten ([email protected])
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 * USA
19 *
20 */
21
22#include "config.h"
23#include "DateInstance.h"
24
25#include "JSGlobalObject.h"
26
27#include <math.h>
28#include <wtf/DateMath.h>
29#include <wtf/MathExtras.h>
30
31using namespace WTF;
32
33namespace JSC {
34
35const ClassInfo DateInstance::info = {"Date", 0, 0, 0};
36
37DateInstance::DateInstance(ExecState* exec, NonNullPassRefPtr<Structure> structure)
38 : JSWrapperObject(structure)
39{
40 setInternalValue(jsNaN(exec));
41}
42
43DateInstance::DateInstance(ExecState* exec, NonNullPassRefPtr<Structure> structure, double time)
44 : JSWrapperObject(structure)
45{
46 setInternalValue(jsNumber(exec, timeClip(time)));
47}
48
49DateInstance::DateInstance(ExecState* exec, double time)
50 : JSWrapperObject(exec->lexicalGlobalObject()->dateStructure())
51{
52 setInternalValue(jsNumber(exec, timeClip(time)));
53}
54
55const GregorianDateTime* DateInstance::calculateGregorianDateTime(ExecState* exec) const
56{
57 double milli = internalNumber();
58 if (isnan(milli))
59 return 0;
60
61 if (!m_data)
62 m_data = exec->globalData().dateInstanceCache.add(milli);
63
64 if (m_data->m_gregorianDateTimeCachedForMS != milli) {
65 msToGregorianDateTime(exec, milli, false, m_data->m_cachedGregorianDateTime);
66 m_data->m_gregorianDateTimeCachedForMS = milli;
67 }
68 return &m_data->m_cachedGregorianDateTime;
69}
70
71const GregorianDateTime* DateInstance::calculateGregorianDateTimeUTC(ExecState* exec) const
72{
73 double milli = internalNumber();
74 if (isnan(milli))
75 return 0;
76
77 if (!m_data)
78 m_data = exec->globalData().dateInstanceCache.add(milli);
79
80 if (m_data->m_gregorianDateTimeUTCCachedForMS != milli) {
81 msToGregorianDateTime(exec, milli, true, m_data->m_cachedGregorianDateTimeUTC);
82 m_data->m_gregorianDateTimeUTCCachedForMS = milli;
83 }
84 return &m_data->m_cachedGregorianDateTimeUTC;
85}
86
87} // namespace JSC
Note: See TracBrowser for help on using the repository browser.