OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 13374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13385 CHECK(!arr->CreateDataProperty(env.local(), v8_str("length"), | 13385 CHECK(!arr->CreateDataProperty(env.local(), v8_str("length"), |
13386 v8::Integer::New(isolate, 1)).FromJust()); | 13386 v8::Integer::New(isolate, 1)).FromJust()); |
13387 CHECK(!try_catch.HasCaught()); | 13387 CHECK(!try_catch.HasCaught()); |
13388 } | 13388 } |
13389 { | 13389 { |
13390 // Special cases for arrays: index exceeds the array's length | 13390 // Special cases for arrays: index exceeds the array's length |
13391 v8::TryCatch try_catch(isolate); | 13391 v8::TryCatch try_catch(isolate); |
13392 CHECK(arr->CreateDataProperty(env.local(), 1, v8::Integer::New(isolate, 23)) | 13392 CHECK(arr->CreateDataProperty(env.local(), 1, v8::Integer::New(isolate, 23)) |
13393 .FromJust()); | 13393 .FromJust()); |
13394 CHECK(!try_catch.HasCaught()); | 13394 CHECK(!try_catch.HasCaught()); |
13395 CHECK_EQ(2, arr->Length()); | 13395 CHECK_EQ(2U, arr->Length()); |
13396 v8::Local<v8::Value> val = arr->Get(env.local(), 1).ToLocalChecked(); | 13396 v8::Local<v8::Value> val = arr->Get(env.local(), 1).ToLocalChecked(); |
13397 CHECK(val->IsNumber()); | 13397 CHECK(val->IsNumber()); |
13398 CHECK_EQ(23.0, val->NumberValue(env.local()).FromJust()); | 13398 CHECK_EQ(23.0, val->NumberValue(env.local()).FromJust()); |
13399 | 13399 |
13400 // Set an existing entry. | 13400 // Set an existing entry. |
13401 CHECK(arr->CreateDataProperty(env.local(), 0, v8::Integer::New(isolate, 42)) | 13401 CHECK(arr->CreateDataProperty(env.local(), 0, v8::Integer::New(isolate, 42)) |
13402 .FromJust()); | 13402 .FromJust()); |
13403 CHECK(!try_catch.HasCaught()); | 13403 CHECK(!try_catch.HasCaught()); |
13404 val = arr->Get(env.local(), 0).ToLocalChecked(); | 13404 val = arr->Get(env.local(), 0).ToLocalChecked(); |
13405 CHECK(val->IsNumber()); | 13405 CHECK(val->IsNumber()); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13488 CHECK(!arr->DefineOwnProperty(env.local(), v8_str("length"), | 13488 CHECK(!arr->DefineOwnProperty(env.local(), v8_str("length"), |
13489 v8::Integer::New(isolate, 1)).FromJust()); | 13489 v8::Integer::New(isolate, 1)).FromJust()); |
13490 CHECK(!try_catch.HasCaught()); | 13490 CHECK(!try_catch.HasCaught()); |
13491 } | 13491 } |
13492 { | 13492 { |
13493 // Special cases for arrays: index exceeds the array's length | 13493 // Special cases for arrays: index exceeds the array's length |
13494 v8::TryCatch try_catch(isolate); | 13494 v8::TryCatch try_catch(isolate); |
13495 CHECK(arr->DefineOwnProperty(env.local(), v8_str("1"), | 13495 CHECK(arr->DefineOwnProperty(env.local(), v8_str("1"), |
13496 v8::Integer::New(isolate, 23)).FromJust()); | 13496 v8::Integer::New(isolate, 23)).FromJust()); |
13497 CHECK(!try_catch.HasCaught()); | 13497 CHECK(!try_catch.HasCaught()); |
13498 CHECK_EQ(2, arr->Length()); | 13498 CHECK_EQ(2U, arr->Length()); |
13499 v8::Local<v8::Value> val = arr->Get(env.local(), 1).ToLocalChecked(); | 13499 v8::Local<v8::Value> val = arr->Get(env.local(), 1).ToLocalChecked(); |
13500 CHECK(val->IsNumber()); | 13500 CHECK(val->IsNumber()); |
13501 CHECK_EQ(23.0, val->NumberValue(env.local()).FromJust()); | 13501 CHECK_EQ(23.0, val->NumberValue(env.local()).FromJust()); |
13502 | 13502 |
13503 // Set an existing entry. | 13503 // Set an existing entry. |
13504 CHECK(arr->DefineOwnProperty(env.local(), v8_str("0"), | 13504 CHECK(arr->DefineOwnProperty(env.local(), v8_str("0"), |
13505 v8::Integer::New(isolate, 42)).FromJust()); | 13505 v8::Integer::New(isolate, 42)).FromJust()); |
13506 CHECK(!try_catch.HasCaught()); | 13506 CHECK(!try_catch.HasCaught()); |
13507 val = arr->Get(env.local(), 0).ToLocalChecked(); | 13507 val = arr->Get(env.local(), 0).ToLocalChecked(); |
13508 CHECK(val->IsNumber()); | 13508 CHECK(val->IsNumber()); |
(...skipping 7861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21370 | 21370 |
21371 TEST(Map) { | 21371 TEST(Map) { |
21372 v8::Isolate* isolate = CcTest::isolate(); | 21372 v8::Isolate* isolate = CcTest::isolate(); |
21373 v8::HandleScope handle_scope(isolate); | 21373 v8::HandleScope handle_scope(isolate); |
21374 LocalContext env; | 21374 LocalContext env; |
21375 | 21375 |
21376 v8::Local<v8::Map> map = v8::Map::New(isolate); | 21376 v8::Local<v8::Map> map = v8::Map::New(isolate); |
21377 CHECK(map->IsObject()); | 21377 CHECK(map->IsObject()); |
21378 CHECK(map->IsMap()); | 21378 CHECK(map->IsMap()); |
21379 CHECK(map->GetPrototype()->StrictEquals(CompileRun("Map.prototype"))); | 21379 CHECK(map->GetPrototype()->StrictEquals(CompileRun("Map.prototype"))); |
21380 CHECK_EQ(0, map->Size()); | 21380 CHECK_EQ(0U, map->Size()); |
21381 | 21381 |
21382 v8::Local<v8::Value> val = CompileRun("new Map([[1, 2], [3, 4]])"); | 21382 v8::Local<v8::Value> val = CompileRun("new Map([[1, 2], [3, 4]])"); |
21383 CHECK(val->IsMap()); | 21383 CHECK(val->IsMap()); |
21384 map = v8::Local<v8::Map>::Cast(val); | 21384 map = v8::Local<v8::Map>::Cast(val); |
21385 CHECK_EQ(2, map->Size()); | 21385 CHECK_EQ(2U, map->Size()); |
21386 | 21386 |
21387 v8::Local<v8::Array> contents = map->AsArray(); | 21387 v8::Local<v8::Array> contents = map->AsArray(); |
21388 CHECK_EQ(4, contents->Length()); | 21388 CHECK_EQ(4U, contents->Length()); |
21389 CHECK_EQ(1, contents->Get(0).As<v8::Int32>()->Value()); | 21389 CHECK_EQ(1, contents->Get(0).As<v8::Int32>()->Value()); |
21390 CHECK_EQ(2, contents->Get(1).As<v8::Int32>()->Value()); | 21390 CHECK_EQ(2, contents->Get(1).As<v8::Int32>()->Value()); |
21391 CHECK_EQ(3, contents->Get(2).As<v8::Int32>()->Value()); | 21391 CHECK_EQ(3, contents->Get(2).As<v8::Int32>()->Value()); |
21392 CHECK_EQ(4, contents->Get(3).As<v8::Int32>()->Value()); | 21392 CHECK_EQ(4, contents->Get(3).As<v8::Int32>()->Value()); |
21393 | 21393 |
21394 map = v8::Map::FromArray(env.local(), contents).ToLocalChecked(); | 21394 map = v8::Map::FromArray(env.local(), contents).ToLocalChecked(); |
21395 CHECK_EQ(2, map->Size()); | 21395 CHECK_EQ(2U, map->Size()); |
21396 | 21396 |
21397 // Odd lengths result in a null MaybeLocal. | 21397 // Odd lengths result in a null MaybeLocal. |
21398 contents = v8::Array::New(isolate, 41); | 21398 contents = v8::Array::New(isolate, 41); |
21399 CHECK(v8::Map::FromArray(env.local(), contents).IsEmpty()); | 21399 CHECK(v8::Map::FromArray(env.local(), contents).IsEmpty()); |
21400 } | 21400 } |
21401 | 21401 |
21402 | 21402 |
21403 TEST(Set) { | 21403 TEST(Set) { |
21404 v8::Isolate* isolate = CcTest::isolate(); | 21404 v8::Isolate* isolate = CcTest::isolate(); |
21405 v8::HandleScope handle_scope(isolate); | 21405 v8::HandleScope handle_scope(isolate); |
21406 LocalContext env; | 21406 LocalContext env; |
21407 | 21407 |
21408 v8::Local<v8::Set> set = v8::Set::New(isolate); | 21408 v8::Local<v8::Set> set = v8::Set::New(isolate); |
21409 CHECK(set->IsObject()); | 21409 CHECK(set->IsObject()); |
21410 CHECK(set->IsSet()); | 21410 CHECK(set->IsSet()); |
21411 CHECK(set->GetPrototype()->StrictEquals(CompileRun("Set.prototype"))); | 21411 CHECK(set->GetPrototype()->StrictEquals(CompileRun("Set.prototype"))); |
21412 CHECK_EQ(0, set->Size()); | 21412 CHECK_EQ(0U, set->Size()); |
21413 | 21413 |
21414 v8::Local<v8::Value> val = CompileRun("new Set([1, 2])"); | 21414 v8::Local<v8::Value> val = CompileRun("new Set([1, 2])"); |
21415 CHECK(val->IsSet()); | 21415 CHECK(val->IsSet()); |
21416 set = v8::Local<v8::Set>::Cast(val); | 21416 set = v8::Local<v8::Set>::Cast(val); |
21417 CHECK_EQ(2, set->Size()); | 21417 CHECK_EQ(2U, set->Size()); |
21418 | 21418 |
21419 v8::Local<v8::Array> keys = set->AsArray(); | 21419 v8::Local<v8::Array> keys = set->AsArray(); |
21420 CHECK_EQ(2, keys->Length()); | 21420 CHECK_EQ(2U, keys->Length()); |
21421 CHECK_EQ(1, keys->Get(0).As<v8::Int32>()->Value()); | 21421 CHECK_EQ(1, keys->Get(0).As<v8::Int32>()->Value()); |
21422 CHECK_EQ(2, keys->Get(1).As<v8::Int32>()->Value()); | 21422 CHECK_EQ(2, keys->Get(1).As<v8::Int32>()->Value()); |
21423 | 21423 |
21424 set = v8::Set::FromArray(env.local(), keys).ToLocalChecked(); | 21424 set = v8::Set::FromArray(env.local(), keys).ToLocalChecked(); |
21425 CHECK_EQ(2, set->Size()); | 21425 CHECK_EQ(2U, set->Size()); |
21426 } | 21426 } |
OLD | NEW |