source: webkit/trunk/JavaScriptCore/kjs/DateMath.cpp@ 36263

Last change on this file since 36263 was 36263, checked in by [email protected], 17 years ago

2008-09-07 Cameron Zwarich <[email protected]>

Reviewed by Maciej Stachowiak.

Bug 20704: Replace the KJS namespace
<https://bugs.webkit.org/show_bug.cgi?id=20704>

Rename the KJS namespace to JSC. There are still some uses of KJS in
preprocessor macros and comments, but these will also be changed some
time in the near future. There are also some uses in the names of JNI
functions, but I will check if these are safe to change as well.

JavaScriptCore:

  • API/APICast.h: (toJS): (toRef): (toGlobalRef):
  • API/JSBase.cpp:
  • API/JSCallbackConstructor.cpp:
  • API/JSCallbackConstructor.h:
  • API/JSCallbackFunction.cpp:
  • API/JSCallbackFunction.h:
  • API/JSCallbackObject.cpp:
  • API/JSCallbackObject.h:
  • API/JSCallbackObjectFunctions.h:
  • API/JSClassRef.cpp: (OpaqueJSClass::staticValues): (OpaqueJSClass::staticFunctions):
  • API/JSClassRef.h:
  • API/JSContextRef.cpp:
  • API/JSObjectRef.cpp:
  • API/JSProfilerPrivate.cpp:
  • API/JSStringRef.cpp:
  • API/JSValueRef.cpp: (JSValueGetType):
  • API/OpaqueJSString.cpp:
  • API/OpaqueJSString.h:
  • JavaScriptCore.Debug.exp:
  • JavaScriptCore.base.exp:
  • VM/CTI.cpp: (JSC::):
  • VM/CTI.h:
  • VM/CodeBlock.cpp:
  • VM/CodeBlock.h:
  • VM/CodeGenerator.cpp:
  • VM/CodeGenerator.h:
  • VM/ExceptionHelpers.cpp:
  • VM/ExceptionHelpers.h:
  • VM/Instruction.h:
  • VM/JSPropertyNameIterator.cpp:
  • VM/JSPropertyNameIterator.h:
  • VM/LabelID.h:
  • VM/Machine.cpp:
  • VM/Machine.h:
  • VM/Opcode.cpp:
  • VM/Opcode.h:
  • VM/Register.h: (WTF::):
  • VM/RegisterFile.cpp:
  • VM/RegisterFile.h:
  • VM/RegisterID.h: (WTF::):
  • VM/SamplingTool.cpp:
  • VM/SamplingTool.h:
  • VM/SegmentedVector.h:
  • kjs/ArgList.cpp:
  • kjs/ArgList.h:
  • kjs/Arguments.cpp:
  • kjs/Arguments.h:
  • kjs/ArrayConstructor.cpp:
  • kjs/ArrayConstructor.h:
  • kjs/ArrayPrototype.cpp:
  • kjs/ArrayPrototype.h:
  • kjs/BatchedTransitionOptimizer.h:
  • kjs/BooleanConstructor.cpp:
  • kjs/BooleanConstructor.h:
  • kjs/BooleanObject.cpp:
  • kjs/BooleanObject.h:
  • kjs/BooleanPrototype.cpp:
  • kjs/BooleanPrototype.h:
  • kjs/CallData.cpp:
  • kjs/CallData.h:
  • kjs/ClassInfo.h:
  • kjs/CommonIdentifiers.cpp:
  • kjs/CommonIdentifiers.h:
  • kjs/ConstructData.cpp:
  • kjs/ConstructData.h:
  • kjs/DateConstructor.cpp:
  • kjs/DateConstructor.h:
  • kjs/DateInstance.cpp: (JSC::DateInstance::msToGregorianDateTime):
  • kjs/DateInstance.h:
  • kjs/DateMath.cpp:
  • kjs/DateMath.h:
  • kjs/DatePrototype.cpp:
  • kjs/DatePrototype.h:
  • kjs/DebuggerCallFrame.cpp:
  • kjs/DebuggerCallFrame.h:
  • kjs/Error.cpp:
  • kjs/Error.h:
  • kjs/ErrorConstructor.cpp:
  • kjs/ErrorConstructor.h:
  • kjs/ErrorInstance.cpp:
  • kjs/ErrorInstance.h:
  • kjs/ErrorPrototype.cpp:
  • kjs/ErrorPrototype.h:
  • kjs/ExecState.cpp:
  • kjs/ExecState.h:
  • kjs/FunctionConstructor.cpp:
  • kjs/FunctionConstructor.h:
  • kjs/FunctionPrototype.cpp:
  • kjs/FunctionPrototype.h:
  • kjs/GetterSetter.cpp:
  • kjs/GetterSetter.h:
  • kjs/GlobalEvalFunction.cpp:
  • kjs/GlobalEvalFunction.h:
  • kjs/IndexToNameMap.cpp:
  • kjs/IndexToNameMap.h:
  • kjs/InitializeThreading.cpp:
  • kjs/InitializeThreading.h:
  • kjs/InternalFunction.cpp:
  • kjs/InternalFunction.h: (JSC::InternalFunction::InternalFunction):
  • kjs/JSActivation.cpp:
  • kjs/JSActivation.h:
  • kjs/JSArray.cpp:
  • kjs/JSArray.h:
  • kjs/JSCell.cpp:
  • kjs/JSCell.h:
  • kjs/JSFunction.cpp:
  • kjs/JSFunction.h: (JSC::JSFunction::JSFunction):
  • kjs/JSGlobalData.cpp: (JSC::JSGlobalData::JSGlobalData):
  • kjs/JSGlobalData.h:
  • kjs/JSGlobalObject.cpp:
  • kjs/JSGlobalObject.h:
  • kjs/JSGlobalObjectFunctions.cpp:
  • kjs/JSGlobalObjectFunctions.h:
  • kjs/JSImmediate.cpp:
  • kjs/JSImmediate.h:
  • kjs/JSLock.cpp:
  • kjs/JSLock.h:
  • kjs/JSNotAnObject.cpp:
  • kjs/JSNotAnObject.h:
  • kjs/JSNumberCell.cpp:
  • kjs/JSNumberCell.h:
  • kjs/JSObject.cpp:
  • kjs/JSObject.h:
  • kjs/JSStaticScopeObject.cpp:
  • kjs/JSStaticScopeObject.h:
  • kjs/JSString.cpp:
  • kjs/JSString.h:
  • kjs/JSType.h:
  • kjs/JSValue.cpp:
  • kjs/JSValue.h:
  • kjs/JSVariableObject.cpp:
  • kjs/JSVariableObject.h:
  • kjs/JSWrapperObject.cpp:
  • kjs/JSWrapperObject.h:
  • kjs/LabelStack.cpp:
  • kjs/LabelStack.h:
  • kjs/MathObject.cpp:
  • kjs/MathObject.h:
  • kjs/NativeErrorConstructor.cpp:
  • kjs/NativeErrorConstructor.h:
  • kjs/NativeErrorPrototype.cpp:
  • kjs/NativeErrorPrototype.h:
  • kjs/NodeInfo.h:
  • kjs/NumberConstructor.cpp:
  • kjs/NumberConstructor.h:
  • kjs/NumberObject.cpp:
  • kjs/NumberObject.h:
  • kjs/NumberPrototype.cpp:
  • kjs/NumberPrototype.h:
  • kjs/ObjectConstructor.cpp:
  • kjs/ObjectConstructor.h:
  • kjs/ObjectPrototype.cpp:
  • kjs/ObjectPrototype.h:
  • kjs/Parser.cpp:
  • kjs/Parser.h:
  • kjs/PropertyMap.cpp: (JSC::PropertyMapStatisticsExitLogger::~PropertyMapStatisticsExitLogger):
  • kjs/PropertyMap.h:
  • kjs/PropertyNameArray.cpp:
  • kjs/PropertyNameArray.h:
  • kjs/PropertySlot.cpp:
  • kjs/PropertySlot.h:
  • kjs/PrototypeFunction.cpp:
  • kjs/PrototypeFunction.h:
  • kjs/PutPropertySlot.h:
  • kjs/RegExpConstructor.cpp:
  • kjs/RegExpConstructor.h:
  • kjs/RegExpObject.cpp:
  • kjs/RegExpObject.h:
  • kjs/RegExpPrototype.cpp:
  • kjs/RegExpPrototype.h:
  • kjs/ScopeChain.cpp:
  • kjs/ScopeChain.h:
  • kjs/ScopeChainMark.h:
  • kjs/Shell.cpp: (jscmain):
  • kjs/SmallStrings.cpp:
  • kjs/SmallStrings.h:
  • kjs/SourceProvider.h:
  • kjs/SourceRange.h:
  • kjs/StringConstructor.cpp:
  • kjs/StringConstructor.h:
  • kjs/StringObject.cpp:
  • kjs/StringObject.h:
  • kjs/StringObjectThatMasqueradesAsUndefined.h:
  • kjs/StringPrototype.cpp:
  • kjs/StringPrototype.h:
  • kjs/StructureID.cpp:
  • kjs/StructureID.h:
  • kjs/SymbolTable.h:
  • kjs/collector.cpp:
  • kjs/collector.h:
  • kjs/completion.h:
  • kjs/create_hash_table:
  • kjs/debugger.cpp:
  • kjs/debugger.h:
  • kjs/dtoa.cpp:
  • kjs/dtoa.h:
  • kjs/grammar.y:
  • kjs/identifier.cpp:
  • kjs/identifier.h: (JSC::Identifier::equal):
  • kjs/interpreter.cpp:
  • kjs/interpreter.h:
  • kjs/lexer.cpp: (JSC::Lexer::Lexer): (JSC::Lexer::clear): (JSC::Lexer::makeIdentifier):
  • kjs/lexer.h:
  • kjs/lookup.cpp:
  • kjs/lookup.h:
  • kjs/nodes.cpp:
  • kjs/nodes.h:
  • kjs/nodes2string.cpp:
  • kjs/operations.cpp:
  • kjs/operations.h:
  • kjs/protect.h:
  • kjs/regexp.cpp:
  • kjs/regexp.h:
  • kjs/ustring.cpp:
  • kjs/ustring.h: (JSC::operator!=): (JSC::IdentifierRepHash::hash): (WTF::):
  • masm/MacroAssembler.h:
  • masm/MacroAssemblerWin.cpp:
  • masm/X86Assembler.h:
  • pcre/pcre_exec.cpp:
  • profiler/CallIdentifier.h: (WTF::):
  • profiler/HeavyProfile.cpp:
  • profiler/HeavyProfile.h:
  • profiler/Profile.cpp:
  • profiler/Profile.h:
  • profiler/ProfileGenerator.cpp:
  • profiler/ProfileGenerator.h:
  • profiler/ProfileNode.cpp:
  • profiler/ProfileNode.h:
  • profiler/Profiler.cpp:
  • profiler/Profiler.h:
  • profiler/TreeProfile.cpp:
  • profiler/TreeProfile.h:
  • wrec/WREC.cpp:
  • wrec/WREC.h:
  • wtf/AVLTree.h:

