Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Unified Diff: test/mjsunit/get-prototype-of.js

Issue 1051523003: [es6] Object.getPrototypeOf should work with values (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/v8natives.js ('k') | test/mjsunit/harmony/set-prototype-of.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/get-prototype-of.js
diff --git a/test/mjsunit/get-prototype-of.js b/test/mjsunit/get-prototype-of.js
index c2a492a3cf3a3872c94829a97b89bd09f0e9133f..3c6c16af8ea4ecca3b68cfdc573b5508f57e6877 100644
--- a/test/mjsunit/get-prototype-of.js
+++ b/test/mjsunit/get-prototype-of.js
@@ -25,43 +25,77 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+assertThrows(function() {
+ Object.getPrototypeOf(undefined);
+}, TypeError);
-function TryGetPrototypeOfNonObject(x) {
- var caught = 0;
- try {
- Object.getPrototypeOf(x);
- } catch (e) {
- caught = e;
- }
+assertThrows(function() {
+ Object.getPrototypeOf(null);
+}, TypeError);
- assertTrue(caught instanceof TypeError);
-};
-
-function GetPrototypeOfObject(x) {
- assertDoesNotThrow(Object.getPrototypeOf(x));
- assertNotNull(Object.getPrototypeOf(x));
- assertEquals(Object.getPrototypeOf(x), x.__proto__);
-}
function F(){};
+var y = new F();
-// Non object
-var x = 10;
+assertSame(Object.getPrototypeOf(y), F.prototype);
+assertSame(Object.getPrototypeOf(F), Function.prototype);
-// Object
-var y = new F();
+assertSame(Object.getPrototypeOf({x: 5}), Object.prototype);
+assertSame(Object.getPrototypeOf({x: 5, __proto__: null}), null);
+
+assertSame(Object.getPrototypeOf([1, 2]), Array.prototype);
+
+
+assertSame(Object.getPrototypeOf(1), Number.prototype);
+assertSame(Object.getPrototypeOf(true), Boolean.prototype);
+assertSame(Object.getPrototypeOf(false), Boolean.prototype);
+assertSame(Object.getPrototypeOf('str'), String.prototype);
+assertSame(Object.getPrototypeOf(Symbol()), Symbol.prototype);
+
+
+// Builtin constructors.
+var functions = [
+ Array,
+ ArrayBuffer,
+ Boolean,
+ // DataView,
+ Date,
+ Error,
+ EvalError,
+ Float32Array,
+ Float64Array,
+ Function,
+ Int16Array,
+ Int32Array,
+ Int8Array,
+ Map,
+ Number,
+ Object,
+ // Promise,
+ RangeError,
+ ReferenceError,
+ RegExp,
+ Set,
+ String,
+ // Symbol, not constructible
+ SyntaxError,
+ TypeError,
+ URIError,
+ Uint16Array,
+ Uint32Array,
+ Uint8Array,
+ Uint8ClampedArray,
+ WeakMap,
+ WeakSet,
+];
+
+for (var f of functions) {
+ assertSame(Object.getPrototypeOf(f), Function.prototype);
+ assertSame(Object.getPrototypeOf(new f), f.prototype);
+}
-// Make sure that TypeError exceptions are thrown when non-objects are passed
-// as argument
-TryGetPrototypeOfNonObject(0);
-TryGetPrototypeOfNonObject(null);
-TryGetPrototypeOfNonObject('Testing');
-TryGetPrototypeOfNonObject(x);
+var p = new Promise(function() {});
+assertSame(Object.getPrototypeOf(p), Promise.prototype);
-// Make sure the real objects have this method and that it returns the
-// actual prototype object. Also test for Functions and RegExp.
-GetPrototypeOfObject(this);
-GetPrototypeOfObject(y);
-GetPrototypeOfObject({x:5});
-GetPrototypeOfObject(F);
-GetPrototypeOfObject(RegExp);
+var dv = new DataView(new ArrayBuffer());
+assertSame(Object.getPrototypeOf(dv), DataView.prototype);
« no previous file with comments | « src/v8natives.js ('k') | test/mjsunit/harmony/set-prototype-of.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698