Title: [158940] trunk/Source/_javascript_Core
Revision
158940
Author
oli...@apple.com
Date
2013-11-08 12:27:55 -0800 (Fri, 08 Nov 2013)

Log Message

Fix minor (unobservable) bug in ArrayIterator::next()
https://bugs.webkit.org/show_bug.cgi?id=124061

Reviewed by Beth Dakin.

I noticed this while reading the array iterator code.  Due to how
ArrayIterator::next() and our enumeration behaviour is implemented
this is not actually a code path that can be hit.  But in order to
future proof this it should be correct.

* runtime/JSArrayIterator.cpp:
(JSC::arrayIteratorNext):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (158939 => 158940)


--- trunk/Source/_javascript_Core/ChangeLog	2013-11-08 20:22:36 UTC (rev 158939)
+++ trunk/Source/_javascript_Core/ChangeLog	2013-11-08 20:27:55 UTC (rev 158940)
@@ -1,3 +1,18 @@
+2013-11-08  Oliver Hunt  <oli...@apple.com>
+
+        Fix minor (unobservable) bug in ArrayIterator::next()
+        https://bugs.webkit.org/show_bug.cgi?id=124061
+
+        Reviewed by Beth Dakin.
+
+        I noticed this while reading the array iterator code.  Due to how
+        ArrayIterator::next() and our enumeration behaviour is implemented
+        this is not actually a code path that can be hit.  But in order to
+        future proof this it should be correct.
+        
+        * runtime/JSArrayIterator.cpp:
+        (JSC::arrayIteratorNext):
+
 2013-11-08  Mark Lam  <mark....@apple.com>
 
         Move breakpoint (and exception break) functionality into JSC::Debugger.

Modified: trunk/Source/_javascript_Core/runtime/JSArrayIterator.cpp (158939 => 158940)


