diff options
Diffstat (limited to 'Source/JavaScriptCore/runtime/RegExpCachedResult.h')
-rw-r--r-- | Source/JavaScriptCore/runtime/RegExpCachedResult.h | 102 |
1 files changed, 55 insertions, 47 deletions
diff --git a/Source/JavaScriptCore/runtime/RegExpCachedResult.h b/Source/JavaScriptCore/runtime/RegExpCachedResult.h index d2763bc77..40cc064f8 100644 --- a/Source/JavaScriptCore/runtime/RegExpCachedResult.h +++ b/Source/JavaScriptCore/runtime/RegExpCachedResult.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Apple Inc. All rights reserved. + * Copyright (C) 2012, 2016 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -23,62 +23,70 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef RegExpCachedResult_h -#define RegExpCachedResult_h +#pragma once #include "RegExpObject.h" namespace JSC { - class JSString; - class RegExpMatchesArray; +class JSArray; +class JSString; - // RegExpCachedResult is used to track the cached results of the last - // match, stores on the RegExp constructor (e.g. $&, $_, $1, $2 ...). - // These values will be lazily generated on demand, so the cached result - // may be in a lazy or reified state. A lazy state is indicated by a - // value of m_result indicating a successful match, and a reified state - // is indicated by setting m_result to MatchResult::failed(). - // Following a successful match, m_result, m_lastInput and m_lastRegExp - // can be used to reify the results from the match, following reification - // m_reifiedResult and m_reifiedInput hold the cached results. - class RegExpCachedResult { - public: - RegExpCachedResult(VM& vm, JSObject* owner, RegExp* emptyRegExp) - : m_result(0, 0) - { - m_lastInput.set(vm, owner, jsEmptyString(&vm)); - m_lastRegExp.set(vm, owner, emptyRegExp); - } +// RegExpCachedResult is used to track the cached results of the last +// match, stores on the RegExp constructor (e.g. $&, $_, $1, $2 ...). +// These values will be lazily generated on demand, so the cached result +// may be in a lazy or reified state. A lazy state is indicated by a +// value of m_result indicating a successful match, and a reified state +// is indicated by setting m_result to MatchResult::failed(). +// Following a successful match, m_result, m_lastInput and m_lastRegExp +// can be used to reify the results from the match, following reification +// m_reifiedResult and m_reifiedInput hold the cached results. +class RegExpCachedResult { +public: + RegExpCachedResult(VM& vm, JSObject* owner, RegExp* emptyRegExp) + : m_result(0, 0) + , m_reified(false) + { + m_lastInput.set(vm, owner, jsEmptyString(&vm)); + m_lastRegExp.set(vm, owner, emptyRegExp); + } - ALWAYS_INLINE void record(VM& vm, JSObject* owner, RegExp* regExp, JSString* input, MatchResult result) - { - m_lastRegExp.set(vm, owner, regExp); - m_lastInput.set(vm, owner, input); - m_result = result; - } + ALWAYS_INLINE void record(VM& vm, JSObject* owner, RegExp* regExp, JSString* input, MatchResult result) + { + vm.heap.writeBarrier(owner); + m_lastRegExp.setWithoutWriteBarrier(regExp); + m_lastInput.setWithoutWriteBarrier(input); + m_result = result; + m_reified = false; + } - RegExpMatchesArray* lastResult(ExecState*, JSObject* owner); - void setInput(ExecState*, JSObject* owner, JSString*); + JSArray* lastResult(ExecState*, JSObject* owner); + void setInput(ExecState*, JSObject* owner, JSString*); - JSString* input() - { - // If m_result showas a match then we're in a lazy state, so m_lastInput - // is the most recent value of the input property. If not then we have - // reified, in which case m_reifiedInput will contain the correct value. - return m_result ? m_lastInput.get() : m_reifiedInput.get(); - } + JSString* leftContext(ExecState*, JSObject* owner); + JSString* rightContext(ExecState*, JSObject* owner); - void visitChildren(SlotVisitor&); + JSString* input() + { + return m_reified ? m_reifiedInput.get() : m_lastInput.get(); + } - private: - MatchResult m_result; - WriteBarrier<JSString> m_lastInput; - WriteBarrier<RegExp> m_lastRegExp; - WriteBarrier<RegExpMatchesArray> m_reifiedResult; - WriteBarrier<JSString> m_reifiedInput; - }; + void visitChildren(SlotVisitor&); -} // namespace JSC + static ptrdiff_t offsetOfLastRegExp() { return OBJECT_OFFSETOF(RegExpCachedResult, m_lastRegExp); } + static ptrdiff_t offsetOfLastInput() { return OBJECT_OFFSETOF(RegExpCachedResult, m_lastInput); } + static ptrdiff_t offsetOfResult() { return OBJECT_OFFSETOF(RegExpCachedResult, m_result); } + static ptrdiff_t offsetOfReified() { return OBJECT_OFFSETOF(RegExpCachedResult, m_reified); } + +private: + MatchResult m_result; + bool m_reified; + WriteBarrier<JSString> m_lastInput; + WriteBarrier<RegExp> m_lastRegExp; + WriteBarrier<JSArray> m_reifiedResult; + WriteBarrier<JSString> m_reifiedInput; + WriteBarrier<JSString> m_reifiedLeftContext; + WriteBarrier<JSString> m_reifiedRightContext; +}; -#endif // RegExpCachedResult_h +} // namespace JSC |