()
| 3900 | }; |
| 3901 | } |
| 3902 | load() { |
| 3903 | const reader = this._reader; |
| 3904 | const marker = []; |
| 3905 | let stack = new builtins.list(); |
| 3906 | const memo = {}; |
| 3907 | let size = 0; |
| 3908 | while (reader.position < reader.length) { |
| 3909 | const opcode = reader.byte(); |
| 3910 | // console.log(`${(reader.position - 1).toString()} ${opcode}`); |
| 3911 | // https://svn.python.org/projects/python/trunk/Lib/pickletools.py |
| 3912 | // https://github.com/python/cpython/blob/master/Lib/pickle.py |
| 3913 | switch (opcode) { |
| 3914 | case 128: { // PROTO |
| 3915 | const version = reader.byte(); |
| 3916 | if (version > 5) { |
| 3917 | throw new python.Error(`Unsupported protocol version '${version}'.`); |
| 3918 | } |
| 3919 | break; |
| 3920 | } |
| 3921 | case 99: { // GLOBAL 'c' |
| 3922 | const module = reader.line(); |
| 3923 | const name = reader.line(); |
| 3924 | stack.push(this.find_class(module, name)); |
| 3925 | break; |
| 3926 | } |
| 3927 | case 147: { // STACK_GLOBAL '\x93' (Protocol 4) |
| 3928 | const name = stack.pop(); |
| 3929 | const module = stack.pop(); |
| 3930 | stack.push(this.find_class(module, name)); |
| 3931 | break; |
| 3932 | } |
| 3933 | case 111: { // OBJ 'o' |
| 3934 | const args = stack; |
| 3935 | const cls = args.pop(); |
| 3936 | stack = marker.pop(); |
| 3937 | const obj = this._instantiate(cls, args); |
| 3938 | stack.push(obj); |
| 3939 | break; |
| 3940 | } |
| 3941 | case 112 : { // PUT 'p' |
| 3942 | const index = parseInt(reader.line(), 10); |
| 3943 | if (stack.length === 0) { |
| 3944 | throw new python.Error(`Empty stack during 'PUT' operation.`); |
| 3945 | } |
| 3946 | memo[index] = stack[stack.length - 1]; |
| 3947 | size++; |
| 3948 | break; |
| 3949 | } |
| 3950 | case 103: { // GET 'g' |
| 3951 | const index = parseInt(reader.line(), 10); |
| 3952 | if (index in memo === false) { |
| 3953 | throw new python.Error(`Memo value not found at index '${index}'.`); |
| 3954 | } |
| 3955 | stack.push(memo[index]); |
| 3956 | break; |
| 3957 | } |
| 3958 | case 48: // POP '0' |
| 3959 | stack.pop(); |
no test coverage detected