WebCore:

  • WebCore.base.exp:
  • bindings/js/GCController.cpp:
  • bindings/js/JSAttrCustom.cpp:
  • bindings/js/JSAudioConstructor.cpp:
  • bindings/js/JSAudioConstructor.h: (WebCore::JSAudioConstructor::classInfo):
  • bindings/js/JSCSSRuleCustom.cpp:
  • bindings/js/JSCSSStyleDeclarationCustom.cpp:
  • bindings/js/JSCSSValueCustom.cpp:
  • bindings/js/JSCanvasPixelArrayCustom.cpp:
  • bindings/js/JSCanvasRenderingContext2DCustom.cpp:
  • bindings/js/JSClipboardCustom.cpp:
  • bindings/js/JSConsoleCustom.cpp:
  • bindings/js/JSCustomSQLStatementCallback.cpp: (WebCore::JSCustomSQLStatementCallback::handleEvent):
  • bindings/js/JSCustomSQLStatementCallback.h: (WebCore::JSCustomSQLStatementCallback::create):
  • bindings/js/JSCustomSQLStatementErrorCallback.cpp: (WebCore::JSCustomSQLStatementErrorCallback::handleEvent):
  • bindings/js/JSCustomSQLStatementErrorCallback.h: (WebCore::JSCustomSQLStatementErrorCallback::create):
  • bindings/js/JSCustomSQLTransactionCallback.cpp: (WebCore::JSCustomSQLTransactionCallback::handleEvent):
  • bindings/js/JSCustomSQLTransactionCallback.h: (WebCore::JSCustomSQLTransactionCallback::create):
  • bindings/js/JSCustomSQLTransactionErrorCallback.cpp: (WebCore::JSCustomSQLTransactionErrorCallback::handleEvent):
  • bindings/js/JSCustomSQLTransactionErrorCallback.h: (WebCore::JSCustomSQLTransactionErrorCallback::create):
  • bindings/js/JSCustomVoidCallback.cpp: (WebCore::JSCustomVoidCallback::handleEvent):
  • bindings/js/JSCustomVoidCallback.h: (WebCore::JSCustomVoidCallback::create):
  • bindings/js/JSCustomXPathNSResolver.cpp: (WebCore::JSCustomXPathNSResolver::create):
  • bindings/js/JSCustomXPathNSResolver.h:
  • bindings/js/JSDOMApplicationCacheCustom.cpp: (WebCore::JSDOMApplicationCache::dispatchEvent):
  • bindings/js/JSDOMBinding.cpp: (WebCore::jsOwnedStringOrNull):
  • bindings/js/JSDOMBinding.h: (WebCore::DOMObject::DOMObject): (WebCore::cacheDOMObject): (WebCore::cacheSVGDOMObject): (WebCore::DOMExceptionTranslator::DOMExceptionTranslator): (WebCore::toJS):
  • bindings/js/JSDOMWindowBase.cpp:
  • bindings/js/JSDOMWindowBase.h: (WebCore::JSDOMWindowBase::classInfo): (WebCore::JSDOMWindowBase::d):
  • bindings/js/JSDOMWindowCustom.cpp: (WebCore::JSDOMWindow::getPropertyAttributes):
  • bindings/js/JSDOMWindowCustom.h: (WebCore::asJSDOMWindow): (WebCore::JSDOMWindow::customGetOwnPropertySlot): (WebCore::JSDOMWindow::customPut): (WebCore::JSDOMWindowBase::allowsAccessFrom): (WebCore::JSDOMWindowBase::allowsAccessFromNoErrorMessage):
  • bindings/js/JSDOMWindowShell.cpp: (WebCore::JSDOMWindowShell::getPropertyAttributes):
  • bindings/js/JSDOMWindowShell.h: (WebCore::JSDOMWindowShell::classInfo):
  • bindings/js/JSDatabaseCustom.cpp:
  • bindings/js/JSDocumentCustom.cpp:
  • bindings/js/JSDocumentFragmentCustom.cpp:
  • bindings/js/JSElementCustom.cpp:
  • bindings/js/JSEventCustom.cpp:
  • bindings/js/JSEventListener.cpp:
  • bindings/js/JSEventListener.h: (WebCore::JSUnprotectedEventListener::create): (WebCore::JSEventListener::create):
  • bindings/js/JSEventTargetBase.cpp:
  • bindings/js/JSEventTargetBase.h: (WebCore::JSEventTargetBase::getValueProperty): (WebCore::JSEventTargetBase::putValueProperty): (WebCore::JSEventTargetBase::getOwnPropertySlot): (WebCore::JSEventTargetBase::put): (WebCore::JSEventTargetPrototype::JSEventTargetPrototype): (WebCore::JSEventTargetPrototype::self): (WebCore::JSEventTargetPrototype::getOwnPropertySlot): (WebCore::JSEventTargetPrototype::classInfo):
  • bindings/js/JSEventTargetNode.cpp:
  • bindings/js/JSEventTargetNode.h: (WebCore::JSEventTargetNode::getOwnPropertySlot): (WebCore::JSEventTargetNode::getValueProperty): (WebCore::JSEventTargetNode::put): (WebCore::JSEventTargetNode::putValueProperty):
  • bindings/js/JSHTMLAllCollection.h: (WebCore::JSHTMLAllCollection::JSHTMLAllCollection): (WebCore::JSHTMLAllCollection::toBoolean):
  • bindings/js/JSHTMLAppletElementCustom.cpp:
  • bindings/js/JSHTMLCollectionCustom.cpp:
  • bindings/js/JSHTMLDocumentCustom.cpp:
  • bindings/js/JSHTMLElementCustom.cpp:
  • bindings/js/JSHTMLEmbedElementCustom.cpp:
  • bindings/js/JSHTMLFormElementCustom.cpp:
  • bindings/js/JSHTMLFrameElementCustom.cpp:
  • bindings/js/JSHTMLFrameSetElementCustom.cpp:
  • bindings/js/JSHTMLIFrameElementCustom.cpp:
  • bindings/js/JSHTMLInputElementBase.cpp: (WebCore::JSHTMLInputElementBase::JSHTMLInputElementBase): (WebCore::JSHTMLInputElementBase::getOwnPropertySlot):
  • bindings/js/JSHTMLInputElementBase.h: (WebCore::JSHTMLInputElementBase::classInfo):
  • bindings/js/JSHTMLObjectElementCustom.cpp:
  • bindings/js/JSHTMLOptionElementConstructor.cpp:
  • bindings/js/JSHTMLOptionElementConstructor.h: (WebCore::JSHTMLOptionElementConstructor::classInfo):
  • bindings/js/JSHTMLOptionsCollectionCustom.cpp:
  • bindings/js/JSHTMLSelectElementCustom.cpp: (WebCore::selectIndexSetter): (WebCore::JSHTMLSelectElement::indexSetter):
  • bindings/js/JSHTMLSelectElementCustom.h:
  • bindings/js/JSHistoryCustom.cpp:
  • bindings/js/JSImageConstructor.cpp:
  • bindings/js/JSImageConstructor.h: (WebCore::JSImageConstructor::classInfo):
  • bindings/js/JSInspectedObjectWrapper.cpp:
  • bindings/js/JSInspectedObjectWrapper.h: (WebCore::JSInspectedObjectWrapper::wrapOutgoingValue): (WebCore::JSInspectedObjectWrapper::classInfo):
  • bindings/js/JSInspectorCallbackWrapper.cpp:
  • bindings/js/JSInspectorCallbackWrapper.h: (WebCore::JSInspectorCallbackWrapper::classInfo): (WebCore::JSInspectorCallbackWrapper::wrapOutgoingValue):
  • bindings/js/JSJavaScriptCallFrameCustom.cpp:
  • bindings/js/JSLocationCustom.cpp:
  • bindings/js/JSMimeTypeArrayCustom.cpp:
  • bindings/js/JSNSResolver.cpp:
  • bindings/js/JSNSResolver.h: (WebCore::JSNSResolver::create):
  • bindings/js/JSNamedNodeMapCustom.cpp:
  • bindings/js/JSNamedNodesCollection.cpp: (WebCore::JSNamedNodesCollection::JSNamedNodesCollection):
  • bindings/js/JSNamedNodesCollection.h: (WebCore::JSNamedNodesCollection::classInfo):
  • bindings/js/JSNavigatorCustom.cpp:
  • bindings/js/JSNodeCustom.cpp:
  • bindings/js/JSNodeFilterCondition.cpp: (WebCore::JSNodeFilterCondition::acceptNode):
  • bindings/js/JSNodeFilterCondition.h: (WebCore::JSNodeFilterCondition::create):
  • bindings/js/JSNodeFilterCustom.cpp:
  • bindings/js/JSNodeIteratorCustom.cpp:
  • bindings/js/JSNodeListCustom.cpp:
  • bindings/js/JSPluginArrayCustom.cpp:
  • bindings/js/JSPluginCustom.cpp:
  • bindings/js/JSPluginElementFunctions.cpp: (WebCore::getRuntimeObject):
  • bindings/js/JSPluginElementFunctions.h:
  • bindings/js/JSQuarantinedObjectWrapper.cpp: (WebCore::JSQuarantinedObjectWrapper::construct): (WebCore::JSQuarantinedObjectWrapper::call):
  • bindings/js/JSQuarantinedObjectWrapper.h: (WebCore::JSQuarantinedObjectWrapper::unwrappedObject): (WebCore::JSQuarantinedObjectWrapper::unwrappedGlobalObject): (WebCore::JSQuarantinedObjectWrapper::className):
  • bindings/js/JSRGBColor.cpp:
  • bindings/js/JSRGBColor.h: (WebCore::JSRGBColor::classInfo):
  • bindings/js/JSSQLResultSetRowListCustom.cpp:
  • bindings/js/JSSQLTransactionCustom.cpp:
  • bindings/js/JSSVGLazyEventListener.cpp:
  • bindings/js/JSSVGLazyEventListener.h:
  • bindings/js/JSSVGLengthCustom.cpp:
  • bindings/js/JSSVGMatrixCustom.cpp: (WebCore::JSSVGMatrix::inverse): (WebCore::JSSVGMatrix::rotateFromVector):
  • bindings/js/JSSVGPathSegCustom.cpp:
  • bindings/js/JSSVGPathSegListCustom.cpp: (WebCore::JSSVGPathSegList::initialize): (WebCore::JSSVGPathSegList::getItem): (WebCore::JSSVGPathSegList::insertItemBefore): (WebCore::JSSVGPathSegList::replaceItem): (WebCore::JSSVGPathSegList::removeItem): (WebCore::JSSVGPathSegList::appendItem):
  • bindings/js/JSSVGPointListCustom.cpp:
  • bindings/js/JSSVGTransformListCustom.cpp:
  • bindings/js/JSStorageCustom.cpp:
  • bindings/js/JSStyleSheetCustom.cpp:
  • bindings/js/JSStyleSheetListCustom.cpp:
  • bindings/js/JSTextCustom.cpp:
  • bindings/js/JSTreeWalkerCustom.cpp:
  • bindings/js/JSXMLHttpRequestConstructor.cpp:
  • bindings/js/JSXMLHttpRequestConstructor.h: (WebCore::JSXMLHttpRequestConstructor::classInfo):
  • bindings/js/JSXMLHttpRequestCustom.cpp:
  • bindings/js/JSXMLHttpRequestUploadCustom.cpp:
  • bindings/js/JSXSLTProcessorConstructor.cpp:
  • bindings/js/JSXSLTProcessorConstructor.h: (WebCore::JSXSLTProcessorConstructor::classInfo):
  • bindings/js/JSXSLTProcessorCustom.cpp:
  • bindings/js/ScheduledAction.cpp:
  • bindings/js/ScheduledAction.h:
  • bindings/js/ScriptController.cpp: (WebCore::ScriptController::attachDebugger): (WebCore::ScriptController::windowScriptNPObject):
  • bindings/js/ScriptController.h:
  • bindings/js/ScriptControllerGtk.cpp: (WebCore::ScriptController::createScriptInstanceForWidget):
  • bindings/js/ScriptControllerMac.mm: (WebCore::ScriptController::createScriptInstanceForWidget): (WebCore::ScriptController::windowScriptObject): (WebCore::ScriptController::clearPlatformScriptObjects): (WebCore::updateRenderingForBindings): (WebCore::ScriptController::initJavaJSBindings):
  • bindings/js/ScriptControllerQt.cpp: (WebCore::ScriptController::createScriptInstanceForWidget):
  • bindings/js/ScriptControllerWin.cpp: (WebCore::ScriptController::createScriptInstanceForWidget):
  • bindings/js/ScriptControllerWx.cpp: (WebCore::ScriptController::createScriptInstanceForWidget):
  • bindings/js/StringSourceProvider.h: (WebCore::StringSourceProvider::getRange):
  • bindings/objc/DOM.mm: (-[DOMNode JSC::Bindings::]):
  • bindings/objc/DOMInternal.h:
  • bindings/objc/DOMInternal.mm: (-[WebScriptObject _initializeScriptDOMNodeImp]):
  • bindings/objc/DOMUtility.mm: (JSC::createDOMWrapper): (WebCore::createDOMWrapper):
  • bindings/objc/WebScriptObject.mm: (WebCore::createJSWrapper): (-[WebScriptObject _initWithJSObject:JSC::originRootObject:JSC::Bindings::rootObject:JSC::Bindings::]):
  • bindings/objc/WebScriptObjectPrivate.h:
  • bindings/scripts/CodeGeneratorJS.pm:
  • bridge/NP_jsobject.cpp:
  • bridge/NP_jsobject.h:
  • bridge/c/c_class.cpp:
  • bridge/c/c_class.h:
  • bridge/c/c_instance.cpp:
  • bridge/c/c_instance.h:
  • bridge/c/c_runtime.cpp:
  • bridge/c/c_runtime.h:
  • bridge/c/c_utility.cpp:
  • bridge/c/c_utility.h:
  • bridge/jni/jni_class.cpp:
  • bridge/jni/jni_class.h:
  • bridge/jni/jni_instance.cpp:
  • bridge/jni/jni_instance.h:
  • bridge/jni/jni_jsobject.h:
  • bridge/jni/jni_jsobject.mm: (JavaJSObject::call): (JavaJSObject::convertJObjectToValue):
  • bridge/jni/jni_objc.mm: (JSC::Bindings::dispatchJNICall):
  • bridge/jni/jni_runtime.cpp:
  • bridge/jni/jni_runtime.h:
  • bridge/jni/jni_utility.cpp:
  • bridge/jni/jni_utility.h:
  • bridge/npruntime.cpp: (_NPN_GetStringIdentifier):
  • bridge/objc/WebScriptObject.h:
  • bridge/objc/objc_class.h:
  • bridge/objc/objc_class.mm:
  • bridge/objc/objc_instance.h:
  • bridge/objc/objc_instance.mm:
  • bridge/objc/objc_runtime.h:
  • bridge/objc/objc_runtime.mm:
  • bridge/objc/objc_utility.h:
  • bridge/objc/objc_utility.mm:
  • bridge/qt/qt_class.cpp:
  • bridge/qt/qt_class.h:
  • bridge/qt/qt_instance.cpp:
  • bridge/qt/qt_instance.h:
  • bridge/qt/qt_runtime.cpp: (JSC::Bindings::convertQVariantToValue): (JSC::Bindings::):
  • bridge/qt/qt_runtime.h:
  • bridge/runtime.cpp:
  • bridge/runtime.h:
  • bridge/runtime_array.cpp:
  • bridge/runtime_array.h:
  • bridge/runtime_method.cpp:
  • bridge/runtime_method.h:
  • bridge/runtime_object.cpp:
  • bridge/runtime_object.h:
  • bridge/runtime_root.cpp: (JSC::Bindings::RootObject::invalidate): (JSC::Bindings::RootObject::gcProtect): (JSC::Bindings::RootObject::gcUnprotect):
  • bridge/runtime_root.h:
  • bridge/testbindings.cpp:
  • bridge/testbindings.mm:
  • bridge/testqtbindings.cpp:
  • dom/Document.cpp: (WebCore::Document::~Document):
  • dom/NSResolver.h:
  • dom/Node.cpp: (WebCore::Node::setDocument): (WebCore::ResolveNamespaceFunctor::ResolveNamespaceFunctor): (WebCore::resolveNamespacesForSelector): (WebCore::Node::querySelector): (WebCore::Node::querySelectorAll):
  • dom/Node.h:
  • dom/NodeFilter.cpp:
  • dom/NodeFilter.h:
  • dom/NodeFilterCondition.cpp:
  • dom/NodeFilterCondition.h:
  • dom/NodeIterator.cpp:
  • dom/NodeIterator.h:
  • dom/Traversal.cpp:
  • dom/Traversal.h:
  • dom/TreeWalker.cpp:
  • dom/TreeWalker.h:
  • dom/make_names.pl:
  • history/CachedPage.cpp:
  • history/CachedPage.h:
  • html/HTMLPlugInElement.cpp: (WebCore::HTMLPlugInElement::getInstance):
  • html/HTMLPlugInElement.h:
  • loader/FrameLoader.cpp:
  • loader/FrameLoader.h:
  • loader/icon/IconDatabase.cpp: (WebCore::iconDatabase):
  • page/Console.cpp:
  • page/Console.h:
  • page/InspectorController.cpp: (WebCore::XMLHttpRequestResource::XMLHttpRequestResource): (WebCore::XMLHttpRequestResource::~XMLHttpRequestResource): (WebCore::InspectorResource::setXMLHttpRequestProperties): (WebCore::InspectorResource::sourceString): (WebCore::getResourceDocumentNode): (WebCore::search): (WebCore::InspectorController::focusNode): (WebCore::InspectorController::inspectedWindowScriptObjectCleared): (WebCore::InspectorController::addDatabaseScriptResource): (WebCore::InspectorController::resourceRetrievedByXMLHttpRequest):
  • page/InspectorController.h: (WebCore::InspectorController::profiles):
  • page/JavaScriptCallFrame.cpp: (WebCore::JavaScriptCallFrame::scopeChain):
  • page/JavaScriptCallFrame.h: (WebCore::JavaScriptCallFrame::create): (WebCore::JavaScriptCallFrame::update):
  • page/JavaScriptDebugListener.h:
  • page/JavaScriptDebugServer.cpp: (WebCore::dispatchDidParseSource):
  • page/JavaScriptDebugServer.h:
  • page/JavaScriptProfile.cpp:
  • page/JavaScriptProfile.h:
  • page/JavaScriptProfileNode.cpp: (WebCore::getTotalTime): (WebCore::getSelfTime): (WebCore::getTotalPercent): (WebCore::getSelfPercent): (WebCore::getNumberOfCalls): (WebCore::getChildren): (WebCore::getVisible):
  • page/JavaScriptProfileNode.h:
  • page/Page.cpp: (WebCore::Page::setDebuggerForAllPages): (WebCore::Page::setDebugger):
  • page/Page.h: (WebCore::Page::debugger):
  • page/mac/FrameMac.mm:
  • platform/KURL.h: (WebCore::KURL::operator JSC::UString):
  • platform/text/AtomicString.cpp: (WebCore::AtomicString::add): (WebCore::AtomicString::find):
  • platform/text/AtomicString.h: (WebCore::AtomicString::AtomicString):
  • platform/text/PlatformString.h:
  • platform/text/String.cpp: (WebCore::charactersToDouble):
  • platform/win/BString.cpp:
  • platform/win/BString.h:
  • plugins/MimeTypeArray.h:
  • plugins/Plugin.h:
  • plugins/PluginArray.h:
  • plugins/PluginView.cpp: (WebCore::PluginView::start): (WebCore::PluginView::performRequest): (WebCore::PluginView::bindingInstance):
  • plugins/PluginView.h:
  • plugins/gtk/PluginViewGtk.cpp: (WebCore::PluginView::paint): (WebCore::PluginView::handleKeyboardEvent): (WebCore::PluginView::handleMouseEvent): (WebCore::PluginView::setNPWindowRect): (WebCore::PluginView::stop): (WebCore::PluginView::init):
  • plugins/qt/PluginViewQt.cpp: (WebCore::PluginView::setNPWindowRect): (WebCore::PluginView::stop): (WebCore::PluginView::init):
  • plugins/win/PluginViewWin.cpp: (WebCore::PluginView::dispatchNPEvent): (WebCore::PluginView::handleKeyboardEvent): (WebCore::PluginView::handleMouseEvent): (WebCore::PluginView::setNPWindowRect): (WebCore::PluginView::stop):
  • storage/Database.cpp: (WebCore::Database::Database):
  • xml/XMLHttpRequest.cpp: (WebCore::XMLHttpRequest::responseText): (WebCore::XMLHttpRequest::loadRequestAsynchronously): (WebCore::XMLHttpRequest::clearResponse): (WebCore::XMLHttpRequest::dropProtection): (WebCore::XMLHttpRequest::didFinishLoading): (WebCore::XMLHttpRequest::didReceiveData):
  • xml/XMLHttpRequest.h:

