Fix bug 557: Disallow user side allocation of ImmutableArray. Also added "instantiation-checks" for some other VM-internal classes.

Review URL: http://codereview.chromium.org//8648003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1811 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
srdjan@google.com
2011-11-23 19:48:25 +00:00
parent 9f230a34c6
commit 4c267997cd
7 changed files with 67 additions and 2 deletions
+5
View File
@@ -161,6 +161,11 @@ class ObjectArray<T> implements List<T> {
// the inline cache misses.
class ImmutableArray<T> implements List<T> {
factory ImmutableArray._uninstantiable() {
throw const UnsupportedOperationException(
"ImmutableArray can only be allocated by the VM");
}
T operator [](int index) native "ObjectArray_getIndexed";
void operator []=(int index, T value) {
+4
View File
@@ -3,4 +3,8 @@
// BSD-style license that can be found in the LICENSE file.
class Bool implements bool {
factory Bool._uninstantiable() {
throw const UnsupportedOperationException(
"Bool can only be allocated by the VM");
}
}
+5
View File
@@ -5,6 +5,11 @@
class GrowableObjectArray<T> implements List<T> {
ObjectArray<T> backingArray;
factory GrowableObjectArray._uninstantiable() {
throw const UnsupportedOperationException(
"GrowableObjectArray can only be allocated by the VM");
}
void copyFrom(List<Object> src, int srcStart, int dstStart, int count) {
Arrays.copy(src, srcStart, this, dstStart, count);
}
+1 -1
View File
@@ -6,7 +6,7 @@
class ImmutableMap<K, V> implements Map<K, V> {
final ImmutableArray kvPairs_;
const ImmutableMap(ImmutableArray keyValuePairs)
const ImmutableMap._create(ImmutableArray keyValuePairs)
: kvPairs_ = keyValuePairs;
+16
View File
@@ -5,6 +5,10 @@
// TODO(srdjan): fix limitations.
// - shift amount must be a Smi.
class IntegerImplementation {
factory IntegerImplementation._uninstantiable() {
throw const UnsupportedOperationException(
"IntegerImplementation can only be allocated by the VM");
}
num operator +(num other) {
return other.addFromInteger(this);
}
@@ -156,6 +160,10 @@ class IntegerImplementation {
}
class Smi extends IntegerImplementation implements int {
factory Smi._uninstantiable() {
throw const UnsupportedOperationException(
"Smi can only be allocated by the VM");
}
int hashCode() {
return this;
}
@@ -166,6 +174,10 @@ class Smi extends IntegerImplementation implements int {
// Represents integers that cannot be represented by Smi but fit into 64bits.
class Mint extends IntegerImplementation implements int {
factory Mint._uninstantiable() {
throw const UnsupportedOperationException(
"Mint can only be allocated by the VM");
}
int hashCode() {
return this;
}
@@ -175,6 +187,10 @@ class Mint extends IntegerImplementation implements int {
// A number that can be represented as Smi or Mint will never be represented as
// Bigint.
class Bigint extends IntegerImplementation implements int {
factory Bigint._uninstantiable() {
throw const UnsupportedOperationException(
"Bigint can only be allocated by the VM");
}
int hashCode() {
return this;
}
+35
View File
@@ -8,6 +8,11 @@
*/
class StringBase {
factory StringBase._uninstantiable() {
throw const UnsupportedOperationException(
"StringBase can't be instaniated");
}
int hashCode() native "String_hashCode";
/**
@@ -385,6 +390,11 @@ class StringBase {
class OneByteString extends StringBase implements String {
factory OneByteString._uninstantiable() {
throw const UnsupportedOperationException(
"OneByteString can only be allocated by the VM");
}
// Checks for one-byte whitespaces only.
// TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid
// whitespaces for one byte strings.
@@ -398,6 +408,11 @@ class OneByteString extends StringBase implements String {
class TwoByteString extends StringBase implements String {
factory TwoByteString._uninstantiable() {
throw const UnsupportedOperationException(
"TwoByteString can only be allocated by the VM");
}
// Checks for one-byte whitespaces only.
// TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid
// whitespaces. Add checking for multi-byte whitespace codepoints.
@@ -410,6 +425,11 @@ class TwoByteString extends StringBase implements String {
class FourByteString extends StringBase implements String {
factory FourByteString._uninstantiable() {
throw const UnsupportedOperationException(
"FourByteString can only be allocated by the VM");
}
// Checks for one-byte whitespaces only.
// TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid
// whitespaces. Add checking for multi-byte whitespace codepoints.
@@ -422,6 +442,11 @@ class FourByteString extends StringBase implements String {
class ExternalOneByteString extends StringBase implements String {
factory ExternalOneByteString._uninstantiable() {
throw const UnsupportedOperationException(
"ExternalOneByteString can only be allocated by the VM");
}
// Checks for one-byte whitespaces only.
// TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid
// whitespaces for one byte strings.
@@ -434,6 +459,11 @@ class ExternalOneByteString extends StringBase implements String {
class ExternalTwoByteString extends StringBase implements String {
factory ExternalTwoByteString._uninstantiable() {
throw const UnsupportedOperationException(
"ExternalTwoByteString can only be allocated by the VM");
}
// Checks for one-byte whitespaces only.
// TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid
// whitespaces. Add checking for multi-byte whitespace codepoints.
@@ -446,6 +476,11 @@ class ExternalTwoByteString extends StringBase implements String {
class ExternalFourByteString extends StringBase implements String {
factory ExternalFourByteString._uninstantiable() {
throw const UnsupportedOperationException(
"ExternalFourByteString can only be allocated by the VM");
}
// Checks for one-byte whitespaces only.
// TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid
// whitespaces. Add checking for multi-byte whitespace codepoints.
+1 -1
View File
@@ -35,7 +35,7 @@ static const char* kLiteralFactoryClassName = "_LiteralFactory";
static const char* kLiteralFactoryListFromLiteralName = "List.fromLiteral";
static const char* kLiteralFactoryMapFromLiteralName = "Map.fromLiteral";
static const char* kImmutableMapName = "ImmutableMap";
static const char* kImmutableMapConstructorName = "ImmutableMap.";
static const char* kImmutableMapConstructorName = "ImmutableMap._create";
static const char* kStringClassName = "StringBase";
static const char* kInterpolateName = "_interpolate";
static const char* kThisName = "this";