More runtime hardening

R=dslomov@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@21039 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 55342170
...@@ -2768,6 +2768,9 @@ RUNTIME_FUNCTION(Runtime_FinishArrayPrototypeSetup) { ...@@ -2768,6 +2768,9 @@ RUNTIME_FUNCTION(Runtime_FinishArrayPrototypeSetup) {
HandleScope scope(isolate); HandleScope scope(isolate);
ASSERT(args.length() == 1); ASSERT(args.length() == 1);
CONVERT_ARG_HANDLE_CHECKED(JSArray, prototype, 0); CONVERT_ARG_HANDLE_CHECKED(JSArray, prototype, 0);
Object* length = prototype->length();
RUNTIME_ASSERT(length->IsSmi() && Smi::cast(length)->value() == 0);
RUNTIME_ASSERT(prototype->HasFastSmiOrObjectElements());
// This is necessary to enable fast checks for absence of elements // This is necessary to enable fast checks for absence of elements
// on Array.prototype and below. // on Array.prototype and below.
prototype->set_elements(isolate->heap()->empty_fixed_array()); prototype->set_elements(isolate->heap()->empty_fixed_array());
...@@ -3091,6 +3094,7 @@ RUNTIME_FUNCTION(Runtime_SetCode) { ...@@ -3091,6 +3094,7 @@ RUNTIME_FUNCTION(Runtime_SetCode) {
Handle<SharedFunctionInfo> target_shared(target->shared()); Handle<SharedFunctionInfo> target_shared(target->shared());
Handle<SharedFunctionInfo> source_shared(source->shared()); Handle<SharedFunctionInfo> source_shared(source->shared());
RUNTIME_ASSERT(!source_shared->bound());
if (!Compiler::EnsureCompiled(source, KEEP_EXCEPTION)) { if (!Compiler::EnsureCompiled(source, KEEP_EXCEPTION)) {
return isolate->heap()->exception(); return isolate->heap()->exception();
...@@ -6326,6 +6330,7 @@ RUNTIME_FUNCTION(Runtime_TruncateString) { ...@@ -6326,6 +6330,7 @@ RUNTIME_FUNCTION(Runtime_TruncateString) {
ASSERT(args.length() == 2); ASSERT(args.length() == 2);
CONVERT_ARG_HANDLE_CHECKED(SeqString, string, 0); CONVERT_ARG_HANDLE_CHECKED(SeqString, string, 0);
CONVERT_SMI_ARG_CHECKED(new_length, 1); CONVERT_SMI_ARG_CHECKED(new_length, 1);
RUNTIME_ASSERT(new_length >= 0);
return *SeqString::Truncate(string, new_length); return *SeqString::Truncate(string, new_length);
} }
...@@ -6771,6 +6776,7 @@ RUNTIME_FUNCTION(Runtime_StringSplit) { ...@@ -6771,6 +6776,7 @@ RUNTIME_FUNCTION(Runtime_StringSplit) {
CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); CONVERT_ARG_HANDLE_CHECKED(String, subject, 0);
CONVERT_ARG_HANDLE_CHECKED(String, pattern, 1); CONVERT_ARG_HANDLE_CHECKED(String, pattern, 1);
CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[2]); CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[2]);
RUNTIME_ASSERT(limit > 0);
int subject_length = subject->length(); int subject_length = subject->length();
int pattern_length = pattern->length(); int pattern_length = pattern->length();
...@@ -7204,7 +7210,6 @@ static inline int StringBuilderConcatLength(int special_length, ...@@ -7204,7 +7210,6 @@ static inline int StringBuilderConcatLength(int special_length,
*one_byte = false; *one_byte = false;
} }
} else { } else {
ASSERT(!elt->IsTheHole());
return -1; return -1;
} }
if (increment > String::kMaxLength - position) { if (increment > String::kMaxLength - position) {
...@@ -7233,6 +7238,7 @@ RUNTIME_FUNCTION(Runtime_StringBuilderConcat) { ...@@ -7233,6 +7238,7 @@ RUNTIME_FUNCTION(Runtime_StringBuilderConcat) {
// This assumption is used by the slice encoding in one or two smis. // This assumption is used by the slice encoding in one or two smis.
ASSERT(Smi::kMaxValue >= String::kMaxLength); ASSERT(Smi::kMaxValue >= String::kMaxLength);
RUNTIME_ASSERT(array->HasFastElements());
JSObject::EnsureCanContainHeapObjectElements(array); JSObject::EnsureCanContainHeapObjectElements(array);
int special_length = special->length(); int special_length = special->length();
...@@ -8202,10 +8208,10 @@ RUNTIME_FUNCTION(Runtime_FunctionBindArguments) { ...@@ -8202,10 +8208,10 @@ RUNTIME_FUNCTION(Runtime_FunctionBindArguments) {
GetCallerArguments(isolate, 0, &argc); GetCallerArguments(isolate, 0, &argc);
// Don't count the this-arg. // Don't count the this-arg.
if (argc > 0) { if (argc > 0) {
ASSERT(*arguments[0] == args[2]); RUNTIME_ASSERT(*arguments[0] == args[2]);
argc--; argc--;
} else { } else {
ASSERT(args[2]->IsUndefined()); RUNTIME_ASSERT(args[2]->IsUndefined());
} }
// Initialize array of bindings (function, this, and any existing arguments // Initialize array of bindings (function, this, and any existing arguments
// if the function was already bound). // if the function was already bound).
...@@ -8214,6 +8220,7 @@ RUNTIME_FUNCTION(Runtime_FunctionBindArguments) { ...@@ -8214,6 +8220,7 @@ RUNTIME_FUNCTION(Runtime_FunctionBindArguments) {
if (bindee->IsJSFunction() && JSFunction::cast(*bindee)->shared()->bound()) { if (bindee->IsJSFunction() && JSFunction::cast(*bindee)->shared()->bound()) {
Handle<FixedArray> old_bindings( Handle<FixedArray> old_bindings(
JSFunction::cast(*bindee)->function_bindings()); JSFunction::cast(*bindee)->function_bindings());
RUNTIME_ASSERT(old_bindings->length() > JSFunction::kBoundFunctionIndex);
new_bindings = new_bindings =
isolate->factory()->NewFixedArray(old_bindings->length() + argc); isolate->factory()->NewFixedArray(old_bindings->length() + argc);
bindee = Handle<Object>(old_bindings->get(JSFunction::kBoundFunctionIndex), bindee = Handle<Object>(old_bindings->get(JSFunction::kBoundFunctionIndex),
...@@ -8256,7 +8263,7 @@ RUNTIME_FUNCTION(Runtime_BoundFunctionGetBindings) { ...@@ -8256,7 +8263,7 @@ RUNTIME_FUNCTION(Runtime_BoundFunctionGetBindings) {
Handle<JSFunction> function = Handle<JSFunction>::cast(callable); Handle<JSFunction> function = Handle<JSFunction>::cast(callable);
if (function->shared()->bound()) { if (function->shared()->bound()) {
Handle<FixedArray> bindings(function->function_bindings()); Handle<FixedArray> bindings(function->function_bindings());
ASSERT(bindings->map() == isolate->heap()->fixed_cow_array_map()); RUNTIME_ASSERT(bindings->map() == isolate->heap()->fixed_cow_array_map());
return *isolate->factory()->NewJSArrayWithElements(bindings); return *isolate->factory()->NewJSArrayWithElements(bindings);
} }
} }
...@@ -8617,6 +8624,7 @@ RUNTIME_FUNCTION(Runtime_RunningInSimulator) { ...@@ -8617,6 +8624,7 @@ RUNTIME_FUNCTION(Runtime_RunningInSimulator) {
RUNTIME_FUNCTION(Runtime_IsConcurrentRecompilationSupported) { RUNTIME_FUNCTION(Runtime_IsConcurrentRecompilationSupported) {
SealHandleScope shs(isolate); SealHandleScope shs(isolate);
ASSERT(args.length() == 0);
return isolate->heap()->ToBoolean( return isolate->heap()->ToBoolean(
isolate->concurrent_recompilation_enabled()); isolate->concurrent_recompilation_enabled());
} }
...@@ -9662,6 +9670,7 @@ RUNTIME_FUNCTION(Runtime_DateParseString) { ...@@ -9662,6 +9670,7 @@ RUNTIME_FUNCTION(Runtime_DateParseString) {
CONVERT_ARG_HANDLE_CHECKED(String, str, 0); CONVERT_ARG_HANDLE_CHECKED(String, str, 0);
CONVERT_ARG_HANDLE_CHECKED(JSArray, output, 1); CONVERT_ARG_HANDLE_CHECKED(JSArray, output, 1);
RUNTIME_ASSERT(output->HasFastElements());
JSObject::EnsureCanContainHeapObjectElements(output); JSObject::EnsureCanContainHeapObjectElements(output);
RUNTIME_ASSERT(output->HasFastObjectElements()); RUNTIME_ASSERT(output->HasFastObjectElements());
Handle<FixedArray> output_array(FixedArray::cast(output->elements())); Handle<FixedArray> output_array(FixedArray::cast(output->elements()));
...@@ -14541,12 +14550,15 @@ RUNTIME_FUNCTION(Runtime_LoadMutableDouble) { ...@@ -14541,12 +14550,15 @@ RUNTIME_FUNCTION(Runtime_LoadMutableDouble) {
CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
CONVERT_ARG_HANDLE_CHECKED(Smi, index, 1); CONVERT_ARG_HANDLE_CHECKED(Smi, index, 1);
int idx = index->value() >> 1; int idx = index->value() >> 1;
int inobject_properties = object->map()->inobject_properties();
if (idx < 0) { if (idx < 0) {
idx = -idx + object->map()->inobject_properties() - 1; idx = -idx + inobject_properties - 1;
} }
int max_idx = object->properties()->length() + inobject_properties;
RUNTIME_ASSERT(idx < max_idx);
Handle<Object> raw_value(object->RawFastPropertyAt(idx), isolate); Handle<Object> raw_value(object->RawFastPropertyAt(idx), isolate);
RUNTIME_ASSERT(raw_value->IsNumber() || raw_value->IsUninitialized()); RUNTIME_ASSERT(raw_value->IsNumber() || raw_value->IsUninitialized());
return *JSObject::FastPropertyAt(object, Representation::Double(), idx); return *Object::NewStorageFor(isolate, raw_value, Representation::Double());
} }
......
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