This source file includes following definitions.
- match
#include "config.h"
#include "bindings/v8/ScriptRegexp.h"
#include "bindings/v8/V8Binding.h"
#include "bindings/v8/V8PerIsolateData.h"
#include "bindings/v8/V8ScriptRunner.h"
namespace WebCore {
ScriptRegexp::ScriptRegexp(const String& pattern, TextCaseSensitivity caseSensitivity, MultilineMode multilineMode)
{
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::HandleScope handleScope(isolate);
v8::Context::Scope contextScope(V8PerIsolateData::from(isolate)->ensureDomInJSContext());
v8::TryCatch tryCatch;
unsigned flags = v8::RegExp::kNone;
if (caseSensitivity == TextCaseInsensitive)
flags |= v8::RegExp::kIgnoreCase;
if (multilineMode == MultilineEnabled)
flags |= v8::RegExp::kMultiline;
v8::Local<v8::RegExp> regex = v8::RegExp::New(v8String(isolate, pattern), static_cast<v8::RegExp::Flags>(flags));
if (!regex.IsEmpty())
m_regex.set(isolate, regex);
}
int ScriptRegexp::match(const String& string, int startFrom, int* matchLength) const
{
if (matchLength)
*matchLength = 0;
if (m_regex.isEmpty() || string.isNull())
return -1;
if (string.length() > INT_MAX)
return -1;
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::HandleScope handleScope(isolate);
v8::Context::Scope contextScope(V8PerIsolateData::from(isolate)->ensureDomInJSContext());
v8::TryCatch tryCatch;
v8::Local<v8::RegExp> regex = m_regex.newLocal(isolate);
v8::Local<v8::Function> exec = regex->Get(v8AtomicString(isolate, "exec")).As<v8::Function>();
v8::Handle<v8::Value> argv[] = { v8String(isolate, string.substring(startFrom)) };
v8::Local<v8::Value> returnValue = V8ScriptRunner::callInternalFunction(exec, regex, WTF_ARRAY_LENGTH(argv), argv, isolate);
if (!returnValue->IsArray())
return -1;
v8::Local<v8::Array> result = returnValue.As<v8::Array>();
int matchOffset = result->Get(v8AtomicString(isolate, "index"))->ToInt32()->Value();
if (matchLength) {
v8::Local<v8::String> match = result->Get(0).As<v8::String>();
*matchLength = match->Length();
}
return matchOffset + startFrom;
}
}