WebKit/gtk:

  • webkit/webkitprivate.cpp: (webkit_init):

WebKit/mac:

  • Misc/WebCoreStatistics.mm:
  • Plugins/WebBaseNetscapePluginStream.mm: (-[WebBaseNetscapePluginStream wantsAllStreams]):
  • Plugins/WebBaseNetscapePluginView.mm: (-[WebBaseNetscapePluginView sendEvent:isDrawRect:]): (-[WebBaseNetscapePluginView setWindowIfNecessary]): (-[WebBaseNetscapePluginView start]): (-[WebBaseNetscapePluginView createPluginScriptableObject]): (-[WebBaseNetscapePluginView evaluateJavaScriptPluginRequest:]): (-[WebBaseNetscapePluginView webFrame:didFinishLoadWithReason:]): (-[WebBaseNetscapePluginView loadPluginRequest:]): (-[WebBaseNetscapePluginView _printedPluginBitmap]):
  • Plugins/WebPluginController.mm: (+[WebPluginController plugInViewWithArguments:fromPluginPackage:]): (-[WebPluginController startAllPlugins]): (-[WebPluginController stopAllPlugins]): (-[WebPluginController addPlugin:]): (-[WebPluginController destroyPlugin:]): (-[WebPluginController destroyAllPlugins]):
  • WebView/WebFrame.mm:
  • WebView/WebScriptDebugDelegate.mm:
  • WebView/WebScriptDebugger.h:
  • WebView/WebScriptDebugger.mm:
  • WebView/WebView.mm: (-[WebViewPrivate init]):

WebKit/qt:


  • Api/qwebframe.cpp: (QWebFrame::addToJavaScriptWindowObject): (QWebFrame::evaluateJavaScript):

WebKit/win:

  • WebCoreStatistics.cpp:
  • WebJavaScriptCollector.cpp:
  • WebScriptCallFrame.cpp: (WebScriptCallFrame::jsValueToString):
  • WebScriptCallFrame.h: (WebScriptCallFrame::state):
  • WebView.cpp: (WebView::WebView): (WebView::stringByEvaluatingJavaScriptFromString):

WebKit/wx:

  • WebFrame.cpp: (wxWebFrame::RunScript):
  • Property svn:eol-style set to native
File size: 27.8 KB
Line 
1/*
2 * Copyright (C) 1999-2000 Harri Porten ([email protected])
3 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
4 *
5 * The Original Code is Mozilla Communicator client code, released
6 * March 31, 1998.
7 *
8 * The Initial Developer of the Original Code is
9 * Netscape Communications Corporation.
10 * Portions created by the Initial Developer are Copyright (C) 1998
11 * the Initial Developer. All Rights Reserved.
12 *
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
17 *
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 *
27 * Alternatively, the contents of this file may be used under the terms
28 * of either the Mozilla Public License Version 1.1, found at
29 * http://www.mozilla.org/MPL/ (the "MPL") or the GNU General Public
30 * License Version 2.0, found at http://www.fsf.org/copyleft/gpl.html
31 * (the "GPL"), in which case the provisions of the MPL or the GPL are
32 * applicable instead of those above. If you wish to allow use of your
33 * version of this file only under the terms of one of those two
34 * licenses (the MPL or the GPL) and not to allow others to use your
35 * version of this file under the LGPL, indicate your decision by
36 * deletingthe provisions above and replace them with the notice and
37 * other provisions required by the MPL or the GPL, as the case may be.
38 * If you do not delete the provisions above, a recipient may use your
39 * version of this file under any of the LGPL, the MPL or the GPL.
40 */
41
42#include "config.h"
43#include "DateMath.h"
44
45#include "JSNumberCell.h"
46#include <math.h>
47#include <stdint.h>
48#include <time.h>
49#include <wtf/ASCIICType.h>
50#include <wtf/Assertions.h>
51#include <wtf/MathExtras.h>
52#include <wtf/StringExtras.h>
53
54#if HAVE(ERRNO_H)
55#include <errno.h>
56#endif
57
58#if PLATFORM(DARWIN)
59#include <notify.h>
60#endif
61
62#if HAVE(SYS_TIME_H)
63#include <sys/time.h>
64#endif
65
66#if HAVE(SYS_TIMEB_H)
67#include <sys/timeb.h>
68#endif
69
70using namespace WTF;
71
72namespace JSC {
73
74/* Constants */
75
76static const double minutesPerDay = 24.0 * 60.0;
77static const double secondsPerDay = 24.0 * 60.0 * 60.0;
78static const double secondsPerYear = 24.0 * 60.0 * 60.0 * 365.0;
79
80static const double usecPerSec = 1000000.0;
81
82static const double maxUnixTime = 2145859200.0; // 12/31/2037
83
84// Day of year for the first day of each month, where index 0 is January, and day 0 is January 1.
85// First for non-leap years, then for leap years.
86static const int firstDayOfMonth[2][12] = {
87 {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334},
88 {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}
89};
90
91static inline bool isLeapYear(int year)
92{
93 if (year % 4 != 0)
94 return false;
95 if (year % 400 == 0)
96 return true;
97 if (year % 100 == 0)
98 return false;
99 return true;
100}
101
102static inline int daysInYear(int year)
103{
104 return 365 + isLeapYear(year);
105}
106
107static inline double daysFrom1970ToYear(int year)
108{
109 // The Gregorian Calendar rules for leap years:
110 // Every fourth year is a leap year. 2004, 2008, and 2012 are leap years.
111 // However, every hundredth year is not a leap year. 1900 and 2100 are not leap years.
112 // Every four hundred years, there's a leap year after all. 2000 and 2400 are leap years.
113
114 static const int leapDaysBefore1971By4Rule = 1970 / 4;
115 static const int excludedLeapDaysBefore1971By100Rule = 1970 / 100;
116 static const int leapDaysBefore1971By400Rule = 1970 / 400;
117
118 const double yearMinusOne = year - 1;
119 const double yearsToAddBy4Rule = floor(yearMinusOne / 4.0) - leapDaysBefore1971By4Rule;
120 const double yearsToExcludeBy100Rule = floor(yearMinusOne / 100.0) - excludedLeapDaysBefore1971By100Rule;
121 const double yearsToAddBy400Rule = floor(yearMinusOne / 400.0) - leapDaysBefore1971By400Rule;
122
123 return 365.0 * (year - 1970) + yearsToAddBy4Rule - yearsToExcludeBy100Rule + yearsToAddBy400Rule;
124}
125
126static inline double msToDays(double ms)
127{
128 return floor(ms / msPerDay);
129}
130
131static inline int msToYear(double ms)
132{
133 int approxYear = static_cast<int>(floor(ms / (msPerDay * 365.2425)) + 1970);
134 double msFromApproxYearTo1970 = msPerDay * daysFrom1970ToYear(approxYear);
135 if (msFromApproxYearTo1970 > ms)
136 return approxYear - 1;
137 if (msFromApproxYearTo1970 + msPerDay * daysInYear(approxYear) <= ms)
138 return approxYear + 1;
139 return approxYear;
140}
141
142static inline int dayInYear(double ms, int year)
143{
144 return static_cast<int>(msToDays(ms) - daysFrom1970ToYear(year));
145}
146
147static inline double msToMilliseconds(double ms)
148{
149 double result = fmod(ms, msPerDay);
150 if (result < 0)
151 result += msPerDay;
152 return result;
153}
154
155// 0: Sunday, 1: Monday, etc.
156static inline int msToWeekDay(double ms)
157{
158 int wd = (static_cast<int>(msToDays(ms)) + 4) % 7;
159 if (wd < 0)
160 wd += 7;
161 return wd;
162}
163
164static inline int msToSeconds(double ms)
165{
166 double result = fmod(floor(ms / msPerSecond), secondsPerMinute);
167 if (result < 0)
168 result += secondsPerMinute;
169 return static_cast<int>(result);
170}
171
172static inline int msToMinutes(double ms)
173{
174 double result = fmod(floor(ms / msPerMinute), minutesPerHour);
175 if (result < 0)
176 result += minutesPerHour;
177 return static_cast<int>(result);
178}
179
180static inline int msToHours(double ms)
181{
182 double result = fmod(floor(ms/msPerHour), hoursPerDay);
183 if (result < 0)
184 result += hoursPerDay;
185 return static_cast<int>(result);
186}
187
188static inline int monthFromDayInYear(int dayInYear, bool leapYear)
189{
190 const int d = dayInYear;
191 int step;
192
193 if (d < (step = 31))
194 return 0;
195 step += (leapYear ? 29 : 28);
196 if (d < step)
197 return 1;
198 if (d < (step += 31))
199 return 2;
200 if (d < (step += 30))
201 return 3;
202 if (d < (step += 31))
203 return 4;
204 if (d < (step += 30))
205 return 5;
206 if (d < (step += 31))
207 return 6;
208 if (d < (step += 31))
209 return 7;
210 if (d < (step += 30))
211 return 8;
212 if (d < (step += 31))
213 return 9;
214 if (d < (step += 30))
215 return 10;
216 return 11;
217}
218
219static inline bool checkMonth(int dayInYear, int& startDayOfThisMonth, int& startDayOfNextMonth, int daysInThisMonth)
220{
221 startDayOfThisMonth = startDayOfNextMonth;
222 startDayOfNextMonth += daysInThisMonth;
223 return (dayInYear <= startDayOfNextMonth);
224}
225
226static inline int dayInMonthFromDayInYear(int dayInYear, bool leapYear)
227{
228 const int d = dayInYear;
229 int step;
230 int next = 30;
231
232 if (d <= next)
233 return d + 1;
234 const int daysInFeb = (leapYear ? 29 : 28);
235 if (checkMonth(d, step, next, daysInFeb))
236 return d - step;
237 if (checkMonth(d, step, next, 31))
238 return d - step;
239 if (checkMonth(d, step, next, 30))
240 return d - step;
241 if (checkMonth(d, step, next, 31))
242 return d - step;
243 if (checkMonth(d, step, next, 30))
244 return d - step;
245 if (checkMonth(d, step, next, 31))
246 return d - step;
247 if (checkMonth(d, step, next, 31))
248 return d - step;
249 if (checkMonth(d, step, next, 30))
250 return d - step;
251 if (checkMonth(d, step, next, 31))
252 return d - step;
253 if (checkMonth(d, step, next, 30))
254 return d - step;
255 step = next;
256 return d - step;
257}
258
259static inline int monthToDayInYear(int month, bool isLeapYear)
260{
261 return firstDayOfMonth[isLeapYear][month];
262}
263
264static inline double timeToMS(double hour, double min, double sec, double ms)
265{
266 return (((hour * minutesPerHour + min) * secondsPerMinute + sec) * msPerSecond + ms);
267}
268
269static int dateToDayInYear(int year, int month, int day)
270{
271 year += month / 12;
272
273 month %= 12;
274 if (month < 0) {
275 month += 12;
276 --year;
277 }
278
279 int yearday = static_cast<int>(floor(daysFrom1970ToYear(year)));
280 int monthday = monthToDayInYear(month, isLeapYear(year));
281
282 return yearday + monthday + day - 1;
283}
284
285double getCurrentUTCTime()
286{
287 return floor(getCurrentUTCTimeWithMicroseconds());
288}
289
290double getCurrentUTCTimeWithMicroseconds()
291{
292#if PLATFORM(WIN_OS)
293 // FIXME: the implementation for Windows is only millisecond resolution.
294#if COMPILER(BORLAND)
295 struct timeb timebuffer;
296 ftime(&timebuffer);
297#else
298 struct _timeb timebuffer;
299 _ftime(&timebuffer);
300#endif
301 double utc = timebuffer.time * msPerSecond + timebuffer.millitm;
302#else
303 struct timeval tv;
304 gettimeofday(&tv, 0);
305 double utc = tv.tv_sec * msPerSecond + tv.tv_usec / 1000.0;
306#endif
307 return utc;
308}
309
310void getLocalTime(const time_t* localTime, struct tm* localTM)
311{
312#if COMPILER(MSVC7) || COMPILER(MINGW)
313 *localTM = *localtime(localTime);
314#elif COMPILER(MSVC)
315 localtime_s(localTM, localTime);
316#else
317 localtime_r(localTime, localTM);
318#endif
319}
320
321// There is a hard limit at 2038 that we currently do not have a workaround
322// for (rdar://problem/5052975).
323static inline int maximumYearForDST()
324{
325 return 2037;
326}
327
328static inline int mimimumYearForDST()
329{
330 // Because of the 2038 issue (see maximumYearForDST) if the current year is
331 // greater than the max year minus 27 (2010), we want to use the max year
332 // minus 27 instead, to ensure there is a range of 28 years that all years
333 // can map to.
334 return std::min(msToYear(getCurrentUTCTime()), maximumYearForDST() - 27) ;
335}
336
337/*
338 * Find an equivalent year for the one given, where equivalence is deterined by
339 * the two years having the same leapness and the first day of the year, falling
340 * on the same day of the week.
341 *
342 * This function returns a year between this current year and 2037, however this
343 * function will potentially return incorrect results if the current year is after
344 * 2010, (rdar://problem/5052975), if the year passed in is before 1900 or after
345 * 2100, (rdar://problem/5055038).
346 */
347int equivalentYearForDST(int year)
348{
349 // It is ok if the cached year is not the current year as long as the rules
350 // for DST did not change between the two years; if they did the app would need
351 // to be restarted.
352 static int minYear = mimimumYearForDST();
353 int maxYear = maximumYearForDST();
354
355 int difference;
356 if (year > maxYear)
357 difference = minYear - year;
358 else if (year < minYear)
359 difference = maxYear - year;
360 else
361 return year;
362
363 int quotient = difference / 28;
364 int product = (quotient) * 28;
365
366 year += product;
367 ASSERT((year >= minYear && year <= maxYear) || (product - year == static_cast<int>(NaN)));
368 return year;
369}
370
371static int32_t calculateUTCOffset()
372{
373 tm localt;
374 memset(&localt, 0, sizeof(localt));
375
376 // get the difference between this time zone and UTC on Jan 01, 2000 12:00:00 AM
377 localt.tm_mday = 1;
378 localt.tm_year = 100;
379 time_t utcOffset = 946684800 - mktime(&localt);
380
381 return static_cast<int32_t>(utcOffset * 1000);
382}
383
384#if PLATFORM(DARWIN)
385static int32_t s_cachedUTCOffset; // In milliseconds. An assumption here is that access to an int32_t variable is atomic on platforms that take this code path.
386static bool s_haveCachedUTCOffset;
387static int s_notificationToken;
388#endif
389
390/*
391 * Get the difference in milliseconds between this time zone and UTC (GMT)
392 * NOT including DST.
393 */
394double getUTCOffset()
395{
396#if PLATFORM(DARWIN)
397 if (s_haveCachedUTCOffset) {
398 int notified;
399 uint32_t status = notify_check(s_notificationToken, &notified);
400 if (status == NOTIFY_STATUS_OK && !notified)
401 return s_cachedUTCOffset;
402 }
403#endif
404
405 int32_t utcOffset = calculateUTCOffset();
406
407#if PLATFORM(DARWIN)
408 // Theoretically, it is possible that several threads will be executing this code at once, in which case we will have a race condition,
409 // and a newer value may be overwritten. In practice, time zones don't change that often.
410 s_cachedUTCOffset = utcOffset;
411#endif
412
413 return utcOffset;
414}
415
416/*
417 * Get the DST offset for the time passed in. Takes
418 * seconds (not milliseconds) and cannot handle dates before 1970
419 * on some OS'
420 */
421static double getDSTOffsetSimple(double localTimeSeconds, double utcOffset)
422{
423 if (localTimeSeconds > maxUnixTime)
424 localTimeSeconds = maxUnixTime;
425 else if (localTimeSeconds < 0) // Go ahead a day to make localtime work (does not work with 0)
426 localTimeSeconds += secondsPerDay;
427
428 //input is UTC so we have to shift back to local time to determine DST thus the + getUTCOffset()
429 double offsetTime = (localTimeSeconds * msPerSecond) + utcOffset;
430
431 // Offset from UTC but doesn't include DST obviously
432 int offsetHour = msToHours(offsetTime);
433 int offsetMinute = msToMinutes(offsetTime);
434
435 // FIXME: time_t has a potential problem in 2038
436 time_t localTime = static_cast<time_t>(localTimeSeconds);
437
438 tm localTM;
439 getLocalTime(&localTime, &localTM);
440
441 double diff = ((localTM.tm_hour - offsetHour) * secondsPerHour) + ((localTM.tm_min - offsetMinute) * 60);
442
443 if (diff < 0)
444 diff += secondsPerDay;
445
446 return (diff * msPerSecond);
447}
448
449// Get the DST offset, given a time in UTC
450static double getDSTOffset(double ms, double utcOffset)
451{
452 // On Mac OS X, the call to localtime (see getDSTOffsetSimple) will return historically accurate
453 // DST information (e.g. New Zealand did not have DST from 1946 to 1974) however the JavaScript
454 // standard explicitly dictates that historical information should not be considered when
455 // determining DST. For this reason we shift away from years that localtime can handle but would
456 // return historically accurate information.
457 int year = msToYear(ms);
458 int equivalentYear = equivalentYearForDST(year);
459 if (year != equivalentYear) {
460 bool leapYear = isLeapYear(year);
461 int dayInYearLocal = dayInYear(ms, year);
462 int dayInMonth = dayInMonthFromDayInYear(dayInYearLocal, leapYear);
463 int month = monthFromDayInYear(dayInYearLocal, leapYear);
464 int day = dateToDayInYear(equivalentYear, month, dayInMonth);
465 ms = (day * msPerDay) + msToMilliseconds(ms);
466 }
467
468 return getDSTOffsetSimple(ms / msPerSecond, utcOffset);
469}
470
471double gregorianDateTimeToMS(const GregorianDateTime& t, double milliSeconds, bool inputIsUTC)
472{
473 int day = dateToDayInYear(t.year + 1900, t.month, t.monthDay);
474 double ms = timeToMS(t.hour, t.minute, t.second, milliSeconds);
475 double result = (day * msPerDay) + ms;
476
477 if (!inputIsUTC) { // convert to UTC
478 double utcOffset = getUTCOffset();
479 result -= utcOffset;
480 result -= getDSTOffset(result, utcOffset);
481 }
482
483 return result;
484}
485
486void msToGregorianDateTime(double ms, bool outputIsUTC, GregorianDateTime& tm)
487{
488 // input is UTC
489 double dstOff = 0.0;
490 const double utcOff = getUTCOffset();
491
492 if (!outputIsUTC) { // convert to local time
493 dstOff = getDSTOffset(ms, utcOff);
494 ms += dstOff + utcOff;
495 }
496
497 const int year = msToYear(ms);
498 tm.second = msToSeconds(ms);
499 tm.minute = msToMinutes(ms);
500 tm.hour = msToHours(ms);
501 tm.weekDay = msToWeekDay(ms);
502 tm.yearDay = dayInYear(ms, year);
503 tm.monthDay = dayInMonthFromDayInYear(tm.yearDay, isLeapYear(year));
504 tm.month = monthFromDayInYear(tm.yearDay, isLeapYear(year));
505 tm.year = year - 1900;
506 tm.isDST = dstOff != 0.0;
507
508 tm.utcOffset = static_cast<long>((dstOff + utcOff) / msPerSecond);
509 tm.timeZone = NULL;
510}
511
512void initDateMath()
513{
514#ifndef NDEBUG
515 static bool alreadyInitialized;
516 ASSERT(!alreadyInitialized++);
517#endif
518
519 equivalentYearForDST(2000); // Need to call once to initialize a static used in this function.
520#if PLATFORM(DARWIN)
521 // Register for a notification whenever the time zone changes.
522 uint32_t status = notify_register_check("com.apple.system.timezone", &s_notificationToken);
523 if (status == NOTIFY_STATUS_OK) {
524 s_cachedUTCOffset = calculateUTCOffset();
525 s_haveCachedUTCOffset = true;
526 }
527#endif
528}
529
530static inline double ymdhmsToSeconds(long year, int mon, int day, int hour, int minute, int second)
531{
532 double days = (day - 32075)
533 + floor(1461 * (year + 4800.0 + (mon - 14) / 12) / 4)
534 + 367 * (mon - 2 - (mon - 14) / 12 * 12) / 12
535 - floor(3 * ((year + 4900.0 + (mon - 14) / 12) / 100) / 4)
536 - 2440588;
537 return ((days * hoursPerDay + hour) * minutesPerHour + minute) * secondsPerMinute + second;
538}
539
540// We follow the recommendation of RFC 2822 to consider all
541// obsolete time zones not listed here equivalent to "-0000".
542static const struct KnownZone {
543#if !PLATFORM(WIN_OS)
544 const
545#endif
546 char tzName[4];
547 int tzOffset;
548} known_zones[] = {
549 { "UT", 0 },
550 { "GMT", 0 },
551 { "EST", -300 },
552 { "EDT", -240 },
553 { "CST", -360 },
554 { "CDT", -300 },
555 { "MST", -420 },
556 { "MDT", -360 },
557 { "PST", -480 },
558 { "PDT", -420 }
559};
560
561inline static void skipSpacesAndComments(const char*& s)
562{
563 int nesting = 0;
564 char ch;
565 while ((ch = *s)) {
566 if (!isASCIISpace(ch)) {
567 if (ch == '(')
568 nesting++;
569 else if (ch == ')' && nesting > 0)
570 nesting--;
571 else if (nesting == 0)
572 break;
573 }
574 s++;
575 }
576}
577
578// returns 0-11 (Jan-Dec); -1 on failure
579static int findMonth(const char* monthStr)
580{
581 ASSERT(monthStr);
582 char needle[4];
583 for (int i = 0; i < 3; ++i) {
584 if (!*monthStr)
585 return -1;
586 needle[i] = static_cast<char>(toASCIILower(*monthStr++));
587 }
588 needle[3] = '\0';
589 const char *haystack = "janfebmaraprmayjunjulaugsepoctnovdec";
590 const char *str = strstr(haystack, needle);
591 if (str) {
592 int position = static_cast<int>(str - haystack);
593 if (position % 3 == 0)
594 return position / 3;
595 }
596 return -1;
597}
598
599double parseDate(const UString &date)
600{
601 // This parses a date in the form:
602 // Tuesday, 09-Nov-99 23:12:40 GMT
603 // or
604 // Sat, 01-Jan-2000 08:00:00 GMT
605 // or
606 // Sat, 01 Jan 2000 08:00:00 GMT
607 // or
608 // 01 Jan 99 22:00 +0100 (exceptions in rfc822/rfc2822)
609 // ### non RFC formats, added for Javascript:
610 // [Wednesday] January 09 1999 23:12:40 GMT
611 // [Wednesday] January 09 23:12:40 GMT 1999
612 //
613 // We ignore the weekday.
614
615 CString dateCString = date.UTF8String();
616 const char *dateString = dateCString.c_str();
617
618 // Skip leading space
619 skipSpacesAndComments(dateString);
620
621 long month = -1;
622 const char *wordStart = dateString;
623 // Check contents of first words if not number
624 while (*dateString && !isASCIIDigit(*dateString)) {
625 if (isASCIISpace(*dateString) || *dateString == '(') {
626 if (dateString - wordStart >= 3)
627 month = findMonth(wordStart);
628 skipSpacesAndComments(dateString);
629 wordStart = dateString;
630 } else
631 dateString++;
632 }
633
634 // Missing delimiter between month and day (like "January29")?
635 if (month == -1 && wordStart != dateString)
636 month = findMonth(wordStart);
637
638 skipSpacesAndComments(dateString);
639
640 if (!*dateString)
641 return NaN;
642
643 // ' 09-Nov-99 23:12:40 GMT'
644 char *newPosStr;
645 errno = 0;
646 long day = strtol(dateString, &newPosStr, 10);
647 if (errno)
648 return NaN;
649 dateString = newPosStr;
650
651 if (!*dateString)
652 return NaN;
653
654 if (day < 0)
655 return NaN;
656
657 long year = 0;
658 if (day > 31) {
659 // ### where is the boundary and what happens below?
660 if (*dateString != '/')
661 return NaN;
662 // looks like a YYYY/MM/DD date
663 if (!*++dateString)
664 return NaN;
665 year = day;
666 month = strtol(dateString, &newPosStr, 10) - 1;
667 if (errno)
668 return NaN;
669 dateString = newPosStr;
670 if (*dateString++ != '/' || !*dateString)
671 return NaN;
672 day = strtol(dateString, &newPosStr, 10);
673 if (errno)
674 return NaN;
675 dateString = newPosStr;
676 } else if (*dateString == '/' && month == -1) {
677 dateString++;
678 // This looks like a MM/DD/YYYY date, not an RFC date.
679 month = day - 1; // 0-based
680 day = strtol(dateString, &newPosStr, 10);
681 if (errno)
682 return NaN;
683 if (day < 1 || day > 31)
684 return NaN;
685 dateString = newPosStr;
686 if (*dateString == '/')
687 dateString++;
688 if (!*dateString)
689 return NaN;
690 } else {
691 if (*dateString == '-')
692 dateString++;
693
694 skipSpacesAndComments(dateString);
695
696 if (*dateString == ',')
697 dateString++;
698
699 if (month == -1) { // not found yet
700 month = findMonth(dateString);
701 if (month == -1)
702 return NaN;
703
704 while (*dateString && *dateString != '-' && *dateString != ',' && !isASCIISpace(*dateString))
705 dateString++;
706
707 if (!*dateString)
708 return NaN;
709
710 // '-99 23:12:40 GMT'
711 if (*dateString != '-' && *dateString != '/' && *dateString != ',' && !isASCIISpace(*dateString))
712 return NaN;
713 dateString++;
714 }
715 }
716
717 if (month < 0 || month > 11)
718 return NaN;
719
720 // '99 23:12:40 GMT'
721 if (year <= 0 && *dateString) {
722 year = strtol(dateString, &newPosStr, 10);
723 if (errno)
724 return NaN;
725 }
726
727 // Don't fail if the time is missing.
728 long hour = 0;
729 long minute = 0;
730 long second = 0;
731 if (!*newPosStr)
732 dateString = newPosStr;
733 else {
734 // ' 23:12:40 GMT'
735 if (!(isASCIISpace(*newPosStr) || *newPosStr == ',')) {
736 if (*newPosStr != ':')
737 return NaN;
738 // There was no year; the number was the hour.
739 year = -1;
740 } else {
741 // in the normal case (we parsed the year), advance to the next number
742 dateString = ++newPosStr;
743 skipSpacesAndComments(dateString);
744 }
745
746 hour = strtol(dateString, &newPosStr, 10);
747 // Do not check for errno here since we want to continue
748 // even if errno was set becasue we are still looking
749 // for the timezone!
750
751 // Read a number? If not, this might be a timezone name.
752 if (newPosStr != dateString) {
753 dateString = newPosStr;
754
755 if (hour < 0 || hour > 23)
756 return NaN;
757
758 if (!*dateString)
759 return NaN;
760
761 // ':12:40 GMT'
762 if (*dateString++ != ':')
763 return NaN;
764
765 minute = strtol(dateString, &newPosStr, 10);
766 if (errno)
767 return NaN;
768 dateString = newPosStr;
769
770 if (minute < 0 || minute > 59)
771 return NaN;
772
773 // ':40 GMT'
774 if (*dateString && *dateString != ':' && !isASCIISpace(*dateString))
775 return NaN;
776
777 // seconds are optional in rfc822 + rfc2822
778 if (*dateString ==':') {
779 dateString++;
780
781 second = strtol(dateString, &newPosStr, 10);
782 if (errno)
783 return NaN;
784 dateString = newPosStr;
785
786 if (second < 0 || second > 59)
787 return NaN;
788 }
789
790 skipSpacesAndComments(dateString);
791
792 if (strncasecmp(dateString, "AM", 2) == 0) {
793 if (hour > 12)
794 return NaN;
795 if (hour == 12)
796 hour = 0;
797 dateString += 2;
798 skipSpacesAndComments(dateString);
799 } else if (strncasecmp(dateString, "PM", 2) == 0) {
800 if (hour > 12)
801 return NaN;
802 if (hour != 12)
803 hour += 12;
804 dateString += 2;
805 skipSpacesAndComments(dateString);
806 }
807 }
808 }
809
810 bool haveTZ = false;
811 int offset = 0;
812
813 // Don't fail if the time zone is missing.
814 // Some websites omit the time zone (4275206).
815 if (*dateString) {
816 if (strncasecmp(dateString, "GMT", 3) == 0 || strncasecmp(dateString, "UTC", 3) == 0) {
817 dateString += 3;
818 haveTZ = true;
819 }
820
821 if (*dateString == '+' || *dateString == '-') {
822 long o = strtol(dateString, &newPosStr, 10);
823 if (errno)
824 return NaN;
825 dateString = newPosStr;
826
827 if (o < -9959 || o > 9959)
828 return NaN;
829
830 int sgn = (o < 0) ? -1 : 1;
831 o = abs(o);
832 if (*dateString != ':') {
833 offset = ((o / 100) * 60 + (o % 100)) * sgn;
834 } else { // GMT+05:00
835 long o2 = strtol(dateString, &newPosStr, 10);
836 if (errno)
837 return NaN;
838 dateString = newPosStr;
839 offset = (o * 60 + o2) * sgn;
840 }
841 haveTZ = true;
842 } else {
843 for (int i = 0; i < int(sizeof(known_zones) / sizeof(KnownZone)); i++) {
844 if (0 == strncasecmp(dateString, known_zones[i].tzName, strlen(known_zones[i].tzName))) {
845 offset = known_zones[i].tzOffset;
846 dateString += strlen(known_zones[i].tzName);
847 haveTZ = true;
848 break;
849 }
850 }
851 }
852 }
853
854 skipSpacesAndComments(dateString);
855
856 if (*dateString && year == -1) {
857 year = strtol(dateString, &newPosStr, 10);
858 if (errno)
859 return NaN;
860 dateString = newPosStr;
861 }
862
863 skipSpacesAndComments(dateString);
864
865 // Trailing garbage
866 if (*dateString)
867 return NaN;
868
869 // Y2K: Handle 2 digit years.
870 if (year >= 0 && year < 100) {
871 if (year < 50)
872 year += 2000;
873 else
874 year += 1900;
875 }
876
877 // fall back to local timezone
878 if (!haveTZ) {
879 GregorianDateTime t;
880 t.monthDay = day;
881 t.month = month;
882 t.year = year - 1900;
883 t.isDST = -1;
884 t.second = second;
885 t.minute = minute;
886 t.hour = hour;
887
888 // Use our gregorianDateTimeToMS() rather than mktime() as the latter can't handle the full year range.
889 return gregorianDateTimeToMS(t, 0, false);
890 }
891
892 return (ymdhmsToSeconds(year, month + 1, day, hour, minute, second) - (offset * 60.0)) * msPerSecond;
893}
894
895double timeClip(double t)
896{
897 if (!isfinite(t))
898 return NaN;
899 if (fabs(t) > 8.64E15)
900 return NaN;
901 return trunc(t);
902}
903
904UString formatDate(const GregorianDateTime &t)
905{
906 char buffer[100];
907 snprintf(buffer, sizeof(buffer), "%s %s %02d %04d",
908 weekdayName[(t.weekDay + 6) % 7],
909 monthName[t.month], t.monthDay, t.year + 1900);
910 return buffer;
911}
912
913UString formatDateUTCVariant(const GregorianDateTime &t)
914{
915 char buffer[100];
916 snprintf(buffer, sizeof(buffer), "%s, %02d %s %04d",
917 weekdayName[(t.weekDay + 6) % 7],
918 t.monthDay, monthName[t.month], t.year + 1900);
919 return buffer;
920}
921
922UString formatTime(const GregorianDateTime &t, bool utc)
923{
924 char buffer[100];
925 if (utc) {
926 snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d GMT", t.hour, t.minute, t.second);
927 } else {
928 int offset = abs(gmtoffset(t));
929 char tzname[70];
930 struct tm gtm = t;
931 strftime(tzname, sizeof(tzname), "%Z", &gtm);
932
933 if (tzname[0]) {
934 snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d GMT%c%02d%02d (%s)",
935 t.hour, t.minute, t.second,
936 gmtoffset(t) < 0 ? '-' : '+', offset / (60*60), (offset / 60) % 60, tzname);
937 } else {
938 snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d GMT%c%02d%02d",
939 t.hour, t.minute, t.second,
940 gmtoffset(t) < 0 ? '-' : '+', offset / (60*60), (offset / 60) % 60);
941 }
942 }
943 return UString(buffer);
944}
945
946} // namespace JSC
Note: See TracBrowser for help on using the repository browser.