/*
 * Copyright (c) 2012-2013 André Bargull
 * Alle Rechte vorbehalten / All Rights Reserved.  Use is subject to license terms.
 *
 * <https://github.com/anba/es6draft>
 */

(function Compatibility(global) {
"use strict";

const Object = global.Object,
      String = global.String;

Object.defineProperty(global, getSym("@@toStringTag"), {
  value: "global", writable: true, enumerable: false, configurable: true
});

const Object_defineProperty = Object.defineProperty,
      Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;

Object.defineProperties(Object.assign(Object.prototype, {
  __defineGetter__(name, getter) {
    var obj = (this != null ? Object(this) : global);
    Object_defineProperty(obj, name, {get: getter, enumerable: true, configurable: true});
  },
  __defineSetter__(name, setter) {
    var obj = (this != null ? Object(this) : global);
    Object_defineProperty(obj, name, {set: setter, enumerable: true, configurable: true});
  },
  __lookupGetter__(name) {
    var p = this;
    do {
      var desc = Object_getOwnPropertyDescriptor(p, name);
      if (desc && desc.get) return desc.get;
    } while ((p = p.__proto__));
  },
  __lookupSetter__(name) {
    var p = this;
    do {
      var desc = Object_getOwnPropertyDescriptor(p, name);
      if (desc && desc.set) return desc.set;
    } while ((p = p.__proto__));
  }
}), {
  __defineGetter__: {enumerable: false},
  __defineSetter__: {enumerable: false},
  __lookupGetter__: {enumerable: false},
  __lookupSetter__: {enumerable: false},
});

const String_prototype_replace = String.prototype.replace;

Object.defineProperties(Object.assign(String.prototype, {
  trimLeft() {
    return String_prototype_replace.call(this, /^\s+/, "");
  },
  trimRight() {
    return String_prototype_replace.call(this, /\s+$/, "");
  },
}), {
  trimLeft: {enumerable: false},
  trimRight: {enumerable: false},
});

})(this);

@@ -274,16 +274,52 @@
 l.String
+,%0A      TypeError = global.TypeError
 ;%0A%0AObjec
@@ -501,16 +501,69 @@
 operty,%0A
+      Object_getPrototypeOf = Object.getPrototypeOf,%0A
       Ob
@@ -624,24 +624,120 @@
 escriptor;%0A%0A
+function ToPropertyKey(pk) %7B%0A  // only string valued property keys here%0A  return String(pk);%0A%7D%0A%0A
 Object.defin
@@ -809,32 +809,122 @@
 name, getter) %7B%0A
+    if (typeof getter != 'function') throw TypeError();%0A    var pk = ToPropertyKey(name);%0A
     var obj = (t
@@ -992,20 +992,18 @@
 ty(obj, 
-name
+pk
 , %7Bget: 
@@ -1086,24 +1086,114 @@
 , setter) %7B%0A
+    if (typeof setter != 'function') throw TypeError();%0A    var pk = ToPropertyKey(name);%0A
     var obj 
@@ -1265,20 +1265,18 @@
 ty(obj, 
-name
+pk
 , %7Bset: 
@@ -1356,39 +1356,105 @@
 ame) %7B%0A    var p
+k
  = 
-this
+ToPropertyKey(name);%0A    var p = (this != null ? Object(this) : this)
 ;%0A    do %7B%0A     
@@ -1492,36 +1492,34 @@
 tyDescriptor(p, 
-name
+pk
 );%0A      if (des
@@ -1523,20 +1523,8 @@
 desc
- && desc.get
 ) re
@@ -1552,35 +1552,48 @@
 while ((p = 
-p.__proto__
+Object_getPrototypeOf(p)
 ));%0A  %7D,%0A  _
@@ -1629,15 +1629,81 @@
 ar p
+k
  = 
-this
+ToPropertyKey(name);%0A    var p = (this != null ? Object(this) : this)
 ;%0A  
@@ -1761,20 +1761,18 @@
 ptor(p, 
-name
+pk
 );%0A     
@@ -1784,20 +1784,8 @@
 desc
- && desc.set
 ) re
@@ -1821,19 +1821,32 @@
 p = 
-p.__proto__
+Object_getPrototypeOf(p)
 ));%0A

Improve compatibility for __{define,lookup}[G|S]etter__