OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2008, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2008, 2009 Apple Inc. All rights reserved. |
3 * Copyright (C) 2008 Collabora Ltd. | 3 * Copyright (C) 2008 Collabora Ltd. |
4 * Copyright (C) 2011 Peter Varga (pvarga@webkit.org), University of Szeged | 4 * Copyright (C) 2011 Peter Varga (pvarga@webkit.org), University of Szeged |
5 * Copyright (C) 2013 Google Inc. All rights reserved. | 5 * Copyright (C) 2013 Google Inc. All rights reserved. |
6 * | 6 * |
7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without |
8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions |
9 * are met: | 9 * are met: |
10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 v8::HandleScope handleScope(isolate); | 73 v8::HandleScope handleScope(isolate); |
74 v8::Local<v8::Context> context = V8PerIsolateData::from(isolate)->ensureScri
ptRegexpContext(); | 74 v8::Local<v8::Context> context = V8PerIsolateData::from(isolate)->ensureScri
ptRegexpContext(); |
75 v8::Context::Scope contextScope(context); | 75 v8::Context::Scope contextScope(context); |
76 v8::TryCatch tryCatch; | 76 v8::TryCatch tryCatch; |
77 | 77 |
78 v8::Local<v8::RegExp> regex = m_regex.newLocal(isolate); | 78 v8::Local<v8::RegExp> regex = m_regex.newLocal(isolate); |
79 v8::Local<v8::Value> exec; | 79 v8::Local<v8::Value> exec; |
80 if (!regex->Get(context, v8AtomicString(isolate, "exec")).ToLocal(&exec)) | 80 if (!regex->Get(context, v8AtomicString(isolate, "exec")).ToLocal(&exec)) |
81 return -1; | 81 return -1; |
82 v8::Local<v8::Value> argv[] = { v8String(isolate, string.substring(startFrom
)) }; | 82 v8::Local<v8::Value> argv[] = { v8String(isolate, string.substring(startFrom
)) }; |
83 v8::Local<v8::Value> returnValue = V8ScriptRunner::callInternalFunction(exec
.As<v8::Function>(), regex, WTF_ARRAY_LENGTH(argv), argv, isolate); | 83 v8::Local<v8::Value> returnValue; |
84 | 84 if (!V8ScriptRunner::callInternalFunction(exec.As<v8::Function>(), regex, WT
F_ARRAY_LENGTH(argv), argv, isolate).ToLocal(&returnValue)) |
85 if (tryCatch.HasCaught()) | |
86 return -1; | 85 return -1; |
87 | 86 |
88 // RegExp#exec returns null if there's no match, otherwise it returns an | 87 // RegExp#exec returns null if there's no match, otherwise it returns an |
89 // Array of strings with the first being the whole match string and others | 88 // Array of strings with the first being the whole match string and others |
90 // being subgroups. The Array also has some random properties tacked on like | 89 // being subgroups. The Array also has some random properties tacked on like |
91 // "index" which is the offset of the match. | 90 // "index" which is the offset of the match. |
92 // | 91 // |
93 // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Obje
cts/RegExp/exec | 92 // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Obje
cts/RegExp/exec |
94 | 93 |
95 ASSERT(!returnValue.IsEmpty()); | 94 ASSERT(!returnValue.IsEmpty()); |
96 if (!returnValue->IsArray()) | 95 if (!returnValue->IsArray()) |
97 return -1; | 96 return -1; |
98 | 97 |
99 v8::Local<v8::Array> result = returnValue.As<v8::Array>(); | 98 v8::Local<v8::Array> result = returnValue.As<v8::Array>(); |
100 v8::Local<v8::Value> matchOffset; | 99 v8::Local<v8::Value> matchOffset; |
101 if (!result->Get(context, v8AtomicString(isolate, "index")).ToLocal(&matchOf
fset)) | 100 if (!result->Get(context, v8AtomicString(isolate, "index")).ToLocal(&matchOf
fset)) |
102 return -1; | 101 return -1; |
103 if (matchLength) { | 102 if (matchLength) { |
104 v8::Local<v8::Value> match; | 103 v8::Local<v8::Value> match; |
105 if (!result->Get(context, 0).ToLocal(&match)) | 104 if (!result->Get(context, 0).ToLocal(&match)) |
106 return -1; | 105 return -1; |
107 *matchLength = match.As<v8::String>()->Length(); | 106 *matchLength = match.As<v8::String>()->Length(); |
108 } | 107 } |
109 | 108 |
110 return matchOffset.As<v8::Int32>()->Value() + startFrom; | 109 return matchOffset.As<v8::Int32>()->Value() + startFrom; |
111 } | 110 } |
112 | 111 |
113 } // namespace blink | 112 } // namespace blink |
OLD | NEW |