Move most IDB object encoding/decoding from WebKit2 to WebCore.
[WebKit.git] / Source / JavaScriptCore / runtime / IntlObject.cpp
1 /*
2  * Copyright (C) 2015 Andy VanWagoner (thetalecrafter@gmail.com)
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "config.h"
27 #include "IntlObject.h"
28
29 #if ENABLE(INTL)
30
31 #include "FunctionPrototype.h"
32 #include "IntlCollator.h"
33 #include "IntlCollatorConstructor.h"
34 #include "IntlCollatorPrototype.h"
35 #include "IntlDateTimeFormat.h"
36 #include "IntlDateTimeFormatConstructor.h"
37 #include "IntlDateTimeFormatPrototype.h"
38 #include "IntlNumberFormat.h"
39 #include "IntlNumberFormatConstructor.h"
40 #include "IntlNumberFormatPrototype.h"
41 #include "JSCInlines.h"
42 #include "Lookup.h"
43 #include "ObjectPrototype.h"
44 #include <wtf/Assertions.h>
45
46 namespace JSC {
47
48 STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(IntlObject);
49
50 }
51
52 namespace JSC {
53
54 const ClassInfo IntlObject::s_info = { "Object", &Base::s_info, 0, CREATE_METHOD_TABLE(IntlObject) };
55
56 IntlObject::IntlObject(VM& vm, Structure* structure)
57     : JSNonFinalObject(vm, structure)
58 {
59 }
60
61 IntlObject* IntlObject::create(VM& vm, JSGlobalObject* globalObject, Structure* structure)
62 {
63     IntlObject* object = new (NotNull, allocateCell<IntlObject>(vm.heap)) IntlObject(vm, structure);
64     object->finishCreation(vm, globalObject);
65     return object;
66 }
67
68 void IntlObject::finishCreation(VM& vm, JSGlobalObject* globalObject)
69 {
70     Base::finishCreation(vm);
71     ASSERT(inherits(info()));
72
73     // Set up Collator.
74     IntlCollatorPrototype* collatorPrototype = IntlCollatorPrototype::create(vm, globalObject, IntlCollatorPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
75     Structure* collatorStructure = IntlCollator::createStructure(vm, globalObject, collatorPrototype);
76     IntlCollatorConstructor* collatorConstructor = IntlCollatorConstructor::create(vm, IntlCollatorConstructor::createStructure(vm, globalObject, globalObject->functionPrototype()), collatorPrototype, collatorStructure);
77
78     collatorPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, collatorConstructor, DontEnum);
79
80     // Set up NumberFormat.
81     IntlNumberFormatPrototype* numberFormatPrototype = IntlNumberFormatPrototype::create(vm, globalObject, IntlNumberFormatPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
82     Structure* numberFormatStructure = IntlNumberFormat::createStructure(vm, globalObject, numberFormatPrototype);
83     IntlNumberFormatConstructor* numberFormatConstructor = IntlNumberFormatConstructor::create(vm, IntlNumberFormatConstructor::createStructure(vm, globalObject, globalObject->functionPrototype()), numberFormatPrototype, numberFormatStructure);
84
85     numberFormatPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, numberFormatConstructor, DontEnum);
86
87     // Set up DateTimeFormat.
88     IntlDateTimeFormatPrototype* dateTimeFormatPrototype = IntlDateTimeFormatPrototype::create(vm, globalObject, IntlDateTimeFormatPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
89     Structure* dateTimeFormatStructure = IntlDateTimeFormat::createStructure(vm, globalObject, dateTimeFormatPrototype);
90     IntlDateTimeFormatConstructor* dateTimeFormatConstructor = IntlDateTimeFormatConstructor::create(vm, IntlDateTimeFormatConstructor::createStructure(vm, globalObject, globalObject->functionPrototype()), dateTimeFormatPrototype, dateTimeFormatStructure);
91
92     dateTimeFormatPrototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, dateTimeFormatConstructor, DontEnum);
93
94     // 8.1 Properties of the Intl Object (ECMA-402 2.0)
95     putDirectWithoutTransition(vm, vm.propertyNames->Collator, collatorConstructor, DontEnum);
96     putDirectWithoutTransition(vm, vm.propertyNames->NumberFormat, numberFormatConstructor, DontEnum);
97     putDirectWithoutTransition(vm, vm.propertyNames->DateTimeFormat, dateTimeFormatConstructor, DontEnum);
98 }
99
100 Structure* IntlObject::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
101 {
102     return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
103 }
104
105 } // namespace JSC
106
107 #endif // ENABLE(INTL)