MCPcopy Create free account
hub / github.com/buke/quickjs-go / TestPropertyFlags

Function TestPropertyFlags

class_test.go:490–593  ·  view source on GitHub ↗

NEW: TestPropertyFlags tests property descriptor flags

(t *testing.T)

Source from the content-addressed store, hash-verified

488
489// NEW: TestPropertyFlags tests property descriptor flags
490func TestPropertyFlags(t *testing.T) {
491 rt := NewRuntime()
492 defer rt.Close()
493
494 context := rt.NewContext()
495 defer context.Close()
496
497 // Create and register Point class
498 pointConstructor, _ := createPointClass(context)
499 if pointConstructor.IsException() {
500 defer pointConstructor.Free()
501 err := context.Exception()
502 t.Fatalf("Failed to create Point class: %v", err)
503 }
504
505 // Register Point class globally
506 context.Globals().Set("Point", pointConstructor)
507
508 // Test property descriptor flags
509 result := context.Eval(`
510 let p = new Point(1, 2)
511
512 // Test default flags for version (writable, enumerable, configurable)
513 let versionDesc = Object.getOwnPropertyDescriptor(p, 'version');
514
515 // Test read-only flags for readOnlyFlag (configurable only)
516 let readOnlyDesc = Object.getOwnPropertyDescriptor(p, 'readOnlyFlag');
517
518 // Test static property flags
519 let piDesc = Object.getOwnPropertyDescriptor(Point, 'PI_CONST');
520 let authorDesc = Object.getOwnPropertyDescriptor(Point, 'AUTHOR');
521
522 [
523 // Instance property with default flags
524 versionDesc.writable, // Should be true
525 versionDesc.enumerable, // Should be true
526 versionDesc.configurable, // Should be true
527
528 // Instance property with read-only flags
529 readOnlyDesc.writable, // Should be false (read-only)
530 readOnlyDesc.enumerable, // Should be false
531 readOnlyDesc.configurable, // Should be true
532
533 // Static property with default flags
534 piDesc.writable, // Should be true
535 piDesc.enumerable, // Should be true
536 piDesc.configurable, // Should be true
537
538 // Static property with enumerable-only flags
539 authorDesc.writable, // Should be false
540 authorDesc.enumerable, // Should be true
541 authorDesc.configurable // Should be false
542 ];
543 `)
544 defer result.Free()
545 if result.IsException() {
546 err := context.Exception()
547 t.Fatalf("Failed to evaluate property flags: %v", err)

Callers

nothing calls this directly

Calls 13

CloseMethod · 0.95
NewContextMethod · 0.95
CloseMethod · 0.95
ExceptionMethod · 0.95
GlobalsMethod · 0.95
EvalMethod · 0.95
NewRuntimeFunction · 0.85
createPointClassFunction · 0.85
IsExceptionMethod · 0.80
SetMethod · 0.80
ToBoolMethod · 0.80
GetIdxMethod · 0.80

Tested by

no test coverage detected