--- trunk/Source/_javascript_Core/runtime/JSArrayIterator.cpp	2013-11-08 20:22:36 UTC (rev 158939)
+++ trunk/Source/_javascript_Core/runtime/JSArrayIterator.cpp	2013-11-08 20:27:55 UTC (rev 158940)
@@ -100,8 +100,10 @@
 static inline EncodedJSValue JSC_HOST_CALL arrayIteratorNext(CallFrame* callFrame)
 {
     JSArrayIterator* iterator = jsDynamicCast<JSArrayIterator*>(callFrame->thisValue());
-    if (!iterator)
-        throwTypeError(callFrame, ASCIILiteral("Cannot call ArrayIterator.next() on a non-ArrayIterator object"));
+    if (!iterator) {
+        ASSERT_NOT_REACHED();
+        return JSValue::encode(throwTypeError(callFrame, ASCIILiteral("Cannot call ArrayIterator.next() on a non-ArrayIterator object")));
+    }
     JSObject* iteratedObject = iterator->iteratedObject();
     size_t index = iterator->nextIndex();
     ArrayIterationKind kind = iterator->iterationKind();

Added: trunk/Source/_javascript_Core/runtime/JSSetIterator.cpp (0 => 158940)


--- trunk/Source/_javascript_Core/runtime/JSSetIterator.cpp	                        (rev 0)
+++ trunk/Source/_javascript_Core/runtime/JSSetIterator.cpp	2013-11-08 20:27:55 UTC (rev 158940)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2013 Apple, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+#include "JSSetIterator.h"
+
+#include "JSSet.h"
+
+namespace JSC {
+
+const ClassInfo JSSetIterator::s_info = { "Set Iterator", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(JSSetIterator) };
+
+void JSSetIterator::finishCreation(VM& vm, JSSet* iteratedObject)
+{
+    Base::finishCreation(vm);
+    m_iteratedObject.set(vm, this, iteratedObject);
+}
+
+}

Added: trunk/Source/_javascript_Core/runtime/JSSetIterator.h (0 => 158940)


--- trunk/Source/_javascript_Core/runtime/JSSetIterator.h	                        (rev 0)
+++ trunk/Source/_javascript_Core/runtime/JSSetIterator.h	2013-11-08 20:27:55 UTC (rev 158940)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2013 Apple, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef JSSetIterator_h
+#define JSSetIterator_h
+
+#include "JSSet.h"
+
+namespace JSC {
+
+class JSSetIterator : public JSNonFinalObject {
+public:
+    typedef JSNonFinalObject Base;
+
+    DECLARE_EXPORT_INFO;
+
+    static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+    {
+        return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+    }
+
+    static JSSetIterator* create(VM& vm, Structure* structure)
+    {
+        JSSetIterator* instance = new (NotNull, allocateCell<JSSetIterator>(vm.heap)) JSSetIterator(vm, structure);
+        instance->finishCreation(vm, structure->globalObject());
+        return instance;
+    }
+
+    static JSSetIterator* create(ExecState* exec, Structure* structure)
+    {
+        return create(exec->vm(), structure);
+    }
+
+private:
+
+    static const unsigned StructureFlags = Base::StructureFlags;
+
+    JSSetIterator(VM& vm, Structure* structure)
+        : Base(vm, structure)
+    {
+    }
+
+    void finishCreation(VM&, JSGlobalObject*);
+    
+    JSSet::const_iterator m_iterator;
+    WriteBarrier<JSSet> m_iteratedObject;
+};
+
+}
+
+#endif // !defined(JSSetIterator_h)

Added: trunk/Source/_javascript_Core/runtime/SetIteratorConstructor.cpp (0 => 158940)


--- trunk/Source/_javascript_Core/runtime/SetIteratorConstructor.cpp	                        (rev 0)
+++ trunk/Source/_javascript_Core/runtime/SetIteratorConstructor.cpp	2013-11-08 20:27:55 UTC (rev 158940)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2013 Apple, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+#include "SetIteratorConstructor.h"
+
+#include "JSCJSValueInlines.h"
+#include "JSCellInlines.h"
+#include "JSGlobalObject.h"
+#include "JSSetIterator.h"
+#include "SetIteratorPrototype.h"
+
+namespace JSC {
+
+const ClassInfo SetIteratorConstructor::s_info = { "SetIterator Iterator", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(SetIteratorConstructor) };
+
+void SetIteratorConstructor::finishCreation(VM& vm)
+{
+    Base::finishCreation(vm, prototype->classInfo()->className);
+    putDirectWithoutTransition(vm, exec->propertyNames().prototype, prototype, DontEnum | DontDelete | ReadOnly);
+}
+
+}
\ No newline at end of file

Added: trunk/Source/_javascript_Core/runtime/SetIteratorConstructor.h (0 => 158940)


--- trunk/Source/_javascript_Core/runtime/SetIteratorConstructor.h	                        (rev 0)
+++ trunk/Source/_javascript_Core/runtime/SetIteratorConstructor.h	2013-11-08 20:27:55 UTC (rev 158940)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2013 Apple, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef SetIteratorConstructor_h
+#define SetIteratorConstructor_h
+
+#include "JSObject.h"
+
+namespace JSC {
+
+class SetIteratorPrototype;
+
+class SetIteratorConstructor : public JSNonFinalObject {
+public:
+    typedef JSNonFinalObject Base;
+
+    static SetIteratorConstructor* create(VM& vm, Structure* structure, SetIteratorPrototype*)
+    {
+        SetIteratorConstructor* constructor = new (NotNull, allocateCell<SetIteratorConstructor>(vm.heap)) SetIteratorConstructor(vm, structure);
+        constructor->finishCreation(vm);
+        return constructor;
+    }
+
+    DECLARE_INFO;
+
+    static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+    {
+        return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+    }
+
+private:
+    SetIteratorConstructor(VM& vm, Structure* structure)
+        : Base(vm, structure)
+    {
+    }
+    void finishCreation(VM&);
+};
+
+}
+
+#endif // !defined(SetIteratorConstructor_h)

Added: trunk/Source/_javascript_Core/runtime/SetIteratorPrototype.cpp (0 => 158940)


--- trunk/Source/_javascript_Core/runtime/SetIteratorPrototype.cpp	                        (rev 0)
+++ trunk/Source/_javascript_Core/runtime/SetIteratorPrototype.cpp	2013-11-08 20:27:55 UTC (rev 158940)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2013 Apple, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+#include "SetIteratorPrototype.h"
+
+#include "JSSetIterator.h"
+
+namespace JSC {
+
+const ClassInfo SetIteratorPrototype::s_info = { "SetIterator", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(SetIteratorPrototype) };
+
+static EncodedJSValue JSC_HOST_CALL SetIteratorPrototypeFuncIterator(ExecState*);
+static EncodedJSValue JSC_HOST_CALL SetIteratorPrototypeFuncNext(ExecState*);
+
+
+void SetIteratorPrototype::finishCreation(VM& vm, JSGlobalObject* globalObject)
+{
+    Base::finishCreation(vm);
+    ASSERT(inherits(info()));
+    vm.prototypeMap.addPrototype(this);
+
+    JSC_NATIVE_FUNCTION(vm.propertyNames->iteratorPrivateName, SetIteratorPrototypeFuncIterator, DontEnum, 0);
+    JSC_NATIVE_FUNCTION(vm.propertyNames->iteratorNextPrivateName, SetIteratorPrototypeFuncNext, DontEnum, 0);
+}
+
+EncodedJSValue JSC_HOST_CALL SetIteratorPrototypeFuncIterator(CallFrame* callFrame)
+{
+    return JSValue::encode(callFrame->thisValue());
+}
+
+EncodedJSValue JSC_HOST_CALL SetIteratorPrototypeFuncNext(CallFrame* callFrame)
+{
+    JSValue result;
+    if (jsCast<JSSetIterator*>(callFrame->thisValue())->next(callFrame, result))
+        return JSValue::encode(result);
+    return JSValue::encode(callFrame->vm().iterationTerminator.get());
+}
+
+
+}

Added: trunk/Source/_javascript_Core/runtime/SetIteratorPrototype.h (0 => 158940)


--- trunk/Source/_javascript_Core/runtime/SetIteratorPrototype.h	                        (rev 0)
+++ trunk/Source/_javascript_Core/runtime/SetIteratorPrototype.h	2013-11-08 20:27:55 UTC (rev 158940)
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2013 Apple, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef SetIteratorPrototype_h
+#define SetIteratorPrototype_h
+
+#include "JSObject.h"
+
+namespace JSC {
+
+class SetIteratorPrototype : public JSNonFinalObject {
+public:
+    typedef JSNonFinalObject Base;
+
+    static SetIteratorPrototype* create(VM& vm, JSGlobalObject* globalObject, Structure* structure)
+    {
+        SetIteratorPrototype* prototype = new (NotNull, allocateCell<SetIteratorPrototype>(vm.heap)) SetIteratorPrototype(vm, structure);
+        prototype->finishCreation(vm, globalObject);
+        return prototype;
+    }
+
+    DECLARE_INFO;
+
+    static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+    {
+        return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+    }
+
+private:
+    SetIteratorPrototype(VM& vm, Structure* structure)
+        : Base(vm, structure)
+    {
+    }
+    void finishCreation(VM&, JSGlobalObject*);
+};
+
+}
+
+#endif // !defined(SetIteratorPrototype_h)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to