Skip to content

Commit 6a83d9f

Browse files
committed
Switch over to shared_ptr based Any implementation
src/Object.h : Add std::shared_ptr based Any implementation src/sequence.h (SequenceImp) : New based on Imp class src/sequence.h (Sequence) : Switch over to Object based implementation src/Any.h : Delete src/Any.cpp : Refine org/w3c/dom/ObjectArray.h : Refine src/Reflect.h : Refine src/js/bridge.cpp : Refine src/v8/bridgeV8.cpp : Refine Makefile.am (libeshtml5_a_SOURCES) : Remove Any.h
1 parent 121023c commit 6a83d9f

File tree

10 files changed

+553
-653
lines changed

10 files changed

+553
-653
lines changed

Makefile.am

-1
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,6 @@ libeshtml5_a_SOURCES = \
631631
src/ObjectArrayImp.h \
632632
src/Reflect.h \
633633
src/Any.cpp \
634-
src/Any.h \
635634
src/Variadic.h \
636635
src/nullable.h \
637636
src/sequence.h \

Makefile.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,7 @@ nodist_libeshtml5_a_SOURCES = $(generated_sources) $(generated_headers) $(genera
14251425
# implementation files originally generated by esidl
14261426
libeshtml5_a_SOURCES = org/w3c/dom/ObjectArray.h src/one_at_a_time.hpp \
14271427
src/Object.h src/ObjectArrayImp.h src/Reflect.h src/Any.cpp \
1428-
src/Any.h src/Variadic.h src/nullable.h src/sequence.h \
1428+
src/Variadic.h src/nullable.h src/sequence.h \
14291429
src/ECMAScript.cpp src/ECMAScript.h src/utf.h src/utf.cpp \
14301430
src/TextIterator.h src/U16InputStream.cpp src/U16InputStream.h \
14311431
src/Canvas.h src/CanvasGL.cpp src/CanvasGL.h \

org/w3c/dom/ObjectArray.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011, 2013 Esrille Inc.
2+
* Copyright 2011-2013 Esrille Inc.
33
* Copyright 2010 Google Inc.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -109,9 +109,9 @@ class ObjectArray : public Object
109109
{
110110
return object.message_(0, getPrefixedName(), IS_KIND_OF_, 0).toBoolean();
111111
}
112-
static bool hasInstance(Object* object)
112+
static bool hasInstance(const std::shared_ptr<Imp>& pimpl)
113113
{
114-
return object && object->message_(0, getPrefixedName(), IS_KIND_OF_, 0).toBoolean();
114+
return pimpl && pimpl->message_(0, getPrefixedName(), IS_KIND_OF_, 0).toBoolean();
115115
}
116116
};
117117

src/Any.cpp

+53-75
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ std::u16string toString(double value)
112112
return text;
113113
}
114114

115-
std::u16string toString(Object* object)
115+
std::u16string toString(const std::shared_ptr<Imp>& pimpl)
116116
{
117-
if (!object)
117+
if (!pimpl)
118118
return u"null";
119-
Any result = object->message_(0, 0, Object::STRINGIFY_, 0);
119+
Any result{ pimpl->message_(0, 0, Object::STRINGIFY_, 0) };
120120
if (result.isString())
121121
return result.toString();
122-
return u"";
122+
return std::u16string();
123123
}
124124

125125
double toNumber(const std::u16string& value)
@@ -225,33 +225,27 @@ double toNumber(const std::u16string& value)
225225

226226
} // namespace
227227

