@@ -310,29 +310,16 @@ namespace Js
310
310
{
311
311
EngineInterfaceObject_CommonFunctionProlog (function, callInfo);
312
312
313
- AssertOrFailFast (args.Info .Count >= 3 && JavascriptString::Is (args.Values [1 ]) && JavascriptFunction ::Is (args.Values [2 ]));
313
+ AssertOrFailFast (args.Info .Count >= 3 && JavascriptString::Is (args.Values [1 ]) && ScriptFunction ::Is (args.Values [2 ]));
314
314
315
315
JavascriptLibrary * library = scriptContext->GetLibrary ();
316
316
317
- // retrieves arguments
318
- JavascriptString* methodName = JavascriptString::FromVar (args.Values [1 ]);
319
- JavascriptFunction* func = JavascriptFunction::FromVar (args.Values [2 ]);
320
-
321
- func->GetFunctionProxy ()->EnsureDeserialized ();
317
+ JavascriptString* methodName = JavascriptString::UnsafeFromVar (args.Values [1 ]);
318
+ ScriptFunction* func = EngineInterfaceObject::CreateLibraryCodeScriptFunction (ScriptFunction::UnsafeFromVar (args.Values [2 ]), methodName, false /* isConstructor */ , true /* isJsBuiltIn */ , false /* isPublic */ );
322
319
323
- DynamicObject* chakraLibraryObject = GetPrototypeFromName (PropertyIds::__chakraLibrary, false , scriptContext);
324
320
PropertyIds functionIdentifier = JavascriptOperators::GetPropertyId (methodName, scriptContext);
325
321
326
- // Link the function to __chakraLibrary.
327
- ScriptFunction* scriptFunction = library->CreateScriptFunction (func->GetFunctionProxy ());
328
- scriptFunction->GetFunctionProxy ()->SetIsJsBuiltInCode ();
329
-
330
- Assert (scriptFunction->HasFunctionBody ());
331
- scriptFunction->GetFunctionBody ()->SetJsBuiltInForceInline ();
332
-
333
- scriptFunction->SetPropertyWithAttributes (PropertyIds::name, methodName, PropertyConfigurable, nullptr );
334
-
335
- library->AddMember (chakraLibraryObject, functionIdentifier, scriptFunction);
322
+ library->AddMember (library->GetChakraLib (), functionIdentifier, func);
336
323
337
324
// Don't need to return anything
338
325
return library->GetUndefined ();
@@ -342,7 +329,7 @@ namespace Js
342
329
{
343
330
EngineInterfaceObject_CommonFunctionProlog (function, callInfo);
344
331
345
- AssertOrFailFast (args.Info .Count >= 3 && JavascriptObject::Is (args.Values [1 ]) && JavascriptFunction ::Is (args.Values [2 ]));
332
+ AssertOrFailFast (args.Info .Count >= 3 && JavascriptObject::Is (args.Values [1 ]) && ScriptFunction ::Is (args.Values [2 ]));
346
333
347
334
JavascriptLibrary * library = scriptContext->GetLibrary ();
348
335
@@ -370,49 +357,33 @@ namespace Js
370
357
371
358
BOOL staticMethod = JavascriptConversion::ToBoolean (staticMethodProperty, scriptContext);
372
359
BOOL forceInline = JavascriptConversion::ToBoolean (forceInlineProperty, scriptContext);
360
+ Assert (forceInline);
373
361
374
- JavascriptFunction* func = JavascriptFunction::FromVar (args.Values [2 ]);
375
-
376
- // Set the function's display name, as the function we pass in argument are anonym.
377
- func->GetFunctionProxy ()->SetIsPublicLibraryCode ();
378
- func->GetFunctionProxy ()->EnsureDeserialized ()->SetDisplayName (methodName->GetString (), methodName->GetLength (), 0 );
362
+ ScriptFunction *func = EngineInterfaceObject::CreateLibraryCodeScriptFunction (ScriptFunction::UnsafeFromVar (args.Values [2 ]), methodName, false /* isConstructor */ , true /* isJsBuiltIn */ , true /* isPublic */ );
379
363
380
364
DynamicObject* prototype = GetPrototypeFromName (JavascriptOperators::GetPropertyId (className, scriptContext), staticMethod, scriptContext);
381
- PropertyIds functionIdentifier = methodName->BufferEquals (_u (" Symbol.iterator" ), 15 )? PropertyIds::_symbolIterator :
382
- JavascriptOperators::GetPropertyId (methodName, scriptContext);
383
-
384
- // Link the function to the prototype.
385
- ScriptFunction* scriptFunction = library->CreateScriptFunction (func->GetFunctionProxy ());
386
- scriptFunction->GetFunctionProxy ()->SetIsJsBuiltInCode ();
387
-
388
- if (forceInline)
389
- {
390
- Assert (scriptFunction->HasFunctionBody ());
391
- scriptFunction->GetFunctionBody ()->SetJsBuiltInForceInline ();
392
- }
393
- scriptFunction->SetPropertyWithAttributes (PropertyIds::length, TaggedInt::ToVarUnchecked (argumentsCount), PropertyConfigurable, nullptr );
394
-
395
- scriptFunction->SetConfigurable (PropertyIds::prototype, true );
396
- scriptFunction->DeleteProperty (PropertyIds::prototype, Js::PropertyOperationFlags::PropertyOperation_None);
365
+ PropertyIds functionIdentifier = methodName->BufferEquals (_u (" Symbol.iterator" ), 15 )
366
+ ? PropertyIds::_symbolIterator
367
+ : JavascriptOperators::GetPropertyId (methodName, scriptContext);
397
368
398
- scriptFunction ->SetPropertyWithAttributes (PropertyIds::name, methodName , PropertyConfigurable, nullptr );
369
+ func ->SetPropertyWithAttributes (PropertyIds::length, TaggedInt::ToVarUnchecked (argumentsCount) , PropertyConfigurable, nullptr );
399
370
400
- library->AddMember (prototype, functionIdentifier, scriptFunction );
371
+ library->AddMember (prototype, functionIdentifier, func );
401
372
402
- RecordCommonNativeInterfaceBuiltIns (functionIdentifier, scriptContext, scriptFunction );
373
+ RecordCommonNativeInterfaceBuiltIns (functionIdentifier, scriptContext, func );
403
374
404
375
if (!JavascriptOperators::IsUndefinedOrNull (aliasProperty))
405
376
{
406
377
JavascriptString * alias = JavascriptConversion::ToString (aliasProperty, scriptContext);
407
378
// Cannot do a string to property id search here, Symbol.* have different hashing mechanism, so resort to this str compare
408
379
PropertyIds aliasFunctionIdentifier = alias->BufferEquals (_u (" Symbol.iterator" ), 15 ) ? PropertyIds::_symbolIterator :
409
380
JavascriptOperators::GetPropertyId (alias, scriptContext);
410
- library->AddMember (prototype, aliasFunctionIdentifier, scriptFunction );
381
+ library->AddMember (prototype, aliasFunctionIdentifier, func );
411
382
}
412
383
413
384
if (prototype == library->arrayPrototype )
414
385
{
415
- RecordDefaultIteratorFunctions (functionIdentifier, scriptContext, scriptFunction );
386
+ RecordDefaultIteratorFunctions (functionIdentifier, scriptContext, func );
416
387
}
417
388
418
389
// Don't need to return anything
0 commit comments