}
-void LookupIterator::WriteDataValue(Handle<Object> value) {
+Handle<Object> LookupIterator::WriteDataValue(Handle<Object> value) {
DCHECK_EQ(DATA, state_);
Handle<JSObject> holder = GetHolder<JSObject>();
if (holder_map_->is_dictionary_map()) {
if (holder->IsGlobalObject()) {
Handle<PropertyCell> cell(
PropertyCell::cast(property_dictionary->ValueAt(dictionary_entry())));
- PropertyCell::SetValueInferType(cell, value);
+ value = PropertyCell::SetValueInferType(cell, value);
} else {
property_dictionary->ValueAtPut(dictionary_entry(), *value);
}
} else {
DCHECK_EQ(v8::internal::CONSTANT, property_details_.type());
}
+ return value;
}
Handle<PropertyCell> GetPropertyCell() const;
Handle<Object> GetAccessors() const;
Handle<Object> GetDataValue() const;
- void WriteDataValue(Handle<Object> value);
+ // Usually returns the value that was passed in, but may perform
+ // non-observable modifications on it, such as internalize strings.
+ Handle<Object> WriteDataValue(Handle<Object> value);
// Checks whether the receiver is an indexed exotic object
// and name is a special numeric index.
it->PrepareForDataProperty(value);
// Write the property value.
- it->WriteDataValue(value);
+ value = it->WriteDataValue(value);
// Send the change record if there are observers.
if (is_observed && !value->SameValue(*maybe_old.ToHandleChecked())) {
JSObject::AddSlowProperty(receiver, it->name(), value, attributes);
} else {
// Write the property value.
- it->WriteDataValue(value);
+ value = it->WriteDataValue(value);
}
// Send the change record if there are observers.
it.ReconfigureDataProperty(value, attributes);
it.PrepareForDataProperty(value);
- it.WriteDataValue(value);
+ value = it.WriteDataValue(value);
if (is_observed) {
RETURN_ON_EXCEPTION(
it.ReconfigureDataProperty(value, attributes);
it.PrepareForDataProperty(value);
- it.WriteDataValue(value);
+ value = it.WriteDataValue(value);
if (is_observed) {
if (old_value->SameValue(*value)) {
}
-void PropertyCell::SetValueInferType(Handle<PropertyCell> cell,
- Handle<Object> value) {
+Handle<Object> PropertyCell::SetValueInferType(Handle<PropertyCell> cell,
+ Handle<Object> value) {
+ // Heuristic: if a string is stored in a previously uninitialized
+ // property cell, internalize it.
+ if ((cell->type()->Is(HeapType::None()) ||
+ cell->type()->Is(HeapType::Undefined())) &&
+ value->IsString()) {
+ value = cell->GetIsolate()->factory()->InternalizeString(
+ Handle<String>::cast(value));
+ }
cell->set_value(*value);
if (!HeapType::Any()->Is(cell->type())) {
Handle<HeapType> new_type = UpdatedType(cell, value);
cell->set_type(*new_type);
}
+ return value;
}
// of the cell's current type and the value's type. If the change causes
// a change of the type of the cell's contents, code dependent on the cell
// will be deoptimized.
- static void SetValueInferType(Handle<PropertyCell> cell,
- Handle<Object> value);
+ // Usually returns the value that was passed in, but may perform
+ // non-observable modifications on it, such as internalize strings.
+ static Handle<Object> SetValueInferType(Handle<PropertyCell> cell,
+ Handle<Object> value);
// Computes the new type of the cell's contents for the given value, but
// without actually modifying the 'type' field.
"var underlying = 'abcdefghijklmnopqrstuvwxyz';"
"underlying")->ToString(CcTest::isolate());
v8::Handle<v8::String> slice = CompileRun(
- "var slice = underlying.slice(1);"
+ "var slice = '';"
+ "slice = underlying.slice(1);"
"slice")->ToString(CcTest::isolate());
CHECK(v8::Utils::OpenHandle(*slice)->IsSlicedString());
CHECK(v8::Utils::OpenHandle(*underlying)->IsSeqOneByteString());
v8::Local<v8::Value> result;
Handle<String> string;
const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';";
- const char* slice = "var slice = str.slice(1,-1); slice";
+ const char* slice = "var slice = ''; slice = str.slice(1,-1); slice";
const char* slice_from_slice = "slice.slice(1,-1);";
CompileRun(init);
// Flags: --string-slices --expose-externalize-string
-var a = "abcdefghijklmnopqrstuvqxy"+"z";
+var a = "internalized dummy";
+a = "abcdefghijklmnopqrstuvqxy"+"z";
externalizeString(a, true);
assertEquals('b', a.substring(1).charAt(0));
// Flags: --allow-natives-syntax
-var string = "hello world";
-var expected = "Hello " + "world";
+var string = "internalized dummy";
+var expected = "internalized dummy";
+string = "hello world";
+expected = "Hello " + "world";
function Capitalize() {
%_OneByteSeqStringSetChar(0, 0x48, string);
}
utf.substring(5,1) + utf.substring(3,7));
// Externalizing strings.
-var a = "123456789" + "qwertyuiopasdfghjklzxcvbnm";
+var a = "internalized dummy";
+a = "123456789" + "qwertyuiopasdfghjklzxcvbnm";
var b = "23456789qwertyuiopasdfghjklzxcvbn"
assertEquals(a.slice(1,-1), b);