Commit b1d4bf41 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Move some Runtime:: functions and remove runtime.h as include when unnecessary.

R=bmeurer@chromium.org

Review URL: https://codereview.chromium.org/662413002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24736 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 010f0899
......@@ -3173,6 +3173,44 @@ bool v8::Object::SetPrivate(v8::Handle<Private> key, v8::Handle<Value> value) {
}
i::MaybeHandle<i::Object> DeleteObjectProperty(
i::Isolate* isolate, i::Handle<i::JSReceiver> receiver,
i::Handle<i::Object> key, i::JSReceiver::DeleteMode mode) {
// Check if the given key is an array index.
uint32_t index;
if (key->ToArrayIndex(&index)) {
// In Firefox/SpiderMonkey, Safari and Opera you can access the
// characters of a string using [] notation. In the case of a
// String object we just need to redirect the deletion to the
// underlying string if the index is in range. Since the
// underlying string does nothing with the deletion, we can ignore
// such deletions.
if (receiver->IsStringObjectWithCharacterAt(index)) {
return isolate->factory()->true_value();
}
return i::JSReceiver::DeleteElement(receiver, index, mode);
}
i::Handle<i::Name> name;
if (key->IsName()) {
name = i::Handle<i::Name>::cast(key);
} else {
// Call-back into JavaScript to convert the key to a string.
i::Handle<i::Object> converted;
if (!i::Execution::ToString(isolate, key).ToHandle(&converted)) {
return i::MaybeHandle<i::Object>();
}
name = i::Handle<i::String>::cast(converted);
}
if (name->IsString()) {
name = i::String::Flatten(i::Handle<i::String>::cast(name));
}
return i::JSReceiver::DeleteProperty(receiver, name, mode);
}
bool v8::Object::ForceDelete(v8::Handle<Value> key) {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ON_BAILOUT(isolate, "v8::Object::ForceDelete()", return false);
......@@ -3191,8 +3229,9 @@ bool v8::Object::ForceDelete(v8::Handle<Value> key) {
EXCEPTION_PREAMBLE(isolate);
i::Handle<i::Object> obj;
has_pending_exception = !i::Runtime::DeleteObjectProperty(
isolate, self, key_obj, i::JSReceiver::FORCE_DELETION).ToHandle(&obj);
has_pending_exception =
!DeleteObjectProperty(isolate, self, key_obj,
i::JSReceiver::FORCE_DELETION).ToHandle(&obj);
EXCEPTION_BAILOUT_CHECK(isolate, false);
return obj->IsTrue();
}
......@@ -3445,8 +3484,9 @@ bool v8::Object::Delete(v8::Handle<Value> key) {
i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
EXCEPTION_PREAMBLE(isolate);
i::Handle<i::Object> obj;
has_pending_exception = !i::Runtime::DeleteObjectProperty(
isolate, self, key_obj, i::JSReceiver::NORMAL_DELETION).ToHandle(&obj);
has_pending_exception =
!DeleteObjectProperty(isolate, self, key_obj,
i::JSReceiver::NORMAL_DELETION).ToHandle(&obj);
EXCEPTION_BAILOUT_CHECK(isolate, false);
return obj->IsTrue();
}
......@@ -3464,11 +3504,22 @@ bool v8::Object::Has(v8::Handle<Value> key) {
i::Handle<i::JSReceiver> self = Utils::OpenHandle(this);
i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
EXCEPTION_PREAMBLE(isolate);
i::Handle<i::Object> obj;
has_pending_exception = !i::Runtime::HasObjectProperty(
isolate, self, key_obj).ToHandle(&obj);
Maybe<bool> maybe;
// Check if the given key is an array index.
uint32_t index;
if (key_obj->ToArrayIndex(&index)) {
maybe = i::JSReceiver::HasElement(self, index);
} else {
// Convert the key to a name - possibly by calling back into JavaScript.
i::Handle<i::Name> name;
if (i::Runtime::ToName(isolate, key_obj).ToHandle(&name)) {
maybe = i::JSReceiver::HasProperty(self, name);
}
}
if (!maybe.has_value) has_pending_exception = true;
EXCEPTION_BAILOUT_CHECK(isolate, false);
return obj->IsTrue();
DCHECK(maybe.has_value);
return maybe.value;
}
......
......@@ -5,7 +5,6 @@
#include "src/v8.h"
#include "src/arguments.h"
#include "src/runtime/runtime.h"
#include "src/runtime/runtime-utils.h"
namespace v8 {
......
......@@ -5,7 +5,6 @@
#include "src/v8.h"
#include "src/arguments.h"
#include "src/runtime/runtime.h"
#include "src/runtime/runtime-utils.h"
......
......@@ -10,7 +10,6 @@
#include "src/frames.h"
#include "src/full-codegen.h"
#include "src/isolate-inl.h"
#include "src/runtime/runtime.h"
#include "src/runtime/runtime-utils.h"
#include "src/v8threads.h"
#include "src/vm-state-inl.h"
......
......@@ -7,7 +7,6 @@
#include "src/arguments.h"
#include "src/date.h"
#include "src/dateparser-inl.h"
#include "src/runtime/runtime.h"
#include "src/runtime/runtime-utils.h"
namespace v8 {
......
......@@ -385,7 +385,7 @@ static SaveContext* FindSavedContextForFrame(Isolate* isolate,
// Advances the iterator to the frame that matches the index and returns the
// inlined frame index, or -1 if not found. Skips native JS functions.
int FindIndexedNonNativeFrame(JavaScriptFrameIterator* it, int index) {
int Runtime::FindIndexedNonNativeFrame(JavaScriptFrameIterator* it, int index) {
int count = -1;
for (; !it->done(); it->Advance()) {
List<FrameSummary> frames(FLAG_max_inlining_levels + 1);
......@@ -435,7 +435,7 @@ RUNTIME_FUNCTION(Runtime_GetFrameDetails) {
JavaScriptFrameIterator it(isolate, id);
// Inlined frame index in optimized frame, starting from outer function.
int inlined_jsframe_index = FindIndexedNonNativeFrame(&it, index);
int inlined_jsframe_index = Runtime::FindIndexedNonNativeFrame(&it, index);
if (inlined_jsframe_index == -1) return heap->undefined_value();
FrameInspector frame_inspector(it.frame(), inlined_jsframe_index, isolate);
......
......@@ -9,7 +9,6 @@
#include "src/compiler.h"
#include "src/deoptimizer.h"
#include "src/frames.h"
#include "src/runtime/runtime.h"
#include "src/runtime/runtime-utils.h"
namespace v8 {
......
......@@ -6,7 +6,6 @@
#include "src/arguments.h"
#include "src/frames-inl.h"
#include "src/runtime/runtime.h"
#include "src/runtime/runtime-utils.h"
namespace v8 {
......
......@@ -8,7 +8,6 @@
#include "src/arguments.h"
#include "src/i18n.h"
#include "src/runtime/runtime.h"
#include "src/runtime/runtime-utils.h"
#include "unicode/brkiter.h"
......
......@@ -7,7 +7,6 @@
#include "src/arguments.h"
#include "src/bootstrapper.h"
#include "src/debug.h"
#include "src/runtime/runtime.h"
#include "src/runtime/runtime-utils.h"
namespace v8 {
......
......@@ -7,7 +7,6 @@
#include "src/arguments.h"
#include "src/json-parser.h"
#include "src/json-stringifier.h"
#include "src/runtime/runtime.h"
#include "src/runtime/runtime-utils.h"
namespace v8 {
......
......@@ -279,7 +279,7 @@ RUNTIME_FUNCTION(Runtime_LiveEditRestartFrame) {
}
JavaScriptFrameIterator it(isolate, id);
int inlined_jsframe_index = FindIndexedNonNativeFrame(&it, index);
int inlined_jsframe_index = Runtime::FindIndexedNonNativeFrame(&it, index);
if (inlined_jsframe_index == -1) return heap->undefined_value();
// We don't really care what the inlined frame index is, since we are
// throwing away the entire frame anyways.
......
......@@ -7,7 +7,6 @@
#include "src/arguments.h"
#include "src/assembler.h"
#include "src/codegen.h"
#include "src/runtime/runtime.h"
#include "src/runtime/runtime-utils.h"
#include "src/third_party/fdlibm/fdlibm.h"
......
......@@ -8,7 +8,6 @@
#include "src/bootstrapper.h"
#include "src/codegen.h"
#include "src/misc-intrinsics.h"
#include "src/runtime/runtime.h"
#include "src/runtime/runtime-utils.h"
......
......@@ -65,27 +65,6 @@ MaybeHandle<Name> Runtime::ToName(Isolate* isolate, Handle<Object> key) {
}
MaybeHandle<Object> Runtime::HasObjectProperty(Isolate* isolate,
Handle<JSReceiver> object,
Handle<Object> key) {
Maybe<bool> maybe;
// Check if the given key is an array index.
uint32_t index;
if (key->ToArrayIndex(&index)) {
maybe = JSReceiver::HasElement(object, index);
} else {
// Convert the key to a name - possibly by calling back into JavaScript.
Handle<Name> name;
ASSIGN_RETURN_ON_EXCEPTION(isolate, name, ToName(isolate, key), Object);
maybe = JSReceiver::HasProperty(object, name);
}
if (!maybe.has_value) return MaybeHandle<Object>();
return isolate->factory()->ToBoolean(maybe.value);
}
MaybeHandle<Object> Runtime::GetObjectProperty(Isolate* isolate,
Handle<Object> object,
Handle<Object> key) {
......@@ -263,42 +242,6 @@ MaybeHandle<Object> Runtime::DefineObjectProperty(Handle<JSObject> js_object,
}
MaybeHandle<Object> Runtime::DeleteObjectProperty(Isolate* isolate,
Handle<JSReceiver> receiver,
Handle<Object> key,
JSReceiver::DeleteMode mode) {
// Check if the given key is an array index.
uint32_t index;
if (key->ToArrayIndex(&index)) {
// In Firefox/SpiderMonkey, Safari and Opera you can access the
// characters of a string using [] notation. In the case of a
// String object we just need to redirect the deletion to the
// underlying string if the index is in range. Since the
// underlying string does nothing with the deletion, we can ignore
// such deletions.
if (receiver->IsStringObjectWithCharacterAt(index)) {
return isolate->factory()->true_value();
}
return JSReceiver::DeleteElement(receiver, index, mode);
}
Handle<Name> name;
if (key->IsName()) {
name = Handle<Name>::cast(key);
} else {
// Call-back into JavaScript to convert the key to a string.
Handle<Object> converted;
ASSIGN_RETURN_ON_EXCEPTION(isolate, converted,
Execution::ToString(isolate, key), Object);
name = Handle<String>::cast(converted);
}
if (name->IsString()) name = String::Flatten(Handle<String>::cast(name));
return JSReceiver::DeleteProperty(receiver, name, mode);
}
RUNTIME_FUNCTION(Runtime_GetPrototype) {
HandleScope scope(isolate);
DCHECK(args.length() == 1);
......
......@@ -5,7 +5,6 @@
#include "src/v8.h"
#include "src/arguments.h"
#include "src/runtime/runtime.h"
#include "src/runtime/runtime-utils.h"
namespace v8 {
......
......@@ -5,7 +5,6 @@
#include "src/v8.h"
#include "src/arguments.h"
#include "src/runtime/runtime.h"
#include "src/runtime/runtime-utils.h"
namespace v8 {
......
......@@ -7,7 +7,6 @@
#include "src/arguments.h"
#include "src/jsregexp-inl.h"
#include "src/jsregexp.h"
#include "src/runtime/runtime.h"
#include "src/runtime/runtime-utils.h"
#include "src/runtime/string-builder.h"
#include "src/string-search.h"
......@@ -1094,46 +1093,5 @@ RUNTIME_FUNCTION(RuntimeReference_IsRegExp) {
CONVERT_ARG_CHECKED(Object, obj, 0);
return isolate->heap()->ToBoolean(obj->IsJSRegExp());
}
// Perform string match of pattern on subject, starting at start index.
// Caller must ensure that 0 <= start_index <= sub->length(),
// and should check that pat->length() + start_index <= sub->length().
int Runtime::StringMatch(Isolate* isolate, Handle<String> sub,
Handle<String> pat, int start_index) {
DCHECK(0 <= start_index);
DCHECK(start_index <= sub->length());
int pattern_length = pat->length();
if (pattern_length == 0) return start_index;
int subject_length = sub->length();
if (start_index + pattern_length > subject_length) return -1;
sub = String::Flatten(sub);
pat = String::Flatten(pat);
DisallowHeapAllocation no_gc; // ensure vectors stay valid
// Extract flattened substrings of cons strings before getting encoding.
String::FlatContent seq_sub = sub->GetFlatContent();
String::FlatContent seq_pat = pat->GetFlatContent();
// dispatch on type of strings
if (seq_pat.IsOneByte()) {
Vector<const uint8_t> pat_vector = seq_pat.ToOneByteVector();
if (seq_sub.IsOneByte()) {
return SearchString(isolate, seq_sub.ToOneByteVector(), pat_vector,
start_index);
}
return SearchString(isolate, seq_sub.ToUC16Vector(), pat_vector,
start_index);
}
Vector<const uc16> pat_vector = seq_pat.ToUC16Vector();
if (seq_sub.IsOneByte()) {
return SearchString(isolate, seq_sub.ToOneByteVector(), pat_vector,
start_index);
}
return SearchString(isolate, seq_sub.ToUC16Vector(), pat_vector, start_index);
}
}
} // namespace v8::internal
......@@ -7,7 +7,6 @@
#include "src/accessors.h"
#include "src/arguments.h"
#include "src/frames-inl.h"
#include "src/runtime/runtime.h"
#include "src/runtime/runtime-utils.h"
#include "src/scopeinfo.h"
#include "src/scopes.h"
......
......@@ -7,7 +7,6 @@
#include "src/arguments.h"
#include "src/jsregexp-inl.h"
#include "src/jsregexp.h"
#include "src/runtime/runtime.h"
#include "src/runtime/runtime-utils.h"
#include "src/runtime/string-builder.h"
#include "src/string-search.h"
......@@ -16,6 +15,47 @@ namespace v8 {
namespace internal {
// Perform string match of pattern on subject, starting at start index.
// Caller must ensure that 0 <= start_index <= sub->length(),
// and should check that pat->length() + start_index <= sub->length().
int StringMatch(Isolate* isolate, Handle<String> sub, Handle<String> pat,
int start_index) {
DCHECK(0 <= start_index);
DCHECK(start_index <= sub->length());
int pattern_length = pat->length();
if (pattern_length == 0) return start_index;
int subject_length = sub->length();
if (start_index + pattern_length > subject_length) return -1;
sub = String::Flatten(sub);
pat = String::Flatten(pat);
DisallowHeapAllocation no_gc; // ensure vectors stay valid
// Extract flattened substrings of cons strings before getting encoding.
String::FlatContent seq_sub = sub->GetFlatContent();
String::FlatContent seq_pat = pat->GetFlatContent();
// dispatch on type of strings
if (seq_pat.IsOneByte()) {
Vector<const uint8_t> pat_vector = seq_pat.ToOneByteVector();
if (seq_sub.IsOneByte()) {
return SearchString(isolate, seq_sub.ToOneByteVector(), pat_vector,
start_index);
}
return SearchString(isolate, seq_sub.ToUC16Vector(), pat_vector,
start_index);
}
Vector<const uc16> pat_vector = seq_pat.ToUC16Vector();
if (seq_sub.IsOneByte()) {
return SearchString(isolate, seq_sub.ToOneByteVector(), pat_vector,
start_index);
}
return SearchString(isolate, seq_sub.ToUC16Vector(), pat_vector, start_index);
}
// This may return an empty MaybeHandle if an exception is thrown or
// we abort due to reaching the recursion limit.
MaybeHandle<String> StringReplaceOneCharWithString(
......@@ -47,7 +87,7 @@ MaybeHandle<String> StringReplaceOneCharWithString(
return subject;
} else {
int index = Runtime::StringMatch(isolate, subject, search, 0);
int index = StringMatch(isolate, subject, search, 0);
if (index == -1) return subject;
*found = true;
Handle<String> first = isolate->factory()->NewSubString(subject, 0, index);
......@@ -101,7 +141,7 @@ RUNTIME_FUNCTION(Runtime_StringIndexOf) {
if (!index->ToArrayIndex(&start_index)) return Smi::FromInt(-1);
RUNTIME_ASSERT(start_index <= static_cast<uint32_t>(sub->length()));
int position = Runtime::StringMatch(isolate, sub, pat, start_index);
int position = StringMatch(isolate, sub, pat, start_index);
return Smi::FromInt(position);
}
......
......@@ -5,7 +5,6 @@
#include "src/v8.h"
#include "src/arguments.h"
#include "src/runtime/runtime.h"
#include "src/runtime/runtime-utils.h"
namespace v8 {
......
......@@ -7,7 +7,6 @@
#include "src/arguments.h"
#include "src/deoptimizer.h"
#include "src/full-codegen.h"
#include "src/runtime/runtime.h"
#include "src/runtime/runtime-utils.h"
namespace v8 {
......@@ -391,7 +390,7 @@ RUNTIME_FUNCTION(Runtime_ListNatives) {
#undef ADD_ENTRY
DCHECK_EQ(index, entry_count);
Handle<JSArray> result = factory->NewJSArrayWithElements(elements);
return *result;
return (*result);
}
#endif
......
......@@ -6,7 +6,6 @@
#include "src/arguments.h"
#include "src/conversions.h"
#include "src/runtime/runtime.h"
#include "src/runtime/runtime-utils.h"
#include "src/string-search.h"
#include "src/utils.h"
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_RUNTIME_UTILS_H_
#define V8_RUNTIME_UTILS_H_
#ifndef V8_RUNTIME_RUNTIME_UTILS_H_
#define V8_RUNTIME_RUNTIME_UTILS_H_
namespace v8 {
......@@ -141,10 +141,7 @@ static inline ObjectPair MakePair(Object* x, Object* y) {
}
#endif
class JavaScriptFrameIterator;
int FindIndexedNonNativeFrame(JavaScriptFrameIterator* it, int index);
}
} // namespace v8::internal
#endif // V8_RUNTIME_UTILS_H_
#endif // V8_RUNTIME_RUNTIME_UTILS_H_
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_RUNTIME_H_
#define V8_RUNTIME_H_
#ifndef V8_RUNTIME_RUNTIME_H_
#define V8_RUNTIME_RUNTIME_H_
#include "src/allocation.h"
#include "src/objects.h"
......@@ -777,6 +777,9 @@ class RuntimeState {
};
class JavaScriptFrameIterator; // Forward declaration.
class Runtime : public AllStatic {
public:
enum FunctionId {
......@@ -828,10 +831,6 @@ class Runtime : public AllStatic {
// Get the intrinsic function with the given function entry address.
static const Function* FunctionForEntry(Address ref);
// General-purpose helper functions for runtime system.
static int StringMatch(Isolate* isolate, Handle<String> sub,
Handle<String> pat, int index);
// TODO(1240886): Some of the following methods are *not* handle safe, but
// accept handle arguments. This seems fragile.
......@@ -848,13 +847,6 @@ class Runtime : public AllStatic {
Handle<JSObject> object, Handle<Object> key, Handle<Object> value,
PropertyAttributes attr);
MUST_USE_RESULT static MaybeHandle<Object> DeleteObjectProperty(
Isolate* isolate, Handle<JSReceiver> object, Handle<Object> key,
JSReceiver::DeleteMode mode);
MUST_USE_RESULT static MaybeHandle<Object> HasObjectProperty(
Isolate* isolate, Handle<JSReceiver> object, Handle<Object> key);
MUST_USE_RESULT static MaybeHandle<Object> GetObjectProperty(
Isolate* isolate, Handle<Object> object, Handle<Object> key);
......@@ -876,6 +868,8 @@ class Runtime : public AllStatic {
static void FreeArrayBuffer(Isolate* isolate,
JSArrayBuffer* phantom_array_buffer);
static int FindIndexedNonNativeFrame(JavaScriptFrameIterator* it, int index);
enum TypedArrayId {
// arrayIds below should be synchromized with typedarray.js natives.
ARRAY_ID_UINT8 = 1,
......@@ -918,4 +912,4 @@ class DeclareGlobalsStrictMode : public BitField<StrictMode, 2, 1> {};
} // namespace internal
} // namespace v8
#endif // V8_RUNTIME_H_
#endif // V8_RUNTIME_RUNTIME_H_
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_STRING_BUILDER_H_
#define V8_STRING_BUILDER_H_
#ifndef V8_RUNTIME_STRING_BUILDER_H_
#define V8_RUNTIME_STRING_BUILDER_H_
namespace v8 {
namespace internal {
......@@ -293,4 +293,4 @@ class ReplacementStringBuilder {
}
} // namespace v8::internal
#endif // V8_STRING_BUILDER_H_
#endif // V8_RUNTIME_STRING_BUILDER_H_
......@@ -30,7 +30,7 @@
#include "src/api.h"
#include "src/debug.h"
#include "src/runtime/runtime.h"
#include "src/string-search.h"
#include "test/cctest/cctest.h"
......@@ -46,13 +46,13 @@ using ::v8::internal::Script;
using ::v8::internal::SmartArrayPointer;
using ::v8::internal::SharedFunctionInfo;
using ::v8::internal::String;
using ::v8::internal::Vector;
static void CheckFunctionName(v8::Handle<v8::Script> script,
const char* func_pos_src,
const char* ref_inferred_name) {
Isolate* isolate = CcTest::i_isolate();
Factory* factory = isolate->factory();
// Get script source.
Handle<Object> obj = v8::Utils::OpenHandle(*script);
......@@ -69,12 +69,14 @@ static void CheckFunctionName(v8::Handle<v8::Script> script,
Handle<String> script_src(String::cast(i_script->source()));
// Find the position of a given func source substring in the source.
Handle<String> func_pos_str =
factory->NewStringFromAsciiChecked(func_pos_src);
int func_pos = Runtime::StringMatch(isolate,
script_src,
func_pos_str,
0);
int func_pos;
{
i::DisallowHeapAllocation no_gc;
Vector<const uint8_t> func_pos_str = i::OneByteVector(func_pos_src);
String::FlatContent script_content = script_src->GetFlatContent();
func_pos = SearchString(isolate, script_content.ToOneByteVector(),
func_pos_str, 0);
}
CHECK_NE(0, func_pos);
// Obtain SharedFunctionInfo for the function.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment