script-decl-func.js (2947B)
1 // Copyright (C) 2016 the V8 project authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 esid: sec-globaldeclarationinstantiation 5 es6id: 15.1.8 6 description: Declaration of function where permissible 7 info: | 8 [...] 9 9. Let declaredFunctionNames be a new empty List. 10 10. For each d in varDeclarations, in reverse list order do 11 a. If d is neither a VariableDeclaration or a ForBinding, then 12 i. Assert: d is either a FunctionDeclaration or a 13 GeneratorDeclaration. 14 ii. NOTE If there are multiple FunctionDeclarations for the same name, 15 the last declaration is used. 16 iii. Let fn be the sole element of the BoundNames of d. 17 iv. If fn is not an element of declaredFunctionNames, then 18 1. Let fnDefinable be ? envRec.CanDeclareGlobalFunction(fn). 19 2. If fnDefinable is false, throw a TypeError exception. 20 3. Append fn to declaredFunctionNames. 21 4. Insert d as the first element of functionsToInitialize. 22 [...] 23 17. For each production f in functionsToInitialize, do 24 a. Let fn be the sole element of the BoundNames of f. 25 b. Let fo be the result of performing InstantiateFunctionObject for f 26 with argument env. 27 c. Perform ? envRec.CreateGlobalFunctionBinding(fn, fo, false). 28 [...] 29 30 8.1.1.4.16 CanDeclareGlobalFunction 31 32 1. Let envRec be the global Environment Record for which the method was 33 invoked. 34 2. Let ObjRec be envRec.[[ObjectRecord]]. 35 3. Let globalObject be the binding object for ObjRec. 36 4. Let existingProp be ? globalObject.[[GetOwnProperty]](N). 37 5. If existingProp is undefined, return ? IsExtensible(globalObject). 38 includes: [propertyHelper.js] 39 ---*/ 40 41 $262.evalScript('function brandNew() {}'); 42 43 assert.sameValue( 44 typeof brandNew, 'function', 'new binding on an extensible global object' 45 ); 46 verifyProperty(this, 'brandNew', { 47 writable: true, 48 enumerable: true, 49 configurable: false, 50 }); 51 52 Object.defineProperty(this, 'configurable', { configurable: true, value: 0 }); 53 Object.defineProperty( 54 this, 55 'nonConfigurable', 56 { configurable: false, writable: true, enumerable: true, value: 0 } 57 ); 58 59 // Prevent extensions on the global object to ensure that detail is not 60 // considered by any of the declarations which follow. 61 Object.preventExtensions(this); 62 63 $262.evalScript('function configurable() {}'); 64 65 assert.sameValue( 66 typeof configurable, 'function', 'like-named configurable property' 67 ); 68 verifyProperty(this, 'configurable', { 69 writable: true, 70 enumerable: true, 71 configurable: false, 72 }); 73 74 $262.evalScript('function nonConfigurable() {}'); 75 76 assert.sameValue( 77 typeof nonConfigurable, 78 'function', 79 'like-named non-configurable data property that is writable and enumerable' 80 ); 81 verifyProperty(this, 'nonConfigurable', { 82 writable: true, 83 enumerable: true, 84 configurable: false, 85 }); 86 87 reportCompare(0, 0);