OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 7095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7106 v8::HandleScope scope; | 7106 v8::HandleScope scope; |
7107 LocalContext context; | 7107 LocalContext context; |
7108 v8::Handle<v8::Object> obj = v8::Object::New(); | 7108 v8::Handle<v8::Object> obj = v8::Object::New(); |
7109 v8::Handle<v8::FunctionTemplate> func_templ = v8::FunctionTemplate::New(); | 7109 v8::Handle<v8::FunctionTemplate> func_templ = v8::FunctionTemplate::New(); |
7110 v8::Handle<v8::String> foo_string = v8::String::New("foo"); | 7110 v8::Handle<v8::String> foo_string = v8::String::New("foo"); |
7111 obj->Set(foo_string, func_templ->GetFunction()); | 7111 obj->Set(foo_string, func_templ->GetFunction()); |
7112 v8::Handle<v8::Object> obj_clone = obj->Clone(); | 7112 v8::Handle<v8::Object> obj_clone = obj->Clone(); |
7113 obj_clone->Set(foo_string, v8::String::New("Hello")); | 7113 obj_clone->Set(foo_string, v8::String::New("Hello")); |
7114 CHECK(!obj->Get(foo_string)->IsUndefined()); | 7114 CHECK(!obj->Get(foo_string)->IsUndefined()); |
7115 } | 7115 } |
| 7116 |
| 7117 |
| 7118 // Regression test for http://crbug.com/16276. |
| 7119 THREADED_TEST(Regress16276) { |
| 7120 v8::HandleScope scope; |
| 7121 LocalContext context; |
| 7122 // Force the IC in f to be a dictionary load IC. |
| 7123 CompileRun("function f(obj) { return obj.x; }\n" |
| 7124 "var obj = { x: { foo: 42 }, y: 87 };\n" |
| 7125 "var x = obj.x;\n" |
| 7126 "delete obj.y;\n" |
| 7127 "for (var i = 0; i < 5; i++) f(obj);"); |
| 7128 // Detach the global object to make 'this' refer directly to the |
| 7129 // global object (not the proxy), and make sure that the dictionary |
| 7130 // load IC doesn't mess up loading directly from the global object. |
| 7131 context->DetachGlobal(); |
| 7132 CHECK_EQ(42, CompileRun("f(this).foo")->Int32Value()); |
| 7133 } |
| 7134 |
| 7135 |
| 7136 THREADED_TEST(PixelArray) { |
| 7137 v8::HandleScope scope; |
| 7138 LocalContext context; |
| 7139 const int kElementCount = 40; |
| 7140 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); |
| 7141 i::Handle<i::PixelArray> pixels = i::Factory::NewPixelArray(kElementCount, |
| 7142 pixel_data); |
| 7143 i::Heap::CollectAllGarbage(); // Force GC to trigger verification. |
| 7144 for (int i = 0; i < kElementCount; i++) { |
| 7145 pixels->set(i, i); |
| 7146 } |
| 7147 i::Heap::CollectAllGarbage(); // Force GC to trigger verification. |
| 7148 for (int i = 0; i < kElementCount; i++) { |
| 7149 CHECK_EQ(i, pixels->get(i)); |
| 7150 CHECK_EQ(i, pixel_data[i]); |
| 7151 } |
| 7152 |
| 7153 v8::Handle<v8::Object> obj = v8::Object::New(); |
| 7154 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); |
| 7155 // Set the elements to be the pixels. |
| 7156 // jsobj->set_elements(*pixels); |
| 7157 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); |
| 7158 CHECK_EQ(1, i::Smi::cast(jsobj->GetElement(1))->value()); |
| 7159 obj->Set(v8_str("field"), v8::Int32::New(1503)); |
| 7160 context->Global()->Set(v8_str("pixels"), obj); |
| 7161 v8::Handle<v8::Value> result = CompileRun("pixels.field"); |
| 7162 CHECK_EQ(1503, result->Int32Value()); |
| 7163 result = CompileRun("pixels[1]"); |
| 7164 CHECK_EQ(1, result->Int32Value()); |
| 7165 result = CompileRun("var sum = 0;" |
| 7166 "for (var i = 0; i < 8; i++) {" |
| 7167 " sum += pixels[i];" |
| 7168 "}" |
| 7169 "sum;"); |
| 7170 CHECK_EQ(28, result->Int32Value()); |
| 7171 |
| 7172 i::Handle<i::Smi> value(i::Smi::FromInt(2)); |
| 7173 i::SetElement(jsobj, 1, value); |
| 7174 CHECK_EQ(2, i::Smi::cast(jsobj->GetElement(1))->value()); |
| 7175 *value.location() = i::Smi::FromInt(256); |
| 7176 i::SetElement(jsobj, 1, value); |
| 7177 CHECK_EQ(255, i::Smi::cast(jsobj->GetElement(1))->value()); |
| 7178 *value.location() = i::Smi::FromInt(-1); |
| 7179 i::SetElement(jsobj, 1, value); |
| 7180 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(1))->value()); |
| 7181 |
| 7182 result = CompileRun("for (var i = 0; i < 8; i++) {" |
| 7183 " pixels[i] = (i * 65) - 109;" |
| 7184 "}" |
| 7185 "pixels[1] + pixels[6];"); |
| 7186 CHECK_EQ(255, result->Int32Value()); |
| 7187 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(0))->value()); |
| 7188 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(1))->value()); |
| 7189 CHECK_EQ(21, i::Smi::cast(jsobj->GetElement(2))->value()); |
| 7190 CHECK_EQ(86, i::Smi::cast(jsobj->GetElement(3))->value()); |
| 7191 CHECK_EQ(151, i::Smi::cast(jsobj->GetElement(4))->value()); |
| 7192 CHECK_EQ(216, i::Smi::cast(jsobj->GetElement(5))->value()); |
| 7193 CHECK_EQ(255, i::Smi::cast(jsobj->GetElement(6))->value()); |
| 7194 CHECK_EQ(255, i::Smi::cast(jsobj->GetElement(7))->value()); |
| 7195 result = CompileRun("var sum = 0;" |
| 7196 "for (var i = 0; i < 8; i++) {" |
| 7197 " sum += pixels[i];" |
| 7198 "}" |
| 7199 "sum;"); |
| 7200 CHECK_EQ(984, result->Int32Value()); |
| 7201 |
| 7202 result = CompileRun("for (var i = 0; i < 8; i++) {" |
| 7203 " pixels[i] = (i * 1.1);" |
| 7204 "}" |
| 7205 "pixels[1] + pixels[6];"); |
| 7206 CHECK_EQ(8, result->Int32Value()); |
| 7207 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(0))->value()); |
| 7208 CHECK_EQ(1, i::Smi::cast(jsobj->GetElement(1))->value()); |
| 7209 CHECK_EQ(2, i::Smi::cast(jsobj->GetElement(2))->value()); |
| 7210 CHECK_EQ(3, i::Smi::cast(jsobj->GetElement(3))->value()); |
| 7211 CHECK_EQ(4, i::Smi::cast(jsobj->GetElement(4))->value()); |
| 7212 CHECK_EQ(6, i::Smi::cast(jsobj->GetElement(5))->value()); |
| 7213 CHECK_EQ(7, i::Smi::cast(jsobj->GetElement(6))->value()); |
| 7214 CHECK_EQ(8, i::Smi::cast(jsobj->GetElement(7))->value()); |
| 7215 |
| 7216 result = CompileRun("for (var i = 0; i < 8; i++) {" |
| 7217 " pixels[7] = undefined;" |
| 7218 "}" |
| 7219 "pixels[7];"); |
| 7220 CHECK_EQ(0, result->Int32Value()); |
| 7221 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(7))->value()); |
| 7222 |
| 7223 result = CompileRun("for (var i = 0; i < 8; i++) {" |
| 7224 " pixels[6] = '2.3';" |
| 7225 "}" |
| 7226 "pixels[6];"); |
| 7227 CHECK_EQ(2, result->Int32Value()); |
| 7228 CHECK_EQ(2, i::Smi::cast(jsobj->GetElement(6))->value()); |
| 7229 |
| 7230 result = CompileRun("for (var i = 0; i < 8; i++) {" |
| 7231 " pixels[5] = NaN;" |
| 7232 "}" |
| 7233 "pixels[5];"); |
| 7234 CHECK_EQ(0, result->Int32Value()); |
| 7235 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(5))->value()); |
| 7236 |
| 7237 result = CompileRun("pixels[3] = 33;" |
| 7238 "delete pixels[3];" |
| 7239 "pixels[3];"); |
| 7240 CHECK_EQ(33, result->Int32Value()); |
| 7241 |
| 7242 result = CompileRun("pixels[0] = 10; pixels[1] = 11;" |
| 7243 "pixels[2] = 12; pixels[3] = 13;" |
| 7244 "pixels.__defineGetter__('2'," |
| 7245 "function() { return 120; });" |
| 7246 "pixels[2];"); |
| 7247 CHECK_EQ(12, result->Int32Value()); |
| 7248 |
| 7249 result = CompileRun("var js_array = new Array(40);" |
| 7250 "js_array[0] = 77;" |
| 7251 "js_array;"); |
| 7252 CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value()); |
| 7253 |
| 7254 result = CompileRun("pixels[1] = 23;" |
| 7255 "pixels.__proto__ = [];" |
| 7256 "js_array.__proto__ = pixels;" |
| 7257 "js_array.concat(pixels);"); |
| 7258 CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value()); |
| 7259 CHECK_EQ(23, v8::Object::Cast(*result)->Get(v8_str("1"))->Int32Value()); |
| 7260 |
| 7261 free(pixel_data); |
| 7262 } |
OLD | NEW |