diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/JavaScriptCore/runtime/StringRecursionChecker.h | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/JavaScriptCore/runtime/StringRecursionChecker.h')
-rw-r--r-- | Source/JavaScriptCore/runtime/StringRecursionChecker.h | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/Source/JavaScriptCore/runtime/StringRecursionChecker.h b/Source/JavaScriptCore/runtime/StringRecursionChecker.h index c99dd4ff1..463b79e66 100644 --- a/Source/JavaScriptCore/runtime/StringRecursionChecker.h +++ b/Source/JavaScriptCore/runtime/StringRecursionChecker.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 Apple Inc. All rights reserved. + * Copyright (C) 2011, 2016 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -17,12 +17,11 @@ * */ -#ifndef StringRecursionChecker_h -#define StringRecursionChecker_h +#pragma once #include "Interpreter.h" +#include "VMInlines.h" #include <wtf/StackStats.h> -#include <wtf/WTFThreadData.h> namespace JSC { @@ -50,9 +49,17 @@ private: inline JSValue StringRecursionChecker::performCheck() { VM& vm = m_exec->vm(); - if (!vm.isSafeToRecurse()) + if (UNLIKELY(!vm.isSafeToRecurseSoft())) return throwStackOverflowError(); - bool alreadyVisited = !vm.stringRecursionCheckVisitedObjects.add(m_thisObject).isNewEntry; + + bool alreadyVisited = false; + if (!vm.stringRecursionCheckFirstObject) + vm.stringRecursionCheckFirstObject = m_thisObject; + else if (vm.stringRecursionCheckFirstObject == m_thisObject) + alreadyVisited = true; + else + alreadyVisited = !vm.stringRecursionCheckVisitedObjects.add(m_thisObject).isNewEntry; + if (alreadyVisited) return emptyString(); // Return empty string to avoid infinite recursion. return JSValue(); // Indicate success. @@ -74,10 +81,14 @@ inline StringRecursionChecker::~StringRecursionChecker() { if (m_earlyReturnValue) return; - ASSERT(m_exec->vm().stringRecursionCheckVisitedObjects.contains(m_thisObject)); - m_exec->vm().stringRecursionCheckVisitedObjects.remove(m_thisObject); -} + VM& vm = m_exec->vm(); + if (vm.stringRecursionCheckFirstObject == m_thisObject) + vm.stringRecursionCheckFirstObject = nullptr; + else { + ASSERT(vm.stringRecursionCheckVisitedObjects.contains(m_thisObject)); + vm.stringRecursionCheckVisitedObjects.remove(m_thisObject); + } } -#endif +} // namespace JSC |