228-
bool Any::isString() const
229-
{
230-
return (type == Dynamic) && vtable->getType() == typeid(std::u16string);
231-
}
232-
233228
std::u16string Any::toString() const
234229
{
235230
switch (type) {
236231
case Bool:
237-
return heap.i32 ? u"true" : u"false";
232+
return i32 ? u"true" : u"false";
238233
case Int32:
239-
return ::toString("%d", heap.i32);
234+
return ::toString("%d", i32);
240235
case Uint32:
241-
return ::toString("%u", heap.u32);
236+
return ::toString("%u", u32);
242237
case Int64:
243-
return ::toString("%lld", heap.i64);
238+
return ::toString("%lld", i64);
244239
case Uint64:
245-
return ::toString("%llu", heap.u64);
240+
return ::toString("%llu", u64);
246241
case Float32:
247-
return ::toString(heap.f32);
242+
return ::toString(f32);
248243
case Float64:
249-
return ::toString(heap.f64);
250-
case Dynamic:
251-
if (vtable->getType() == typeid(std::u16string))
252-
return *reinterpret_cast<const std::u16string*>(&heap);
253-
if (vtable->getType() == typeid(Object))
254-
return ::toString(const_cast<Object*>(reinterpret_cast<const Object*>(&heap)));
244+
return ::toString(f64);
245+
case String:
246+
return string;
247+
case Shared:
248+
return ::toString(pimpl);
255249
break;
256250
default:
257251
break;
@@ -269,20 +263,19 @@ double Any::toNumber() const
269263
return NAN;
270264
case Bool:
271265
case Int32:
272-
return heap.i32;
266+
return i32;
273267
case Uint32:
274-
return heap.u32;
268+
return u32;
275269
case Int64:
276-
return heap.i64;
270+
return i64;
277271
case Uint64:
278-
return heap.u64;
272+
return u64;
279273
case Float32:
280-
return heap.f32;
274+
return f32;
281275
case Float64:
282-
return heap.f64;
283-
case Dynamic:
284-
if (vtable->getType() == typeid(std::u16string))
285-
return ::toNumber(*reinterpret_cast<const std::u16string*>(&heap));
276+
return f64;
277+
case String:
278+
return ::toNumber(string);
286279
break;
287280
default:
288281
break;
@@ -298,43 +291,42 @@ unsigned int Any::toArrayIndex() const
298291
case Bool:
299292
break;
300293
case Int32:
301-
if (0 <= heap.i32)
302-
return heap.i32;
294+
if (0 <= i32)
295+
return i32;
303296
break;
304297
case Uint32:
305-
return heap.u32;
298+
return u32;
306299
case Int64:
307-
if (0 <= heap.i64 && heap.i64 < UINT_MAX)
308-
return heap.i64;
300+
if (0 <= i64 && i64 < UINT_MAX)
301+
return i64;
309302
case Uint64:
310-
if (heap.u64 < UINT_MAX)
311-
return heap.u64;
303+
if (u64 < UINT_MAX)
304+
return u64;
312305
break;
313306
case Float32:
314-
if (0.0f <= heap.f32) {
315-
float f = floorf(heap.f32);
316-
if (f == heap.f32 && f < UINT_MAX)
317-
return static_cast<unsigned int>(heap.f32);
307+
if (0.0f <= f32) {
308+
float f = floorf(f32);
309+
if (f == f32 && f < UINT_MAX)
310+
return static_cast<unsigned int>(f32);
318311
}
319312
break;
320313
case Float64:
321-
if (0.0 <= heap.f64) {
322-
double f = floor(heap.f64);
323-
if (f == heap.f64 && f < UINT_MAX)
324-
return static_cast<unsigned int>(heap.f64);
314+
if (0.0 <= f64) {
315+
double f = floor(f64);
316+
if (f == f64 && f < UINT_MAX)
317+
return static_cast<unsigned int>(f64);
325318
}
326319
break;
327320
break;
328-
case Dynamic:
329-
if (vtable->getType() == typeid(std::u16string)) {
330-
double v = ::toNumber(*reinterpret_cast<const std::u16string*>(&heap));
331-
if (0.0 <= v) {
332-
double f = floor(v);
333-
if (f == v && f < UINT_MAX && ::toString(f) == *reinterpret_cast<const std::u16string*>(&heap))
334-
return static_cast<unsigned int>(f);
335-
}
321+
case String: {
322+
double v = ::toNumber(string);
323+
if (0.0 <= v) {
324+
double f = floor(v);
325+
if (f == v && f < UINT_MAX && ::toString(f) == string)
326+
return static_cast<unsigned int>(f);
336327
}
337328
break;
329+
}
338330
default:
339331
break;
340332
}
@@ -350,36 +342,22 @@ bool Any::toBoolean() const
350342
switch (type) {
351343
case Bool:
352344
case Int32:
353-
return heap.i32;
345+
return i32;
354346
case Uint32:
355-
return heap.u32;
347+
return u32;
356348
case Int64:
357-
return heap.i64;
349+
return i64;
358350
case Uint64:
359-
return heap.u64;
351+
return u64;
360352
case Float32:
361-
return heap.f32 && !isnan(heap.f32);
353+
return f32 && !isnan(f32);
362354
case Float64:
363-
return heap.f64 && !isnan(heap.f64);
364-
case Dynamic:
365-
if (vtable->getType() == typeid(std::u16string))
366-
return (*reinterpret_cast<const std::u16string*>(&heap)).length();
367-
return true;
355+
return f64 && !isnan(f64);
356+
case String:
357+
return string.length();
368358
break;
369359
default:
370360
break;
371361
}
372362
return false;
373363
}
374-
375-
bool Any::isObject() const
376-
{
377-
return (type == Dynamic) && vtable->getType() == typeid(Object);
378-
}
379-
380-
Object* Any::toObject() const
381-
{
382-
if (isObject())
383-
return const_cast<Object*>(reinterpret_cast<const Object*>(&heap));
384-
return 0;
385-
}

0 commit comments

Comments
 (0)